connectWebSocket
Establish real-time WebSocket connections to Bitget cryptocurrency exchange for instant access to market data, order updates, and account information for efficient trading.
Instructions
Connect to WebSocket for real-time data
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
No arguments | |||
Implementation Reference
- src/server.ts:469-491 (handler)Handler for the 'connectWebSocket' tool call. It attempts to connect the WebSocket client via this.wsClient.connect() and returns success or error message.case 'connectWebSocket': { try { await this.wsClient.connect(); return { content: [ { type: 'text', text: 'WebSocket connected successfully', }, ], } as CallToolResult; } catch (error: any) { return { content: [ { type: 'text', text: `Failed to connect WebSocket: ${error.message}`, }, ], isError: true, } as CallToolResult; } }
- src/server.ts:239-247 (registration)Registration of the 'connectWebSocket' tool in the listTools response, including its description and input schema (empty object, no parameters).{ name: 'connectWebSocket', description: 'Connect to WebSocket for real-time data', inputSchema: { type: 'object', properties: {}, required: [] }, },
- src/server.ts:242-246 (schema)Input schema definition for the 'connectWebSocket' tool: accepts no parameters.inputSchema: { type: 'object', properties: {}, required: [] },
- src/api/websocket-client.ts:41-79 (helper)Core implementation of WebSocket connection in BitgetWebSocketClient class. Creates WebSocket instance, sets up event handlers, waits for 'open' event with timeout, starts ping, and resubscribes to channels.async connect(): Promise<void> { if (this.isConnected || this.isConnecting) { return; } this.isConnecting = true; logger.info('Connecting to Bitget WebSocket', { url: this.config.url }); try { this.ws = new WebSocket(this.config.url); this.setupEventHandlers(); return new Promise((resolve, reject) => { const timeout = setTimeout(() => { reject(new Error('WebSocket connection timeout')); }, 10000); this.ws!.once('open', () => { clearTimeout(timeout); this.isConnected = true; this.isConnecting = false; this.reconnectCount = 0; logger.info('WebSocket connected successfully'); this.startPing(); this.resubscribeAll(); resolve(); }); this.ws!.once('error', (error) => { clearTimeout(timeout); this.isConnecting = false; reject(error); }); }); } catch (error) { this.isConnecting = false; throw error; } }