Discussing the article: "Introduction to MQL5 (Part 37): Mastering API and WebRequest Function in MQL5 (XI)"
You are missing trading opportunities:
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
Registration
Log in
You agree to website policy and terms of use
If you do not have an account, please register
Check out the new article: Introduction to MQL5 (Part 37): Mastering API and WebRequest Function in MQL5 (XI).
In this article, we show how to send authenticated requests to the Binance API using MQL5 to retrieve your account balance for all assets. Learn how to use your API key, server time, and signature to securely access account data, and how to save the response to a file for future use.
A message and a secret key are the two essential components needed to create a safe signature for Binance, as we covered in the last post. The message in this instance is the timestamp, which needs to reflect the current time on the Binance server rather than the time on your local computer. To secure your requests, the timestamp is essential. Repeated attacks are prevented by ensuring that each signed request is distinct and cannot be utilized by another party. The timestamp captures the precise moment the request is made because it is continually changing. Binance allows for accurate verification by providing the timestamp in milliseconds. When contacting private endpoints, such as checking balances or making trades, using the appropriate server time ensures that your signature will be valid.
We must submit an API request to Binance to obtain this server time. The server timestamp is the official reference that Binance uses for all authorized requests, in contrast to local time, which can vary according to your computer's clock or time zone. This means that before creating the signature, our MQL5 software needs to get in touch with Binance to obtain the server time. Any signature we make without this step would be rejected since the timestamp wouldn't fit Binance's expectations. To obtain the current server time, a GET request must be sent to a certain Binance endpoint. We can freely access this endpoint since it doesn't require authentication. The current server time in milliseconds is contained in a JSON object that Binance provides in response to our request. After that, our script will take this value out of the response and use it as the message while the signature is being created.
Author: Israel Pelumi Abioye