Skip to main content
Glama

get_ticker

Retrieve real-time trading data including price, bid/ask spread, and volume for cryptocurrency pairs on supported exchanges like MEXC, Gate.io, Bitget, and Kraken.

Instructions

Get real-time price, bid/ask, spread, and volume for a trading pair on a supported exchange

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
exchangeYesExchange to query. Supported: mexc, gateio, bitget, kraken
symbolYesTrading pair symbol (e.g., BTC/USDT, INDY/USDT)

Implementation Reference

  • Main tool registration and handler implementation. Validates exchange and symbol parameters, fetches ticker data via connector.getTicker(), and returns formatted JSON with price, bid/ask, spread, volume, and timestamp.
    server.tool(
      'get_ticker',
      'Get real-time price, bid/ask, spread, and volume for a trading pair on a supported exchange',
      {
        exchange: ExchangeParam,
        symbol: SymbolParam,
      },
      async ({ exchange, symbol }) => {
        const validExchange = validateExchange(exchange);
        const validSymbol = validateSymbol(symbol);
    
        const connector = await getConnectorSafe(exchange);
        const ticker = await connector.getTicker(validSymbol);
    
        return {
          content: [
            {
              type: 'text' as const,
              text: JSON.stringify(
                {
                  symbol: ticker.symbol,
                  last: ticker.last,
                  bid: ticker.bid,
                  ask: ticker.ask,
                  spread: ticker.ask - ticker.bid,
                  spreadPercent: ((ticker.ask - ticker.bid) / ticker.ask) * 100,
                  baseVolume: ticker.baseVolume,
                  quoteVolume: ticker.quoteVolume,
                  timestamp: ticker.timestamp,
                  exchange: validExchange,
                },
                null,
                2
              ),
            },
          ],
        };
      }
    );
  • Zod schema definitions for tool input parameters. ExchangeParam validates supported exchanges (mexc, gateio, bitget, kraken). SymbolParam validates trading pair symbols like BTC/USDT.
    export const ExchangeParam = z
      .string()
      .describe('Exchange to query. Supported: mexc, gateio, bitget, kraken');
    
    export const SymbolParam = z.string().describe('Trading pair symbol (e.g., BTC/USDT, INDY/USDT)');
  • Registers all tool categories with the MCP server, including registerMarketDataTools which contains get_ticker.
    export function registerTools(server: McpServer): void {
      registerMarketDataTools(server);
      registerAccountTools(server);
      registerTradingTools(server);
      registerCardanoTools(server);
      registerStrategyTools(server);
    }
  • Helper functions to validate exchange names and safely instantiate exchange connectors. Used by get_ticker handler to fetch data from the correct exchange.
    export function validateExchange(exchange: string): SupportedExchange {
      const lower = exchange.toLowerCase();
      if (!(SUPPORTED_EXCHANGES as readonly string[]).includes(lower)) {
        throw new Error(
          `Unsupported exchange: ${exchange}. Supported: ${SUPPORTED_EXCHANGES.join(', ')}`
        );
      }
      return lower as SupportedExchange;
    }
    
    export async function getConnectorSafe(exchange: string): Promise<BaseExchangeConnector> {
      const validExchange = validateExchange(exchange);
      const { ExchangeFactory } = await import('@3rd-eye-labs/openmm');
      try {
        return await ExchangeFactory.getExchange(validExchange as any);
      } catch (error) {
        const message = error instanceof Error ? error.message : String(error);
        throw new Error(`Failed to connect to ${validExchange}: ${message}`);
      }
    }
  • Symbol validation helper that checks format and converts to uppercase. Used by get_ticker to validate the trading pair symbol.
    export function validateSymbol(symbol: string): string {
      if (!symbol) {
        throw new Error('Symbol is required');
      }
      const upper = symbol.toUpperCase();
      if (!/^[A-Z]+\/[A-Z]+$/.test(upper) && !/^[A-Z]+[A-Z]+$/.test(upper)) {
        throw new Error(`Invalid symbol format: ${symbol}. Expected: BTC/USDT or BTCUSDT`);
      }
      return upper;
    }

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/QBT-Labs/openmm-mcp'

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