unsubscribe_ticker
Stop receiving real-time price updates for a specific cryptocurrency trading pair on the OKX exchange to manage data streams and reduce unnecessary notifications.
Instructions
Unsubscribe from 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:440-454 (handler)Main execution logic for the unsubscribe_ticker tool: logs the action, calls the WebSocket client's unsubscribe method for the 'tickers' channel, and returns a success confirmation message.if (request.params.name === "unsubscribe_ticker") { console.error( `[WebSocket] Unsubscribing from ticker for ${args.instrument}` ); this.wsClient.unsubscribe("tickers", args.instrument); return { content: [ { type: "text", text: `Successfully unsubscribed from real-time ticker updates for ${args.instrument}.`, }, ], }; }
- src/index.ts:370-384 (schema)Input schema definition for the unsubscribe_ticker tool, specifying the required 'instrument' parameter.{ name: "unsubscribe_ticker", description: "Unsubscribe from 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:390-396 (registration)Registration of unsubscribe_ticker as a valid tool name in the dispatch logic for CallToolRequestSchema.const validTools = [ "get_price", "get_candlesticks", "subscribe_ticker", "get_live_ticker", "unsubscribe_ticker", ];
- src/index.ts:184-208 (helper)Helper method in OKXWebSocketClient class that performs the actual WebSocket unsubscription, used by the tool handler.unsubscribe(channel: string, instId: string): void { const key = `${channel}:${instId}`; if (!this.subscriptions.has(key)) { return; // Not subscribed } console.error(`[WebSocket] Unsubscribing from ${channel} for ${instId}`); this.subscriptions.delete(key); if (this.ws && this.ws.readyState === WebSocket.OPEN) { this.ws.send( JSON.stringify({ op: "unsubscribe", args: [ { channel, instId, }, ], }) ); } }