Binance WebSocket & REST API
Stream Binance market data (trades, klines, ticker, partial book depth, diff depth) and drive the signed REST API from a single typed component.
Stream Binance market data (trades, klines, ticker, partial book depth, diff depth) and drive the signed REST API from a single typed component.
WebSocket Market Streams plus REST_API access for spot trading. Pairs with TsgcWebSocketClient for the transport and signs payloads with HMAC-SHA256 against your ApiKey/ApiSecret.
TsgcWSAPI_Binance
Windows, macOS, Linux, iOS, Android
Standard / Professional / Enterprise
Plug a TsgcWebSocketClient into the API component, set Binance.ApiKey/ApiSecret if you need signed channels, then call SubscribeTicker / SubscribeKLine / SubscribeDiffDepth.
uses
sgcWebSocket, sgcWebSocket_API_Binance;
var
WSClient: TsgcWebSocketClient;
Binance: TsgcWSAPI_Binance;
begin
WSClient := TsgcWebSocketClient.Create(nil);
Binance := TsgcWSAPI_Binance.Create(nil);
Binance.Client := WSClient;
Binance.Binance.ApiKey := 'your-api-key';
Binance.Binance.ApiSecret := 'your-api-secret';
WSClient.Active := True;
// public market streams
Binance.SubscribeTicker('bnbbtc');
Binance.SubscribeKLine('bnbbtc', bci5m);
Binance.SubscribeDiffDepth('bnbbtc');
// REST_API call (signed)
ShowMessage(Binance.REST_API.GetAccountInformation);
end;
// uses: sgcWebSocket, sgcWebSocket_API_Binance
TsgcWebSocketClient *WSClient = new TsgcWebSocketClient(this);
TsgcWSAPI_Binance *Binance = new TsgcWSAPI_Binance(this);
Binance->Client = WSClient;
Binance->Binance->ApiKey = "your-api-key";
Binance->Binance->ApiSecret = "your-api-secret";
WSClient->Active = true;
Binance->SubscribeTicker("bnbbtc");
Binance->SubscribeKLine("bnbbtc", bci5m);
Binance->SubscribeDiffDepth("bnbbtc");
ShowMessage(Binance->REST_API->GetAccountInformation());
using esegece.sgcWebSockets;
var WSClient = new TsgcWebSocketClient();
var Binance = new TsgcWSAPI_Binance();
Binance.Client = WSClient;
Binance.Binance.ApiKey = "your-api-key";
Binance.Binance.ApiSecret = "your-api-secret";
WSClient.Active = true;
Binance.SubscribeTicker("bnbbtc");
Binance.SubscribeKLine("bnbbtc", TBinanceCryptoInterval.bci5m);
Binance.SubscribeDiffDepth("bnbbtc");
Both the WebSocket Market Streams and the signed REST API are exposed by the same component.
SubscribeAggregateTrades, SubscribeTrades, SubscribeKLine, SubscribeTicker, SubscribeAllMarketTickers, SubscribePartialBookDepth and SubscribeDiffDepth cover the full Binance public stream catalog.
Binance.REST_API exposes the full spot REST surface: GetAccountInformation, Get24hrTicker, GetKLines, GetOrderBook, GetOpenOrders, WalletWithdraw, GetWalletDepositHistory — over 40 typed methods.
Toggle Binance.BinanceUS for the US endpoint and Binance.TestNet for the sandbox. The component switches both the WebSocket and REST base URLs.
Set Binance.ApiKey and Binance.ApiSecret — the component computes the HMAC-SHA256 signature Binance requires for signed REST endpoints and User Data streams.
Use StartUserDataStream to obtain a listenKey, then subscribe to it for real-time account, order and balance updates. KeepAliveUserDataStream keeps the key alive.
For USDT/COIN-margined futures use the sibling component TsgcWSAPI_Binance_Futures — identical pattern with FuturesContracts selecting bfcUSDT or bfcCOIN.
Authoritative sources for the APIs this component implements.
Deep-link to the component reference, grab the ready-to-run demo project, and download the trial.
| Online Help — API_Binance Full property, method and event reference for this component. | Open | |
| Demo Project — Demos\05.Crypto\01.Binance Ready-to-run example project. Ships inside the sgcWebSockets package — download the trial below. | Open | |
| Technical Document (PDF) Features, quick start, code samples for Delphi, C++ Builder and .NET and primary-source references — this component only. | Open | |
| User Manual (PDF) Comprehensive manual covering every component in the library. | Open |