Skip to main content
Glama
gagarinyury

MCP Bitget Trading Server

by gagarinyury

getTicker

Retrieve real-time trading pair data including price, volume, and market information for cryptocurrency trading decisions on Bitget exchange.

Instructions

Get full ticker information for a trading pair

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
symbolYesTrading pair symbol

Implementation Reference

  • MCP server handler for 'getTicker' tool: parses arguments with GetTickerSchema, calls BitgetRestClient.getTicker(), and returns JSON stringified result.
    case 'getTicker': {
      const { symbol } = GetTickerSchema.parse(args);
      const ticker = await this.bitgetClient.getTicker(symbol);
      return {
        content: [
          {
            type: 'text',
            text: JSON.stringify(ticker, null, 2),
          },
        ],
      } as CallToolResult;
    }
  • Zod schema definition for getTicker tool input validation (symbol parameter).
    export const GetTickerSchema = z.object({
      symbol: z.string().describe('Trading pair symbol (BTCUSDT for spot, BTCUSDT_UMCBL for futures)')
    });
  • src/server.ts:114-124 (registration)
    Tool registration in MCP server's listTools response, defining name, description, and input schema.
    {
      name: 'getTicker',
      description: 'Get full ticker information for a trading pair',
      inputSchema: {
        type: 'object',
        properties: {
          symbol: { type: 'string', description: 'Trading pair symbol' }
        },
        required: ['symbol']
      },
    },
  • Core implementation of getTicker in BitgetRestClient: handles spot/futures detection, API calls to Bitget endpoints, caching with tickerCache, and formats Ticker response.
    async getTicker(symbol: string): Promise<Ticker> {
      const cacheKey = `ticker:${symbol}`;
      
      // Try cache first
      const cachedTicker = tickerCache.get(cacheKey);
      if (cachedTicker) {
        return cachedTicker;
      }
    
      let ticker: Ticker = {
        symbol: '',
        last: '',
        bid: '',
        ask: '',
        high24h: '',
        low24h: '',
        volume24h: '',
        change24h: '',
        changePercent24h: '',
        timestamp: 0
      };
      
      if (this.isFuturesSymbol(symbol)) {
        // Futures ticker
        const futuresSymbol = symbol.includes('_UMCBL') ? symbol : `${symbol}_UMCBL`;
        const response = await this.request<any>('GET', '/api/mix/v1/market/ticker', { symbol: futuresSymbol });
        if (response.data) {
          const tickerData = response.data;
          ticker = {
            symbol: tickerData.symbol,
            last: tickerData.last,
            bid: tickerData.bestBid,
            ask: tickerData.bestAsk,
            high24h: tickerData.high24h,
            low24h: tickerData.low24h,
            volume24h: tickerData.baseVolume,
            change24h: ((parseFloat(tickerData.last) - parseFloat(tickerData.openUtc)) / parseFloat(tickerData.openUtc) * 100).toFixed(2),
            changePercent24h: tickerData.priceChangePercent,
            timestamp: parseInt(tickerData.timestamp) || Date.now()
          };
        } else {
          throw new Error(`Ticker not found for symbol: ${symbol}`);
        }
      } else {
        // Spot ticker - use v1 public API
        const response = await this.request<any>('GET', '/api/spot/v1/market/tickers', {});
        if (response.data && Array.isArray(response.data)) {
          const tickerData = response.data.find((t: any) => t.symbol === symbol);
          if (tickerData) {
            ticker = {
              symbol: tickerData.symbol,
              last: tickerData.close,
              bid: tickerData.buyOne,
              ask: tickerData.sellOne,
              high24h: tickerData.high24h,
              low24h: tickerData.low24h,
              volume24h: tickerData.baseVol,
              change24h: tickerData.change,
              changePercent24h: tickerData.changePercent,
              timestamp: parseInt(tickerData.ts) || Date.now()
            };
          } else {
            throw new Error(`Ticker not found for symbol: ${symbol}`);
          }
        } else {
          throw new Error(`Ticker not found for symbol: ${symbol}`);
        }
      }
      
      // Cache the result
      tickerCache.set(cacheKey, ticker);
      return ticker;
    }

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