OKX WebSocket API
Subscribe to OKX v5 public channels (tickers, candles, trades, books) and authenticated private channels (account, positions, orders) with HMAC signing.
Subscribe to OKX v5 public channels (tickers, candles, trades, books) and authenticated private channels (account, positions, orders) with HMAC signing.
OKX v5 WebSocket client — tickers, candles, trades, books, instruments plus signed private streams for account, positions, orders.
TsgcWSAPI_OKX
Windows, macOS, Linux, iOS, Android
Standard / Professional / Enterprise
Pair with a TsgcWebSocketClient, set OKX.ApiKey / OKX.ApiSecret / OKX.Passphrase for signed channels, then subscribe to public or private streams.
uses
sgcWebSocket, sgcWebSocket_API_OKX;
var
WSClient: TsgcWebSocketClient;
OKX: TsgcWSAPI_OKX;
begin
WSClient := TsgcWebSocketClient.Create(nil);
OKX := TsgcWSAPI_OKX.Create(nil);
OKX.Client := WSClient;
OKX.OKX.ApiKey := 'your-api-key';
OKX.OKX.ApiSecret := 'your-api-secret';
OKX.OKX.Passphrase := 'your-passphrase';
WSClient.Active := True;
OKX.SubscribeTickers('BTC-USDT');
OKX.SubscribeCandle('BTC-USDT', oxi5m);
OKX.SubscribeBooks('BTC-USDT');
end;
// uses: sgcWebSocket, sgcWebSocket_API_OKX
TsgcWebSocketClient *WSClient = new TsgcWebSocketClient(this);
TsgcWSAPI_OKX *OKX = new TsgcWSAPI_OKX(this);
OKX->Client = WSClient;
WSClient->Active = true;
OKX->SubscribeTickers("BTC-USDT");
OKX->SubscribeCandle("BTC-USDT", oxi5m);
Public market streams, signed private streams, and a typed router that delivers each channel as its own event.
SubscribeTickers, SubscribeCandle, SubscribeTrades, SubscribeBooks, SubscribeBooks5, SubscribeBooksL2-TBT, SubscribeInstruments map every OKX v5 public channel.
OKX requires a per-connection login with HMAC over timestamp+method+requestPath. The component handles the login and re-login on reconnect.
SubscribeAccount, SubscribePositions, SubscribeOrders, SubscribeBalanceAndPosition open authenticated channels after login.
OKX exposes trading verbs (place-order, cancel-order, amend-order, mass-cancel) over the same authenticated WebSocket — typed methods cover each.
OKX demo trading lives on wspap.okx.com with the x-simulated-trading header; toggle OKX.DemoTrading to switch endpoints.
OKX requires a text "ping" every 25-30 seconds; the component sends them automatically and resets the timer on every inbound frame.
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_OKX Full property, method and event reference for this component. | Open | |
| Demo Project — Demos\05.Crypto\12.OKX 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 primary-source references — this component only. | Open | |
| User Manual (PDF) Comprehensive manual covering every component in the library. | Open |