OKX WebSocket API

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

Quick answer: TsgcWSAPI_OKX is the sgcWebSockets component that connects Delphi and C++ Builder apps to OKX. It subscribes to the OKX v5 public WebSocket channels and, after an HMAC-signed login, to the authenticated account, position and order channels.

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.

Frequently asked questions

Common questions about the OKX API component for Delphi and C++ Builder.

Drop a TsgcWebSocketClient and a TsgcWSAPI_OKX component on your form, assign the client to the API component's Client property, set OKX.ApiKey, OKX.ApiSecret and OKX.Passphrase if you need private channels, then set WSClient.Active := True and call subscribe methods like SubscribeTickers or SubscribeBooks.
The TsgcWSAPI_OKX component focuses on the OKX v5 WebSocket API. It covers the public market channels, the signed private channels (account, positions, orders) and the trading verbs (place-order, cancel-order, amend-order, mass-cancel) that OKX exposes over the same authenticated WebSocket connection.
Public channels such as tickers, candles, trades and books work without credentials. OKX private channels require an API key, secret and passphrase: set OKX.ApiKey, OKX.ApiSecret and OKX.Passphrase and the component performs the per-connection HMAC login (and re-logs in on reconnect).
sgcWebSockets supports Delphi 7 through the latest Delphi 13, plus the matching C++ Builder versions. The OKX component runs on Windows, macOS, Linux, iOS and Android.

Ready to Trade on OKX?

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