Skip to main content
Glama

fetchMarkets

Retrieve market data from cryptocurrency exchanges to access trading pairs, symbols, and exchange-specific information for analysis and trading decisions.

Instructions

Fetch markets from a cryptocurrency exchange

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
exchangeIdYesExchange ID (e.g., 'binance', 'coinbase')

Implementation Reference

  • The core handler function for the 'fetchMarkets' tool. It retrieves a public CCXT exchange instance, loads the markets, and returns the JSON-stringified markets data or an error message.
    async ({ exchangeId }) => { try { // 공개 인스턴스 사용 const exchange = ccxtServer.getPublicExchangeInstance(exchangeId); const markets = await exchange.loadMarkets(); return { content: [ { type: "text", text: JSON.stringify(markets, null, 2) } ] }; } catch (error) { return { content: [ { type: "text", text: `Error fetching markets: ${(error as Error).message}` } ], isError: true }; } }
  • Zod schema defining the input parameters for the 'fetchMarkets' tool: exchangeId as a string.
    { exchangeId: z.string().describe("Exchange ID (e.g., 'binance', 'coinbase')") },
  • The server.tool() call that registers the 'fetchMarkets' tool, including its name, description, input schema, and handler function.
    "fetchMarkets", "Fetch markets from a cryptocurrency exchange", { exchangeId: z.string().describe("Exchange ID (e.g., 'binance', 'coinbase')") }, async ({ exchangeId }) => { try { // 공개 인스턴스 사용 const exchange = ccxtServer.getPublicExchangeInstance(exchangeId); const markets = await exchange.loadMarkets(); return { content: [ { type: "text", text: JSON.stringify(markets, null, 2) } ] }; } catch (error) { return { content: [ { type: "text", text: `Error fetching markets: ${(error as Error).message}` } ], isError: true }; } } );
  • src/server.ts:372-372 (registration)
    Invocation of registerMarketTools within CcxtMcpServer's registerTools() method, which triggers the registration of 'fetchMarkets' and other market tools.
    registerMarketTools(this.server, this);
  • Helper method getPublicExchangeInstance used by the fetchMarkets handler to obtain an unauthenticated CCXT exchange instance for loading markets.
    exchangeId: string, marketType: "spot" | "futures" = "spot", ): Exchange { const instanceKey = `${exchangeId}-${marketType}`; if (!this.publicExchangeInstances[instanceKey]) { if (!ccxt.exchanges.includes(exchangeId)) { console.error( `Exchange ID '${exchangeId}' not found in ccxt.exchanges for public instance.`, ); throw new Error(`Unsupported exchange for public data: ${exchangeId}`); } const exchangeOptions = { options: { defaultType: marketType, }, }; try { // @ts-ignore - CCXT dynamic instantiation without credentials this.publicExchangeInstances[instanceKey] = new ccxt[exchangeId]( exchangeOptions, ); } catch (error) { console.error( `Failed to create public CCXT instance for ${exchangeId} (${marketType}):`, error, ); throw error; // Re-throw the error after logging } } return this.publicExchangeInstances[instanceKey]; }

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/lazy-dinosaur/ccxt-mcp'

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