get_orderbook
Retrieve current bid and ask price levels for cryptocurrency markets to analyze market depth and liquidity for trading decisions.
Instructions
Get the current orderbook (bid/ask levels) for a market.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| symbol | Yes | Market symbol, e.g. "BTC-KRW" | |
| depth | No | Number of price levels (default 20) |
Implementation Reference
- src/index.ts:329-334 (handler)The handler function for get_orderbook tool that executes the tool logic. It makes an API GET request to fetch orderbook data for a specific market symbol with configurable depth, then returns the data as JSON text content.
async ({ symbol, depth }) => { const data = await apiGet<unknown>(`/markets/${symbol}/orderbook?depth=${depth}`); return { content: [{ type: "text" as const, text: JSON.stringify(data, null, 2) }], }; } - src/index.ts:325-328 (schema)Zod schema definition for get_orderbook tool inputs: 'symbol' (required string, e.g., 'BTC-KRW') and 'depth' (optional number with default value 20 for number of price levels).
{ symbol: z.string().describe('Market symbol, e.g. "BTC-KRW"'), depth: z.number().optional().default(20).describe("Number of price levels (default 20)"), }, - src/index.ts:322-335 (registration)Complete registration of get_orderbook tool with the MCP server using server.tool(). Includes tool name, description, schema, and handler function.
server.tool( "get_orderbook", "Get the current orderbook (bid/ask levels) for a market.", { symbol: z.string().describe('Market symbol, e.g. "BTC-KRW"'), depth: z.number().optional().default(20).describe("Number of price levels (default 20)"), }, async ({ symbol, depth }) => { const data = await apiGet<unknown>(`/markets/${symbol}/orderbook?depth=${depth}`); return { content: [{ type: "text" as const, text: JSON.stringify(data, null, 2) }], }; } ); - src/index.ts:91-100 (helper)The apiGet helper function used by get_orderbook handler to make authenticated HTTP GET requests to the API. Handles response validation and error handling.
async function apiGet<T>(path: string): Promise<T> { const res = await fetch(`${API_BASE}${path}`, { headers: getAuthHeaders(), }); if (!res.ok) { const text = await res.text(); throw new Error(`API GET ${path} failed (${res.status}): ${text}`); } return res.json() as Promise<T>; }