Skip to main content
Glama
badger3000

OKX MCP Server

by badger3000

unsubscribe_ticker

Stop receiving real-time price updates for a specific cryptocurrency trading pair on the OKX exchange to manage data streams and reduce unnecessary notifications.

Instructions

Unsubscribe from real-time ticker updates for an instrument

Input Schema

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

Implementation Reference

  • Main execution logic for the unsubscribe_ticker tool: logs the action, calls the WebSocket client's unsubscribe method for the 'tickers' channel, and returns a success confirmation message.
    if (request.params.name === "unsubscribe_ticker") {
      console.error(
        `[WebSocket] Unsubscribing from ticker for ${args.instrument}`
      );
      this.wsClient.unsubscribe("tickers", args.instrument);
    
      return {
        content: [
          {
            type: "text",
            text: `Successfully unsubscribed from real-time ticker updates for ${args.instrument}.`,
          },
        ],
      };
    }
  • Input schema definition for the unsubscribe_ticker tool, specifying the required 'instrument' parameter.
    {
      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"],
      },
    },
  • src/index.ts:390-396 (registration)
    Registration of unsubscribe_ticker as a valid tool name in the dispatch logic for CallToolRequestSchema.
    const validTools = [
      "get_price",
      "get_candlesticks",
      "subscribe_ticker",
      "get_live_ticker",
      "unsubscribe_ticker",
    ];
  • Helper method in OKXWebSocketClient class that performs the actual WebSocket unsubscription, used by the tool handler.
    unsubscribe(channel: string, instId: string): void {
      const key = `${channel}:${instId}`;
    
      if (!this.subscriptions.has(key)) {
        return; // Not subscribed
      }
    
      console.error(`[WebSocket] Unsubscribing from ${channel} for ${instId}`);
      this.subscriptions.delete(key);
    
      if (this.ws && this.ws.readyState === WebSocket.OPEN) {
        this.ws.send(
          JSON.stringify({
            op: "unsubscribe",
            args: [
              {
                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