GET_ORDERBOOK
Retrieve the current orderbook snapshot for a specific Upbit market. Enter the market code to get bid and ask depth data.
Instructions
Get orderbook snapshot for a given market
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| market | Yes | Upbit market code, e.g., KRW-BTC |
Implementation Reference
- src/tools/get-orderbook.ts:15-24 (handler)The execute function that calls Upbit API /orderbook with the market parameter and returns the first orderbook entry as formatted JSON.
execute: async ({ market }: Params) => { const baseURL = `${config.upbit.baseUrl}${config.upbit.apiBasePath}`; const client = createHttpClient(baseURL); const data = await fetchJson<unknown>(client, "/orderbook", { params: { markets: market }, }); /** biome-ignore lint/suspicious/noExplicitAny: <not important> */ const item = Array.isArray(data) ? (data as any[])[0] : (data as any); return JSON.stringify(item, null, 2); }, - src/tools/get-orderbook.ts:5-7 (schema)Zod schema defining the input parameter: a market string (min 3 characters).
const paramsSchema = z.object({ market: z.string().min(3).describe("Upbit market code, e.g., KRW-BTC"), }); - src/index.ts:32-32 (registration)Registration of the GET_ORDERBOOK tool on the FastMCP server.
server.addTool(getOrderbookTool); - src/tools/get-orderbook.ts:11-25 (registration)Tool definition object with name 'GET_ORDERBOOK', description, parameters schema, and execute handler.
export const getOrderbookTool = { name: "GET_ORDERBOOK", description: "Get orderbook snapshot for a given market", parameters: paramsSchema, execute: async ({ market }: Params) => { const baseURL = `${config.upbit.baseUrl}${config.upbit.apiBasePath}`; const client = createHttpClient(baseURL); const data = await fetchJson<unknown>(client, "/orderbook", { params: { markets: market }, }); /** biome-ignore lint/suspicious/noExplicitAny: <not important> */ const item = Array.isArray(data) ? (data as any[])[0] : (data as any); return JSON.stringify(item, null, 2); }, } as const; - src/lib/http.ts:32-67 (helper)Generic HTTP helper used by the handler to fetch JSON data from the Upbit API.
export async function fetchJson<T>( client: AxiosInstance, url: string, options: { method?: "GET" | "POST" | "DELETE" | "PUT" | "PATCH"; params?: Record<string, unknown>; data?: unknown; headers?: Record<string, string>; } = {}, schema?: z.ZodType<T>, ): Promise<T> { try { const response = await client.request({ url, method: options.method ?? "GET", params: options.params, data: options.data, headers: options.headers, }); const data = response.data; if (schema) { return schema.parse(data); } return data as T; } catch (err) { if (axios.isAxiosError(err)) { const ae = err as AxiosError; const status = ae.response?.status ?? 0; const message = ae.message || "HTTP request failed"; const data = ae.response?.data; throw new HttpError(status, message, data); } throw err; } }