subscribe_ticker
Subscribe to real-time price updates for cryptocurrency trading pairs on OKX exchange to monitor market movements and track live price changes.
Instructions
Subscribe to real-time ticker updates for an instrument
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| instrument | Yes | Instrument ID (e.g. BTC-USDT) |
Implementation Reference
- src/index.ts:423-437 (handler)Executes the subscribe_ticker tool by subscribing to the WebSocket 'tickers' channel for the specified instrument via wsClient and returns a success confirmation message.if (request.params.name === "subscribe_ticker") { console.error( `[WebSocket] Subscribing to ticker for ${args.instrument}` ); this.wsClient.subscribe("tickers", args.instrument); return { content: [ { type: "text", text: `Successfully subscribed to real-time ticker updates for ${args.instrument}. Use get_live_ticker to retrieve the latest data.`, }, ], }; }
- src/index.ts:336-350 (registration)Registers the subscribe_ticker tool in the listTools response with name, description, and input schema.{ name: "subscribe_ticker", description: "Subscribe to real-time ticker updates for an instrument", inputSchema: { type: "object", properties: { instrument: { type: "string", description: "Instrument ID (e.g. BTC-USDT)", }, }, required: ["instrument"], }, },
- src/index.ts:340-349 (schema)Input schema definition for the subscribe_ticker tool requiring an 'instrument' string parameter.inputSchema: { type: "object", properties: { instrument: { type: "string", description: "Instrument ID (e.g. BTC-USDT)", }, }, required: ["instrument"], },
- src/index.ts:170-183 (helper)Implementation of the WebSocket subscription logic in OKXWebSocketClient class, which adds the subscription to the set and sends the subscribe message if connected.subscribe(channel: string, instId: string): void { const key = `${channel}:${instId}`; if (this.subscriptions.has(key)) { return; // Already subscribed } console.error(`[WebSocket] Subscribing to ${channel} for ${instId}`); this.subscriptions.add(key); if (this.ws && this.ws.readyState === WebSocket.OPEN) { this.sendSubscription(channel, instId); } }