OKX WebSocket & REST API

Subscribe to OKX v5 public channels (tickers, candles, trades, books) and authenticated private channels (account, positions, orders) with HMAC signing. From release 2026.12, the signed OKX v5 REST API is in the same component.

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. From release 2026.12, its REST_API property also calls the signed OKX v5 REST API for market data, account, positions and orders.

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.SubscribeTicker('BTC-USDT');
  OKX.SubscribeCandlestick('BTC-USDT', okxCandle5m);
  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->SubscribeTicker("BTC-USDT");
OKX->SubscribeCandlestick("BTC-USDT", okxCandle5m);

What's inside

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

Public streams

SubscribeTicker, SubscribeCandlestick, 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.

REST endpoints

New in 2026.12: REST_API signs OKX v5 REST calls with the OK-ACCESS headers. Instruments, candles, balance, positions, leverage, pending orders, order history, fills, and place, cancel and amend order, plus generic GetRequest and PostRequest. OKX.IsDemo adds the x-simulated-trading header.

HTTP status & response headers

New in 2026.12: REST_API.LastResponseCode and REST_API.LastResponseHeaders give the HTTP status and the response headers (raw Name: value lines) of every REST call, and the OnHTTPAPIResponse event fires after every request, on success or error, before the error is raised. Use them to log every call and to inspect the headers of an error response.

Persistent REST connection

New in 2026.12: set REST_API.KeepAlive to True (default False) and the component keeps one HTTP/1.1 connection open and reuses it, so an order or a query no longer pays a new TCP and TLS handshake. An idle connection that the server closed is reopened before the request is sent. A POST, PUT, PATCH or DELETE that was already sent is never sent again, only a GET that failed on a closed connection is retried once. Calls on one instance are serialized.

Demo mode

OKX demo trading lives on wspap.okx.com with the x-simulated-trading header; toggle OKX.IsDemo 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 SubscribeTicker or SubscribeBooks.
Yes, from release 2026.12. The same TsgcWSAPI_OKX component covers the OKX v5 WebSocket API, with the public market channels, the signed private channels (account, positions, orders) and the trading verbs (place-order, cancel-order, amend-order, mass-cancel), and, through its REST_API property, the signed REST API for instruments, candles, balance, positions, leverage, orders and fills. It uses the same API key, secret and passphrase, and REST_API.OKXOptions.BaseURL selects www.okx.com or openapi.okx.com.
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 Florence, plus the matching C++ Builder versions. The OKX component runs on Windows, macOS, Linux, iOS and Android.
Best value: All-AccessEvery eSeGeCe product, Premium Support included, from €1,059/year.
See All-Access pricing

Ready to Trade on OKX?

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