Skip to main content
Glama
badger3000

OKX MCP Server

by badger3000

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

  • Executes the subscribe_ticker tool by subscribing to the WebSocket 'tickers' channel for the specified instrument via wsClient and returns a success confirmation message.
    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.`,
          },
        ],
      };
    }
  • src/index.ts:336-350 (registration)
    Registers the subscribe_ticker tool in the listTools response with name, description, and input schema.
    {
      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"],
      },
    },
  • Input schema definition for the subscribe_ticker tool requiring an 'instrument' string parameter.
    inputSchema: {
      type: "object",
      properties: {
        instrument: {
          type: "string",
          description: "Instrument ID (e.g. BTC-USDT)",
        },
      },
      required: ["instrument"],
    },
  • Implementation of the WebSocket subscription logic in OKXWebSocketClient class, which adds the subscription to the set and sends the subscribe message if connected.
    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