Skip to main content
Glama

subscribe_ticker

Subscribe to real-time price updates for cryptocurrency trading pairs on OKX exchange to monitor market movements and track live price changes.

Instructions

Subscribe to real-time ticker updates for an instrument

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
instrumentYesInstrument ID (e.g. BTC-USDT)

Implementation Reference

  • The handler logic for the 'subscribe_ticker' tool within the central CallToolRequestSchema handler. It delegates to the WebSocket client's subscribe method.
    if (request.params.name === "subscribe_ticker") { console.error( `[WebSocket] Subscribing to ticker for ${args.instrument}` ); this.wsClient.subscribe("tickers", args.instrument); return { content: [ { type: "text", text: `Successfully subscribed to real-time ticker updates for ${args.instrument}. Use get_live_ticker to retrieve the latest data.`, }, ], }; }
  • Tool schema definition including name, description, and input schema for 'subscribe_ticker'.
    { name: "subscribe_ticker", description: "Subscribe to real-time ticker updates for an instrument", inputSchema: { type: "object", properties: { instrument: { type: "string", description: "Instrument ID (e.g. BTC-USDT)", }, }, required: ["instrument"], }, },
  • src/index.ts:284-386 (registration)
    Registration of all tools including 'subscribe_ticker' in the ListToolsRequestSchema handler.
    this.server.setRequestHandler(ListToolsRequestSchema, async () => ({ tools: [ { name: "get_price", description: "Get latest price for an OKX instrument with formatted visualization", inputSchema: { type: "object", properties: { instrument: { type: "string", description: "Instrument ID (e.g. BTC-USDT)", }, format: { type: "string", description: "Output format (json or markdown)", default: "markdown", }, }, required: ["instrument"], }, }, { name: "get_candlesticks", description: "Get candlestick data for an OKX instrument with visualization options", inputSchema: { type: "object", properties: { instrument: { type: "string", description: "Instrument ID (e.g. BTC-USDT)", }, bar: { type: "string", description: "Time interval (e.g. 1m, 5m, 1H, 1D)", default: "1m", }, limit: { type: "number", description: "Number of candlesticks (max 100)", default: 100, }, format: { type: "string", description: "Output format (json, markdown, or table)", default: "markdown", }, }, required: ["instrument"], }, }, { name: "subscribe_ticker", description: "Subscribe to real-time ticker updates for an instrument", inputSchema: { type: "object", properties: { instrument: { type: "string", description: "Instrument ID (e.g. BTC-USDT)", }, }, required: ["instrument"], }, }, { name: "get_live_ticker", description: "Get the latest ticker data from WebSocket subscription", inputSchema: { type: "object", properties: { instrument: { type: "string", description: "Instrument ID (e.g. BTC-USDT)", }, format: { type: "string", description: "Output format (json or markdown)", default: "markdown", }, }, required: ["instrument"], }, }, { name: "unsubscribe_ticker", description: "Unsubscribe from real-time ticker updates for an instrument", inputSchema: { type: "object", properties: { instrument: { type: "string", description: "Instrument ID (e.g. BTC-USDT)", }, }, required: ["instrument"], }, }, ], }));
  • Core WebSocket subscription method called by the tool handler to manage subscriptions.
    subscribe(channel: string, instId: string): void { const key = `${channel}:${instId}`; if (this.subscriptions.has(key)) { return; // Already subscribed } console.error(`[WebSocket] Subscribing to ${channel} for ${instId}`); this.subscriptions.add(key); if (this.ws && this.ws.readyState === WebSocket.OPEN) { this.sendSubscription(channel, instId); } }

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/badger3000/okx-mcp-server'

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