subscribeToOrderBook
Receive real-time order book updates for specific trading pairs on Bitget cryptocurrency exchange. Specify the symbol and instrument type to monitor market depth and liquidity changes instantly.
Instructions
Subscribe to real-time order book updates
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| instType | No | Instrument type (default: SPOT) | |
| symbol | Yes | Trading pair symbol |
Input Schema (JSON Schema)
{
"properties": {
"instType": {
"description": "Instrument type (default: SPOT)",
"enum": [
"SPOT",
"UMCBL"
],
"type": "string"
},
"symbol": {
"description": "Trading pair symbol",
"type": "string"
}
},
"required": [
"symbol"
],
"type": "object"
}
Implementation Reference
- src/server.ts:518-529 (handler)MCP tool handler for subscribeToOrderBook that parses arguments and calls the WebSocket client's subscribe method with channel 'books'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)Tool registration in the listTools handler, defining the tool name, description, and input schema for subscribeToOrderBook{ 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)The subscribe helper method in BitgetWebSocketClient that constructs and sends the WebSocket subscription message (used for order book with channel: 'books')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 }); } }