Rest API connection to the Binance API

MQL4 Asesores Expertos

Trabajo finalizado

Plazo de ejecución 3 minutos
Comentario del Ejecutor
Great customer with great ideas + well understanding about job and technical specifications like a developer.
Comentario del Cliente
Very fast and honest developer!!

Tarea técnica

I have created skeleton EA, which goal is to open order and check the balance though Binance.com REST API, but it doesnt work. There are two layers of problems. First is described in this forum topic:

https://www.mql5.com/en/forum/253049

Apply to this job only if you know how to solve that. The Webrequest doesn't seem to properly connect to most binance api addresses. The only one that reports anything other than 404 is address for opening orders.

1. The EA needs to successfully connect to the REST API and open a waiting order (amount 1.0 ETH, price 0.001, pair ETHBTC). It needs to display result as Alert() and store it in string variable.

2. The EA must read "account" properly and display it's result as an Alert() and store it in string variable.


Currently the EA reports authorization error 401 result1 = {"code":-2014,"msg":"API-key format invalid."} for ORDER function and 404 not found error for ACCOUNT function. (404 also for any other function than order)

Documentation to Binance REST API:

https://github.com/binance-exchange/binance-official-api-docs/blob/master/rest-api.md


Here is my skeleton EA, that needs to be corrected:

#property copyright "Copyright 2017,Grzegorz Korycki"
#property version   "1.00"
#property strict

#include <MQLMySQL.mqh>
#include <SHA256.mqh>

string api_key     = "erased1";
string api_secret  = "erased2";


int private_api_timeout = 2000;
int last_api_call =0;
string result1 = "";
int first_run = 1;

double API_Balance(string symbol_temp) {
   bool failed = false;

   Alert("executing API Balance");
   bool value_returned = false;
   char secret_char[];
   string data2 = "";
   
   int timestamp = (int)TimeGMT();
   string for_encode = "timestamp="+(string)timestamp;
   
   char output_char[];
   string output; 

   SHA256 hash256;
   string hash = hash256.hmac(for_encode,api_secret);

   output = hash;
   
   Alert("output = "+output);
   string uri = "https://api.binance.com/api/v3/account";

   string body = for_encode+"&signature="+output;
   char body_char[];
   StringToCharArray(body, body_char, 0, WHOLE_ARRAY, CP_UTF8);
   ArrayResize(body_char, ArraySize(body_char)-1);

   ResetLastError();
   char result_char[]; string result_headers;
   string headers = "Sign: "+output+"\r\nKey: "+api_key;
   headers = "X-MBX-APIKEY: "+api_key;
   Alert("headers = "+headers);
   int res=WebRequest("POST",uri,"",headers,5000,body_char,ArraySize(body_char),result_char, result_headers);
   Alert("Executing URL:"+uri);
   result1 = CharArrayToString(result_char,0,WHOLE_ARRAY);

   if(res!=200)
   {
      Alert("Authorization error #"+(string)res+", LastError="+(string)GetLastError());
      Alert("result1 = "+ result1);
      failed = true;
      return -1;
   } else {
      Alert("balance loaded !");
      Alert("result1 = "+ result1);
      return 1;
   }
}

bool API_Open_Trade(int trade_direction, string pair_name, double trade_size, double price_temp, ) {
   bool failed = false;

   Alert("executing API Open Trade");
   bool value_returned = false;
   char secret_char[];
   string data2 = "";
   
   int timestamp = (int)TimeGMT();
   string for_encode = "symbol=ETHBTC&side=BUY&type=LIMIT&timeInForce=GTC&quantity=1&price=0.002&recvWindow=5000&timestamp="+(string)timestamp;
   
   char output_char[];
   string output; 

   SHA256 hash256;
   string hash = hash256.hmac(for_encode,api_secret);

   output = hash;
   
   Alert("output = "+output);
   string uri = "https://api.binance.com/api/v3/order/test";
   string body = for_encode+"&signature="+output;

   char body_char[];
   StringToCharArray(body, body_char, 0, WHOLE_ARRAY, CP_UTF8);
   ArrayResize(body_char, ArraySize(body_char)-1);

   ResetLastError();
   char result_char[]; string result_headers;
   string headers = "Sign: "+output+"\r\nKey: "+api_key;
   headers = "X-MBX-APIKEY: "+api_key;
   Alert("headers = "+headers);
   int res=WebRequest("POST",uri,"",headers,5000,body_char,ArraySize(body_char),result_char, result_headers);
   Alert("Executing URL:"+uri);
   result1 = CharArrayToString(result_char,0,WHOLE_ARRAY);

   if(res!=200)
   {
      Alert("Authorization error #"+(string)res+", LastError="+(string)GetLastError());
      Alert("result1 = "+ result1);
      failed = true;
      return -1;
   } else {
      Alert("balance loaded !");
      Alert("result1 = "+ result1);
      return 1;
   }
}

