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)The handler logic for the 'unsubscribe_ticker' tool within the CallToolRequestSchema request handler. It logs the unsubscription, calls the WebSocket client's unsubscribe method with channel 'tickers' and the instrument, and returns a success 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)The tool registration in the listTools response, including name, description, and input schema requiring an 'instrument' string.{ 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:185-208 (helper)The unsubscribe method in OKXWebSocketClient class, which removes the subscription from the set, sends an unsubscribe message to the WebSocket if connected, and logs the action.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, }, ], }) ); } }
- src/index.ts:391-395 (registration)The validTools array that includes 'unsubscribe_ticker' for validation in the CallToolRequestSchema handler."get_price", "get_candlesticks", "subscribe_ticker", "get_live_ticker", "unsubscribe_ticker",