Skip to main content
Skip to main content

OKX Data Connector

Want Bitcoin, Ethereum, or altcoin charts with live prices and no API key? The OKX connector talks to OKX public v5 endpoints — history over REST, candle updates over WebSocket.

Loading chart…

Use the controls above to change symbol and timeframe. This is the same integration you will copy into your app.

Standalone demo

Full-page version with sample code: OKX live demo.

What you get

FeatureDetails
No API keyPublic OKX spot market data
HistoryUp to 300 candles per REST request (adapter paginates for more)
Live ticksWebSocket candle channel on /ws/v5/business
PairsMajor spot symbols (BTC-USDT, ETH-USDT, …)
Timeframes1m through monthly
Symbol helperAccepts BTCUSDT and normalizes to BTC-USDT

Perfect for crypto dashboards, multi-exchange terminals, and Asia-focused products.

Install

npm install @efixdata/exeria-chart @efixdata/connector-okx

Minimal example

import { createChart } from "@efixdata/exeria-chart";
import { OkxAdapter } from "@efixdata/connector-okx";

const connector = new OkxAdapter();

const chart = createChart({
container,
dataAdapter: connector,
});

chart.init();

await chart.loadData("BTC-USDT", {
interval: "1d",
limit: 500,
});

chart.subscribeToUpdates("BTC-USDT", (tick) => {
console.log("Last price:", tick.price ?? tick.c);
});

Step by step

1 — Create the connector

const connector = new OkxAdapter();

Uses OKX public URLs by default. Optional tuning below.

2 — Attach to the chart

const chart = createChart({ container, dataAdapter: connector });
chart.init();

The chart delegates loadData and subscribeToUpdates to the connector.

3 — Load history

await chart.loadData("BTC-USDT", {
interval: "1h",
limit: 500,
});
OptionMeaning
intervalCandle size — "1m", "1h", "1d", "1w", "1M"
limitHow many recent bars (adapter paginates above 300)
from / toOptional date range instead of “latest N”

4 — Go live

chart.subscribeToUpdates("BTC-USDT");
// or with a callback:
chart.subscribeToUpdates("BTC-USDT", (tick) => { /* update UI */ });

5 — Clean up

chart.unsubscribeFromUpdates();
await connector.disconnect();
SymbolMarket
BTC-USDTBitcoin / USDT
ETH-USDTEthereum / USDT
SOL-USDTSolana / USDT
XRP-USDTXRP / USDT
BNB-USDTBNB / USDT

OKX uses BASE-QUOTE with a hyphen (BTC-USDT). The adapter also accepts compact symbols like BTCUSDT.

Switch cryptocurrency

async function switchSymbol(newSymbol: string) {
chart.unsubscribeFromUpdates();

await chart.loadData(newSymbol, {
interval: "1d",
limit: 500,
});

chart.subscribeToUpdates(newSymbol);
}

Always unsubscribe before loading a new symbol on the same chart instance.

Custom configuration (optional)

const connector = new OkxAdapter({
baseUrl: "https://www.okx.com",
wsUrl: "wss://ws.okx.com:8443/ws/v5/business",
requestTimeout: 10000,
maxRetries: 5,
retryDelay: 2000,
pageDelayMs: 120,
});

For demo trading:

const connector = new OkxAdapter({
baseUrl: "https://www.okx.com",
wsUrl: "wss://wspap.okx.com:8443/ws/v5/business",
});

Error handling

try {
await chart.loadData("BTC-USDT", { interval: "1d", limit: 500 });
} catch (error) {
if (error instanceof Error && error.message.includes("Invalid instrument")) {
console.error("Symbol not found on OKX");
} else {
console.error("Load failed:", error);
}
}

Show a retry button or message in your UI — users on bad networks will thank you.

Limits to know

TopicLimit
Candles per REST request300 max (adapter paginates automatically)
REST rate20 requests / 2 seconds per IP (OKX policy)
WebSocketCandle channel uses /ws/v5/business
BrowserNeeds WebSocket support (all modern browsers)

For heavy traffic: cache history server-side.

Exchange comparison

Binance / BybitOKX
SymbolBTCUSDTBTC-USDT
REST limit1,000 / request300 / request
API key (public data)NoNo

Need BTCUSDT format? See Binance or Bybit.

What is next?