Skip to main content
Glama

get_market_info

Retrieve real-time market data for cryptocurrency trading pairs on Bybit, including spot, linear, and inverse categories. Specify symbols and limit results for precise insights.

Instructions

Get detailed market information for trading pairs

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
categoryNoCategory of the instrument (spot, linear, inverse)
limitNoLimit for the number of results (max 1000)
symbolNoOptional: Trading pair symbol (e.g., 'BTCUSDT'). If not provided, returns info for all symbols in the category

Implementation Reference

  • Core handler function `toolCall` that validates input parameters (category, symbol, limit), calls Bybit's getInstrumentsInfo API, and formats the response or error.
    async toolCall(request: z.infer<typeof CallToolRequestSchema>) { try { const args = request.params.arguments as unknown if (!args || typeof args !== 'object') { throw new Error("Invalid arguments") } const typedArgs = args as Record<string, unknown> // Validate category explicitly if (typedArgs.category && typeof typedArgs.category === 'string') { if (!["spot", "linear", "inverse"].includes(typedArgs.category)) { throw new Error(`Invalid category: ${typedArgs.category}. Must be one of: spot, linear, inverse`) } } const category = ( typedArgs.category && typeof typedArgs.category === 'string' && ["spot", "linear", "inverse"].includes(typedArgs.category) ) ? typedArgs.category as SupportedCategory : CONSTANTS.DEFAULT_CATEGORY as SupportedCategory const symbol = typedArgs.symbol && typeof typedArgs.symbol === 'string' ? typedArgs.symbol : undefined const limit = ( typedArgs.limit && typeof typedArgs.limit === 'string' && ["1", "10", "50", "100", "200", "500", "1000"].includes(typedArgs.limit) ) ? parseInt(typedArgs.limit, 10) : 200 const params: GetInstrumentsInfoParamsV5 = { category, symbol, limit, } const response = await this.client.getInstrumentsInfo(params) if (response.retCode !== 0) { throw new Error(`Bybit API error: ${response.retMsg}`) } // Return the list array directly return this.formatResponse(response.result.list) } catch (error) { // Ensure error responses are properly formatted const errorMessage = error instanceof Error ? error.message : String(error) return { content: [{ type: "text" as const, text: errorMessage }], isError: true } } }
  • Tool schema definition including input schema with properties for category (spot/linear/inverse), optional symbol, and limit.
    toolDefinition: Tool = { name: this.name, description: "Get detailed market information for trading pairs", inputSchema: { type: "object", properties: { category: { type: "string", description: "Category of the instrument (spot, linear, inverse)", enum: ["spot", "linear", "inverse"], }, symbol: { type: "string", description: "Optional: Trading pair symbol (e.g., 'BTCUSDT'). If not provided, returns info for all symbols in the category", }, limit: { type: "string", description: "Limit for the number of results (max 1000)", enum: ["1", "10", "50", "100", "200", "500", "1000"], }, }, required: [], },
  • src/index.ts:134-136 (registration)
    Loads all tools dynamically using toolLoader and creates a map keyed by tool name for dispatching calls.
    const tools = await loadTools() toolsMap = createToolsMap(tools)
  • Dynamically discovers and instantiates all tool classes from src/tools directory, including GetMarketInfo, validating they extend BaseToolImplementation.
    export async function loadTools(): Promise<BaseToolImplementation[]> { try { const toolsPath = await findToolsPath() const files = await fs.readdir(toolsPath) const tools: BaseToolImplementation[] = [] for (const file of files) { if (!isToolFile(file)) { continue } try { const modulePath = `file://${join(toolsPath, file)}` const { default: ToolClass } = await import(modulePath) if (!ToolClass || typeof ToolClass !== 'function') { console.warn(JSON.stringify({ type: "warning", message: `Invalid tool class in ${file}` })) continue } const tool = new ToolClass() if ( tool instanceof BaseToolImplementation && tool.name && tool.toolDefinition && typeof tool.toolCall === "function" ) { tools.push(tool) console.info(JSON.stringify({ type: "info", message: `Loaded tool: ${tool.name}` })) } else { console.warn(JSON.stringify({ type: "warning", message: `Invalid tool implementation in ${file}` })) } } catch (error) { console.error(JSON.stringify({ type: "error", message: `Error loading tool from ${file}: ${error instanceof Error ? error.message : String(error)}` })) } } return tools } catch (error) { console.error(JSON.stringify({ type: "error", message: `Failed to load tools: ${error instanceof Error ? error.message : String(error)}` })) return [] } }
  • Helper method used by the handler to format successful API responses as MCP CallToolResult.
    protected formatResponse(data: any): CallToolResult { this.ensureInitialized() const content: TextContent = { type: "text", text: JSON.stringify(data, null, 2), annotations: { audience: ["assistant", "user"], priority: 1 } } return { content: [content] } }

Other Tools

Related Tools

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/sammcj/bybit-mcp'

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