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
| Name | Required | Description | Default |
|---|---|---|---|
| exchangeId | Yes | Exchange ID (e.g., 'binance', 'coinbase') |
Implementation Reference
- src/tools/market-tools.ts:20-45 (handler)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 }; } }
- src/tools/market-tools.ts:17-19 (schema)Zod schema defining the input parameters for the 'fetchMarkets' tool: exchangeId as a string.{ exchangeId: z.string().describe("Exchange ID (e.g., 'binance', 'coinbase')") },
- src/tools/market-tools.ts:15-46 (registration)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);
- src/server.ts:322-356 (helper)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]; }