OKX WebSocket API

Subscribe to OKX v5 public channels (tickers, candles, trades, books) and authenticated private channels (account, positions, orders) with HMAC signing.

TsgcWSAPI_OKX

OKX v5 WebSocket client — tickers, candles, trades, books, instruments plus signed private streams for account, positions, orders.

Component class

TsgcWSAPI_OKX

Protocol

OKX v5 API

Platforms

Windows, macOS, Linux, iOS, Android

Edition

Standard / Professional / Enterprise

Drop the component, set keys, subscribe

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);

What's inside

Public market streams, signed private streams, and a typed router that delivers each channel as its own event.

Public streams

SubscribeTickers, SubscribeCandle, SubscribeTrades, SubscribeBooks, SubscribeBooks5, SubscribeBooksL2-TBT, SubscribeInstruments map every OKX v5 public channel.

Signed login

OKX requires a per-connection login with HMAC over timestamp+method+requestPath. The component handles the login and re-login on reconnect.

Private streams

SubscribeAccount, SubscribePositions, SubscribeOrders, SubscribeBalanceAndPosition open authenticated channels after login.

Trading actions

OKX exposes trading verbs (place-order, cancel-order, amend-order, mass-cancel) over the same authenticated WebSocket — typed methods cover each.

Demo mode

OKX demo trading lives on wspap.okx.com with the x-simulated-trading header; toggle OKX.DemoTrading to switch endpoints.

Heartbeats

OKX requires a text "ping" every 25-30 seconds; the component sends them automatically and resets the timer on every inbound frame.

Specifications & references

Authoritative sources for the APIs this component implements.

Documentation & Demos

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.
Demo Project — Demos\05.Crypto\12.OKX Ready-to-run example project. Ships inside the sgcWebSockets package — download the trial below.
Technical Document (PDF) Features, quick start, code samples for Delphi & C++ Builder and primary-source references — this component only.
User Manual (PDF) Comprehensive manual covering every component in the library.

Ready to Trade on OKX?

Download the free trial and stream OKX market data and account events from Delphi.