成交
通道名
spot:trade:{symbol}
鉴权:不需要(公开通道)。
描述
实时推送每笔公开成交。订阅时不发送快照 — 订阅此通道可获取实时成交流;如需历史成交记录,请先调用 GET /spot/trades。
订阅
发送:
{ "type": "subscribe", "channel": "spot:trade:DFUSDT" }
响应:
{ "type": "subscribed", "channel": "spot:trade:DFUSDT" }
不会紧随快照。下一次推送在下一笔成交发生时到达。
推送格式
spot_trade
每笔成交推送一条,在撮合引擎记录到撮合时立即发出。
{
"type": "spot_trade",
"channel": "spot:trade:DFUSDT",
"data": {
"trade_id": "9f2a1b3c-4d5e-6f7a-8b9c-0d1e2f3a4b5c",
"symbol": "DFUSDT",
"side": "buy",
"price": "0.5000",
"quantity": "30",
"ts": 1778400000123
}
}
| 字段 | 类型 | 描述 |
|---|---|---|
trade_id | string (UUID) | 本次成交的唯一标识符。 |
symbol | string | 交易对标识符,如 DFUSDT。 |
side | string | 撮合的吃单方向:buy 或 sell。 |
price | string (decimal) | 成交价格。 |
quantity | string (decimal) | 成交的基础资产数量(DFUSDT 市场中为 DF)。 |
ts | integer | Unix 时间戳,单位为毫秒(现货 API 中唯一具有毫秒精度的字段)。 |
side反映的是吃单方。buy表示市价买单或激进限价买单主动与挂单卖单撮合。如需区分自己作为挂单方还是吃单方,请使用私有通道spot:user:orders。
推送频率
每笔成交推送一次,事件驱动。没有轮询间隔或限流 — 每次撮合精确产生一条 spot_trade 消息。
代码示例
const ws = new WebSocket('wss://api-sepolia.p99.world/ws');
ws.onopen = () => {
ws.send(JSON.stringify({ type: 'subscribe', channel: 'spot:trade:DFUSDT' }));
setInterval(() => ws.send(JSON.stringify({ type: 'ping' })), 30000);
};
ws.onmessage = (event) => {
const msg = JSON.parse(event.data);
if (msg.type === 'spot_trade') {
const { trade_id, symbol, side, price, quantity, ts } = msg.data;
const time = new Date(ts).toISOString(); // ts is milliseconds
console.log(`[${time}] ${symbol} ${side.toUpperCase()} ${quantity} @ ${price} (id=${trade_id})`);
// Add to your trade tape, update last-price display, etc.
}
};