Skip to main content
Glama
gagarinyury

MCP Bitget Trading Server

by gagarinyury

connectWebSocket

Establish WebSocket connection to receive live cryptocurrency market data and trading updates from Bitget exchange.

Instructions

Connect to WebSocket for real-time data

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault

No arguments

Implementation Reference

  • MCP tool handler for 'connectWebSocket' that connects the WebSocket client instance 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, defining name, description, and input schema.
    { name: 'connectWebSocket', description: 'Connect to WebSocket for real-time data', inputSchema: { type: 'object', properties: {}, required: [] }, },
  • Core WebSocket connection implementation in BitgetWebSocketClient.connect(), handling connection, timeout, and event setup.
    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; } }
  • Factory function used to create and initialize the BitgetWebSocketClient instance in the server.
    export function createBitgetWebSocketClient(config: BitgetConfig): BitgetWebSocketClient { return new BitgetWebSocketClient({ url: config.wsUrl, pingInterval: 30000, reconnectInterval: 5000, maxReconnects: 10 }); }

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/gagarinyury/MCP-bitget-trading'

If you have feedback or need assistance with the MCP directory API, please join our Discord server