subscribeToOrderBook
Subscribe to real-time order book updates for cryptocurrency trading pairs to monitor market depth and price levels.
Instructions
Subscribe to real-time order book updates
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| symbol | Yes | Trading pair symbol | |
| instType | No | Instrument type (default: SPOT) |
Implementation Reference
- src/server.ts:518-529 (handler)Handler for the subscribeToOrderBook MCP tool. Extracts symbol and optional instType from arguments, subscribes to the 'books' WebSocket channel via wsClient, and returns a confirmation message.case 'subscribeToOrderBook': { const { symbol, instType = 'SPOT' } = args as any; this.wsClient.subscribe('books', symbol, instType); return { content: [ { type: 'text', text: `Subscribed to order book updates for ${symbol} (${instType})`, }, ], } as CallToolResult; }
- src/server.ts:269-280 (registration)Registration of the subscribeToOrderBook tool in the listTools response, including name, description, and input schema definition.{ name: 'subscribeToOrderBook', description: 'Subscribe to real-time order book updates', inputSchema: { type: 'object', properties: { symbol: { type: 'string', description: 'Trading pair symbol' }, instType: { type: 'string', enum: ['SPOT', 'UMCBL'], description: 'Instrument type (default: SPOT)' } }, required: ['symbol'] }, },
- src/api/websocket-client.ts:110-129 (helper)Core subscribe helper method in BitgetWebSocketClient. Constructs and sends the WebSocket subscription message (op: 'subscribe') for the given channel ('books' for order book), tracks subscriptions for automatic resubscribe on reconnect.subscribe(channel: string, symbol: string, instType: 'SPOT' | 'UMCBL' | 'DMCBL' = 'SPOT'): void { const subscription: WSSubscription = { op: 'subscribe', args: [{ instType, channel, instId: symbol }] }; const subKey = `${instType}:${channel}:${symbol}`; this.subscriptions.add(subKey); if (this.isConnected && this.ws) { logger.debug('Subscribing to channel', { channel, symbol, instType }); this.ws.send(JSON.stringify(subscription)); } else { logger.warn('WebSocket not connected, subscription will be sent on reconnect', { channel, symbol }); } }