Loading...
Loading...
Subscribe to BingX spot WebSocket market data streams including real-time trades, order book depth, K-lines, 24h ticker, latest price, best bid/ask, and incremental depth. Use when the user asks about real-time spot market data, live spot price feeds, streaming spot order books, or WebSocket subscriptions for spot trading.
npx skill4agent add bingx-api/api-ai-skills bingx-spot-ws-marketwss://open-api-ws.bingx.com/market| Channel | dataType Format | Description | Push Frequency |
|---|---|---|---|
| Trade | | Latest trade detail | Real-time |
| K-Line | | OHLCV candlestick | On update |
| Depth | | Limited order book depth | Every 300ms |
| 24h Ticker | | 24-hour price change statistics | Every 1s |
| Last Price | | Latest trade price | Real-time |
| Book Ticker | | Best bid/ask price & qty | Real-time |
| Incremental Depth | | Incremental + full depth (1000 levels) | Every 500ms |
BASE-USDTBTC-USDTETH-USDTSOL-USDT51020501001min3min5min15min30min1h2h4h6h8h12h1d3d1w1MNote: Spot kline intervals usesuffix (e.g.,min) unlike swap which uses1min(e.g.,m).1m
^[A-Z0-9]+-[A-Z]+$BTC-USDT5102050100references/websocket.mdCONSTRAINT: You MUST copy thefunction below verbatim when generating code. Do NOT rewrite the WebSocket or decompression logic. Only modify: (1) subscription channels passed to the function.connectSpotWsMarket
import * as pako from "pako";
function decompress(data: ArrayBuffer): string {
return new TextDecoder("utf-8").decode(pako.ungzip(new Uint8Array(data)));
}
function connectSpotWsMarket(
channels: string[],
onMessage: (data: unknown) => void
): WebSocket {
const ws = new WebSocket("wss://open-api-ws.bingx.com/market");
ws.binaryType = "arraybuffer";
ws.onopen = () => {
for (const ch of channels) {
ws.send(JSON.stringify({
id: crypto.randomUUID(),
reqType: "sub",
dataType: ch,
}));
}
};
ws.onmessage = (event) => {
const text = decompress(event.data as ArrayBuffer);
if (text.includes("ping") || text === "Ping") {
ws.send("Pong");
return;
}
try {
onMessage(JSON.parse(text));
} catch {
onMessage(text);
}
};
ws.onerror = (err) => console.error("WS error:", err);
ws.onclose = (ev) => console.log("WS closed:", ev.code, ev.reason);
return ws;
}connectSpotWsMarketdecompressws.binaryType = "arraybuffer"pingconnectSpotWsMarket(["BTC-USDT@trade"], (data) => {
// data.data: array of trade records
});connectSpotWsMarket(["BTC-USDT@depth50"], (data) => {
// data.bids, data.asks
});connectSpotWsMarket(["BTC-USDT@kline_1min"], (data) => {
// data.data.K: kline object
});connectSpotWsMarket([
"BTC-USDT@ticker",
"BTC-USDT@lastPrice",
"ETH-USDT@bookTicker",
], (data) => {
// Handle different data types
});&=?#Please select the market data stream type:
- Real-time trades — trade
- Order book depth (snapshot) — depth
- K-line / Candlestick updates — kline
- 24h price change statistics — ticker
- Latest trade price — lastPrice
- Best bid/ask (top of book) — bookTicker
- Incremental depth updates — incrDepth
Please select a trading pair (or type another):
- BTC-USDT
- ETH-USDT
- SOL-USDT
- BNB-USDT
- Other (enter manually, format: BASE-USDT)
Please select a K-line interval:
- 1min (1 minute) / 5min / 15min / 1h / 4h / 1d / 1w