Rest API connection to the Binance API

MQL4 Эксперты

Работа завершена

Время выполнения 3 минуты
Отзыв от исполнителя
Great customer with great ideas + well understanding about job and technical specifications like a developer.
Отзыв от заказчика
Very fast and honest developer!!

Техническое задание

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.

Откликнулись

1
Разработчик 1
Оценка
(337)
Проекты
624
38%
Арбитраж
40
23% / 65%
Просрочено
93
15%
Свободен
Опубликовал: 4 статьи, 19 примеров
2
Разработчик 2
Оценка
(20)
Проекты
19
11%
Арбитраж
23
4% / 83%
Просрочено
3
16%
Свободен
Опубликовал: 7 примеров
3
Разработчик 3
Оценка
(69)
Проекты
93
34%
Арбитраж
10
40% / 30%
Просрочено
5
5%
Свободен
Похожие заказы
Hello I need an EA for MT4 The EA uses only indicator, which shows a buy arrow for buy signal , and a sell arrow for sell signal. Conditions to open a trade: Open BUY trade, when we have a buy arrow show up, CANDLE CLOSES , AND THE ARROW IS STILL THERE .Then open BUY TRADE Open SELL trade, when we have a sell arrow show up, CANDLE CLOSES , AND THE ARROW IS THIS THERE .Then open BUY TRADE Open Close on opposite
​ Indicators: Fast MA (Period 10, Exponential) and Slow MA (Period 50, Exponential). ​ Buy Signal: When Fast MA crosses above Slow MA. ​ Sell Signal: When Fast MA crosses below Slow MA. ​ Risk Management & Parameters: ​Customizable Lot Size (Default: 0.01). ​Stop Loss (SL) and Take Profit (TP) in pips. ​Trailing Stop options. ​Max Spread filter. ​ Platform: MetaTrader 5 (MQL5)
​ Indicators: Fast MA (Period 10, Exponential) and Slow MA (Period 50, Exponential). ​ Buy Signal: When Fast MA crosses above Slow MA. ​ Sell Signal: When Fast MA crosses below Slow MA. ​ Risk Management & Parameters: ​Customizable Lot Size (Default: 0.01). ​Stop Loss (SL) and Take Profit (TP) in pips. ​Trailing Stop options. ​Max Spread filter. ​ Platform: MetaTrader 5 (MQL5)
A robot 30+ USD
Je souhaite trouver un développeur pour réaliser ce travail et effectuer les paiements via cette application. Je m'engage à ne communiquer avec les candidats que par cette application, y compris par messageries tierces, correspondance personnelle ou courriel. Je comprends que toute personne ne respectant pas ces conditions sera interdite de publier des commandes sur la plateforme Freelance
I am looking for an experienced MQL5/MT5 developer to develop a custom Expert Advisor based on a complete technical architecture already prepared by the client. This is not a request to design a trading strategy from scratch . The strategy architecture, entry/exit concepts, filters, risk-management requirements and testing requirements are already documented. The main responsibility will be MQL5 development
EAs 100+ USD
To apply, you must already have your EA running on an active MT5 trading account connected to the market. The account must have genuine trading history that can be independently reviewed and verified. EA Requirements 1. Prop-Firm Compatible Risk Management - The EA must include daily and overall drawdown protection. - Required inputs: "MaxDailyLoss = 5%" "MaxTotalDrawdown = 10%" - Once either limit is
Strategy 40 - 60 USD
yo i have a strategy i would really like to turn into a signal bot basically please this is very technical and serious to me the strategy needs more time 1 time frame and the bot most be 100% accurate
Ready to use bot 100+ USD
seller must provide the following to be considered... i will answer to all who fit this description, and can purchase more than 1 EA... - brief strategy description - overall EA expectancy - 1 week limited trial version, with whatever settings you consider best (can be blocked on demo, i don't really care) - investor password from a reputable broker (if history is available... live / demo, same thing, doesn't really
I want you to develop a professional HFT trading robot for MT5/MQL5 , initially focused on XAUUSD . The robot should be designed for high-speed tick-level trading , analyzing real-time bid/ask movement, spread, tick velocity, momentum, volatility, price acceleration and short-term market microstructure to identify very short-term opportunities. The core strategy should be capable of opening 5–10+ positions in a
can you help me use a Tickblaze Algo NRBO on the NT platform? I have it somewhat set up, but I have other questions about running it & knowing how to operate it in NT. Thank you if anyone have experience in this kindly bib and let do it asap

Информация о проекте

Бюджет
30+ USD
Сроки выполнения
от 1 до 3 дн.