Rest API connection to the Binance API

MQL4 Experts

Trabalho concluído

Tempo de execução 3 minutos
Comentário do desenvolvedor
Great customer with great ideas + well understanding about job and technical specifications like a developer.
Comentário do cliente
Very fast and honest developer!!

Termos de Referência

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.

Respondido

1
Desenvolvedor 1
Classificação
(336)
Projetos
620
38%
Arbitragem
39
23% / 64%
Expirado
93
15%
Livre
2
Desenvolvedor 2
Classificação
(19)
Projetos
19
11%
Arbitragem
21
5% / 86%
Expirado
3
16%
Trabalhando
3
Desenvolvedor 3
Classificação
(69)
Projetos
93
34%
Arbitragem
10
40% / 30%
Expirado
5
5%
Livre
Pedidos semelhantes
I need stochastic div (hidden &regular ea) that should perform task in all tf's ..divergence is a repaint stly so i want to use it with candlestick flips .. so bet for it
Hello, I have an indicator from a friend and I'd like to replicate it on my own TradingView or MT5 platform. Could you assist me with that?. Here is the link
so basically I have an EA(mql5), AI script(python), flask server and socket server both on python. Now this is an experimental script as I am trying to learn. However the EA is not entering any trades. How much would it cost for you to troubleshoot this for me? Thank you in advance
NEW FUNCTION 50+ USD
La idea es la siguiente, sería un EA semi automático. Yo como trader opero en zonas. En adelante las vamos a denominar ``zonas calientes´´. El EA debe que necesito debe operar conforme a 4 zonas calientes que yo configure en el mismo. ¿Qué hará el EA en cada una de esas zonas calientes que yo he configurado? En cada una de estas zonas el EA debe realizar hedging (crear un rango en el cual el EA entrara en sell o en
I have the bot just over half made, from another developer who let me down and decided they no longer wished to finish the project, so I have a basic example of the fundamentals of what it could look like, although multiple functions I require do not work, but I can show this to you on request. There are multiple features that I require, so please read the in depth requirement sheet on the attachment. Function: To
I need EA that works on MT5 to be able to do the following: - Can recognize Support/Resistance area - Can recognize VWAP direction. - Can recognize RSI. - Can recognize Double Top/bottom, Bullish/Bearish hammer candle, Bullish/bearish engulfing candle. - Ability to set Stoploss below/above support/resistance, but risk must be fixed at a certain price. - Stoploss
I want a program that will help calculate and enter the market on full margin for me. I just need to put in the price for entry, Stop loss and TP then it will calculate the lot sizes for entering the trade on full margin on Mt5
"I need an expert advisor (EA) based on stochastic divergence and candlestick formation. It should be able to identify both hidden and regular divergences. The EA should also include modified risk-reward ratios, modified timeframes, and a trailing stop loss. It is important that the EA is 100% accurate. Once an experienced developer applies, I will share the complete strategy."
I am seeking a highly skilled and experienced developer to assist with an important project. I need a development of an automated trading bot for NinjaTrader, utilizing a 4 SMA (Simple Moving Average) crossing strategy, with additional custom diversions for trade entries. The bot needs to be based on a strategy involving the crossing of four different SMAs. The exact periods for these SMAs and the conditions for
I need someone that can make expert advisor for backtesting purpose. The input file is History trade report export file from MQl5 the expert advisor should open position the exact time of open trade on the report. The same as the close time

Informações sobre o projeto

Orçamento
30+ USD
IVA (23%): 6.9 USD
Total: 36.9 USD
Desenvolvedor
27 USD
Prazo
de 1 para 3 dias