Binance API
Binance spot and futures WebSocket and REST client — public streams, user data and authenticated trading.
Binance spot and futures WebSocket and REST client — public streams, user data and authenticated trading.
Binance is an international multi-language cryptocurrency exchange. It offers some APIs to access Binance data. The following APIs are supported:
TsgcWSAPI_Binance| Standards & specs | Binance Spot API documentation · Binance USDT-M Futures API |
| Component class | TsgcWSAPI_Binance (unit sgcWebSocket_API_Binance) |
| Frameworks | VCL, FireMonkey, Lazarus / FPC, .NET |
| Platforms | Windows, macOS, Linux, iOS, Android |
The principal published / public properties used to configure and drive the component. Consult the online help for the full list.
Client | Published or public property used to configure or query the component. |
OnBinanceHTTPException | Published or public property used to configure or query the component. |
Binance | Published or public property used to configure or query the component. |
RawMessages | Published or public property used to configure or query the component. |
REST_API | Published or public property used to configure or query the component. |
ListenKey | Published or public property used to configure or query the component. |
Version | Published or public property used to configure or query the component. |
The principal public methods exposed by the component.
SubscribeAggregateTrades() | Public function exposed by the component. |
UnSubscribeAggregateTrades() | Public function exposed by the component. |
SubscribeTrades() | Public function exposed by the component. |
UnSubscribeTrades() | Public function exposed by the component. |
SubscribeKLine() | Public function exposed by the component. |
UnSubscribeKLine() | Public function exposed by the component. |
SubscribeMiniTicker() | Public function exposed by the component. |
UnSubscribeMiniTicker() | Public function exposed by the component. |
SubscribeAllMiniTickers() | Public function exposed by the component. |
UnSubscribeAllMiniTickers() | Public function exposed by the component. |
Drop the component on a form, configure the properties below and activate it. The snippet that follows shows the typical Binance | Connect WebSocket API configuration sourced from the online help.
oClient := TsgcWebSocketClient.Create(nil); oBinance := TsgcWSAPI_Binance.Create(nil); oBinance.Client := oClient; oClient.Active := True;
TsgcWebSocketClient *oClient = new TsgcWebSocketClient(NULL); TsgcWSAPI_Binance *oBinance = new TsgcWSAPI_Binance(NULL); oBinance->Client = oClient; oClient->Active = true;
TsgcWebSocketClient oClient = new TsgcWebSocketClient(); TsgcWSAPI_Binance oBinance = new TsgcWSAPI_Binance(); oBinance.Client = oClient; oClient.Active = true;
The following scenarios are lifted verbatim from the online help. Each shows the configuration and method calls needed to drive the component through a specific real-world flow.
Binance offers a variety of channels where you can subscribe to get real-time updates of market data, orders... Find below a sample of how to subscribe to a Ticker:
oClient := TsgcWebSocketClient.Create(nil); oBinance := TsgcWSAPI_Binance.Create(nil); oBinance.Client := oClient; oBinance.SubscribeTicker('bnbbtc'); procedure OnMessage(Connection: TsgcWSConnection; const aText: string); begin // here you will receive the ticker updates end;
TsgcWebSocketClient *oClient = new TsgcWebSocketClient(NULL); TsgcWSAPI_Binance *oBinance = new TsgcWSAPI_Binance(NULL); oBinance->Client = oClient; oBinance->SubscribeTicker("bnbbtc"); void OnMessage(TsgcWSConnection *Connection, const string aText) { // here you will receive the ticker updates }
TsgcWebSocketClient oClient = new TsgcWebSocketClient(); TsgcWSAPI_Binance oBinance = new TsgcWSAPI_Binance(); oBinance.Client = oClient; oBinance.SubscribeTicker("bnbbtc"); void OnMessage(TsgcWSConnection Connection, const string aText) { // here you will receive the ticker updates }
To place a new order, just call the method REST_API.NewOrder of the Binance Client Component.
oBinance := TsgcWSAPI_Binance.Create(nil); oBinance.Binance.ApiKey := '<api key>'; oBinance.Binance.ApiSecret := '<api secret>'; ShowMessage(oBinance.REST_API.NewOrder('BNBBTC', 'BUY', 'MARKET', '', 1));
TsgcWSAPI_Binance *oBinance = new TsgcWSAPI_Binance(this); oBinance->Binance->ApiKey = "<api key>"; oBinance->Binance->ApiSecret = "<api secret>"; ShowMessage(oBinance->REST_API->NewOrder("BNBBTC", "BUY", "MARKET", "", 1));
TsgcWSAPI_Binance oBinance = new TsgcWSAPI_Binance(); oBinance.Binance.ApiKey = "<api key>"; oBinance.Binance.ApiSecret = "<api secret>"; MessageBox.Show(oBinance.REST_API.NewOrder("BNBBTC", "BUY", "MARKET", "", 1));
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.
oBinance := TsgcWSAPI_Binance.Create(nil); ShowMessage(oBinance.REST_API.GetPriceTicker('BNBBTC'));
TsgcWSAPI_Binance *oBinance = new TsgcWSAPI_Binance(this); ShowMessage(oBinance->REST_API->GetPriceTicker("BNBBTC"));
TsgcWSAPI_Binance oBinance = new TsgcWSAPI_Binance(); MessageBox.Show(oBinance.REST_API.GetPriceTicker("BNBBTC"));
The Binance REST API offers public and private endpoints. The Private endpoints require that messages are signed to increase the security of transactions.
oBinance := TsgcWSAPI_Binance.Create(nil); oBinance.Binance.ApiKey := '<your api key>'; oBinance.Binance.ApiSecret := '<your api secret>'; ShowMessage(oBinance.REST_API.GetAccountInformation);
TsgcWSAPI_Binance *oBinance = new TsgcWSAPI_Binance(this); oBinance->Binance->ApiKey = "<your api key>"; oBinance->Binance->ApiSecret = "<your api secret>"; ShowMessage(oBinance->REST_API->GetAccountInformation());
TsgcWSAPI_Binance oBinance = new TsgcWSAPI_Binance(); oBinance.Binance.ApiKey = "<your api key>"; oBinance.Binance.ApiSecret = "<your api secret>"; MessageBox.Show(oBinance.REST_API.GetAccountInformation());
Binance allows you to use the Wallet API to submit a Withdraw request, only the following parameters are mandatory:
oBinance := TsgcWSAPI_Binance.Create(nil); oBinance.Binance.ApiKey := '<your api key>'; oBinance.Binance.ApiSecret := '<your api secret>'; ShowMessage(oBinance.REST_API.WalletWithdraw('BTC', '7213fea8e94b4a5593d507237e5a555b', 0.25));
TsgcWSAPI_Binance *oBinance = new TsgcWSAPI_Binance(this); oBinance->Binance->ApiKey = "<your api key>"; oBinance->Binance->ApiSecret = "<your api secret>"; ShowMessage(oBinance->REST_API->WalletWithdraw("BTC", "7213fea8e94b4a5593d507237e5a555b", 0.25));
TsgcWSAPI_Binance oBinance = new TsgcWSAPI_Binance(); oBinance.Binance.ApiKey = "<your api key>"; oBinance.Binance.ApiSecret = "<your api secret>"; MessageBox.Show(oBinance.REST_API.WalletWithdraw("BTC", "7213fea8e94b4a5593d507237e5a555b", 0.25));
Every external claim links back to a primary source. The online-help references decode the canonical deep-link the company maintains for this component.
Demos\05.Crypto\01.Binance
.net\demos\05.Crypto\01.Binance