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)The handler logic for the 'subscribe_ticker' tool within the central CallToolRequestSchema handler. It delegates to the WebSocket client's subscribe method.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 (schema)Tool schema definition including name, description, and input schema for 'subscribe_ticker'.{ 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:284-386 (registration)Registration of all tools including 'subscribe_ticker' in the ListToolsRequestSchema handler.this.server.setRequestHandler(ListToolsRequestSchema, async () => ({ tools: [ { name: "get_price", description: "Get latest price for an OKX instrument with formatted visualization", inputSchema: { type: "object", properties: { instrument: { type: "string", description: "Instrument ID (e.g. BTC-USDT)", }, format: { type: "string", description: "Output format (json or markdown)", default: "markdown", }, }, required: ["instrument"], }, }, { name: "get_candlesticks", description: "Get candlestick data for an OKX instrument with visualization options", inputSchema: { type: "object", properties: { instrument: { type: "string", description: "Instrument ID (e.g. BTC-USDT)", }, bar: { type: "string", description: "Time interval (e.g. 1m, 5m, 1H, 1D)", default: "1m", }, limit: { type: "number", description: "Number of candlesticks (max 100)", default: 100, }, format: { type: "string", description: "Output format (json, markdown, or table)", default: "markdown", }, }, required: ["instrument"], }, }, { 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"], }, }, { name: "get_live_ticker", description: "Get the latest ticker data from WebSocket subscription", inputSchema: { type: "object", properties: { instrument: { type: "string", description: "Instrument ID (e.g. BTC-USDT)", }, format: { type: "string", description: "Output format (json or markdown)", default: "markdown", }, }, required: ["instrument"], }, }, { 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:170-183 (helper)Core WebSocket subscription method called by the tool handler to manage subscriptions.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); } }