Binance | Get Market Data

Binance offers public Market Data through REST Endpoints, when you call one of these endpoints, you will get a snapshot of the market data requested.

The Market Data Endpoints don't require authentication, so are freely available to all users.

 

Example: to get a snapshot of the ticker BNBBTC, make the following call:


oBinance := TsgcWSAPI_Binance.Create(nil);
ShowMessage(oBinance.REST_API.GetPriceTicker('BNBBTC'));

 

Errors and Response Headers

When a request fails with an HTTP error status, the client raises EsgcHTTPAPIProtocolException, declared in the unit sgcHTTP_API. The exception descends from the one raised in previous versions, so existing exception handlers keep working without any change, and it carries the response headers of the failed request. Those headers were lost before, because the HTTP object was destroyed before the error reached the application.

 

 

Example: when Binance answers with an HTTP 429, wait the time the server asks for and read the request weight already consumed.


oBinance := TsgcWSAPI_Binance.Create(nil);
try
  ShowMessage(oBinance.REST_API.GetAggregateTrades('BTCUSDT'));
except
  on E: EsgcHTTPAPIProtocolException do
  begin
    if E.ErrorCode = 429 then
      Sleep(E.RetryAfterMs);
    ShowMessage(E.GetHeader('X-MBX-USED-WEIGHT-1M'));
  end;
end;

 

The ResponseHeaders parameter accepted by the Post and Query methods is now filled when the request fails too, not only when it succeeds.