int OnInit()
  {
   API_Open_Trade(1,"ETHBTC", 1, 0.001);
   API_Balance("ETH");
   return(INIT_SUCCEEDED);
  }

void OnDeinit(const int reason)
  {

  }

Please contact me if you are interested. I will provide you with API keys and SHA256 function. https://api.binance.com needs to be added to allowed addresses in MT4.

Again - apply only if you know how to solve the problem mentioned in the Forum topic - you test the issue in your MT4 in less than a minute.

If solution uses external files, they must allow for usage of HTTP proxy.

Han respondido

1
Desarrollador 1
Evaluación
(336)
Proyectos
621
38%
Arbitraje
39
23% / 64%
Caducado
93
15%
Libre
2
Desarrollador 2
Evaluación
(19)
Proyectos
19
11%
Arbitraje
21
5% / 86%
Caducado
3
16%
Trabaja
3
Desarrollador 3
Evaluación
(69)
Proyectos
93
34%
Arbitraje
10
40% / 30%
Caducado
5
5%
Libre
Solicitudes similares
I would like to create an EA based on the Shved Supply and Demand indicator. you can find the Shved Supply and Demand v1.7 indicator in the following link https://www.mql5.com/en/code/29395 NB: Checks the trading robot must pass before publication in the Market ( https://www.mql5.com/en/articles/2555 ) MQ5 file to be provided
Im looking for an coder to code an EA: Trade management 1. opening trades according to the indicator 2. trades settings to choose from like: open all trades according to the signal open only trade 1,2,3 or 4 % per trade ( example 50/30/20 of the lot settings, with 4 trades it would be for example 50/30/10/10) 3. SL/Trailing settings: Move SL to entry after hitting TP1/TP2 or TP3 moving SL by % keep the original SL
Hi I'm looking to have 2 of my pinescript strategies converted to MQL5 and was wondering if you could first give me a quote for the more simple strategy and then for both the simple and complex strategy together. The simple strategy is a MACD crossover type thing that uses a special EMA script that filters out some ranging price action and also fractal candles for the stop loss. The second strategy is market
I want grate robot for making profits that know when to start a good trade and close a trade and must be active all time to avoid lost of money
I have developed a very strong TradingView strategy in Pine Script but unfortunately, a third-party connector is requiired and in my opinion, I want a more direct connection. I am not brilliant at coding, but I have coded the majority of the MT5 code and I would like you to make sure that the MT5 code matches my TradingView script and executes the same way as the TradingView script that I will provide if you are
Mbeje fx 50+ USD
I like to own my robot that why I want to build my own.i like to be a best to every robot ever in the life to be have more money
I need an MT5 EA that can do the following: I have to give the EA a price in advance, when the price is reached the EA has to automatically place a buy stop or sell stop order 0.5 pips below or above the price. Is this possible
Dr Pattern 30+ USD
good day i need the service of the seaso coder to help me fix my ea The Job required 1 knowledge of Mt4 and Mt5 indicator coding 2. Telegram code 3. ability to code indicator to work on multiple Time frame combine to trade 4 Ability to Join two or three indicator on same ir different time frame if you have these skill please let chart i will discuss the details of the Job inside to you The required day including
Good day, I want someone to help me create a universal news filter with on/off switch, with start and end settings, and drawdown control with magic number of EAs, etc. Thanks
Hello, I am looking for a professional programmer to optimize my existing EA integrating it with ChatGPT to analyze currencies using various methods to make the right trading decisions. i want it to be an EA that can be trusted to carry trade with the help of chat gpt and also have a very low drawdown

Información sobre el proyecto

Presupuesto
30+ USD
IVA (23%): 6.9 USD
Total: 36.9 USD
Para el ejecutor
27 USD
Plazo límite de ejecución
de 1 a 3 día(s)