Skip to main content
Glama
gagarinyury

MCP Bitget Trading Server

by gagarinyury

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
NameRequiredDescriptionDefault

No arguments

Implementation Reference

  • 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: [] }, },
  • Input schema definition for the 'connectWebSocket' tool: accepts no parameters.
    inputSchema: { type: 'object', properties: {}, required: [] },
  • 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; } }

Other Tools

Related Tools

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