GET_TRADES
Retrieve the most recent trades for a specific Upbit market by providing the market code (e.g., KRW-BTC).
Instructions
Get recent trades for a market
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| market | Yes | Upbit market code, e.g., KRW-BTC |
Implementation Reference
- src/tools/get-trades.ts:11-22 (handler)The GET_TRADES tool definition and execute handler. Makes a GET request to /trades/ticks on the Upbit API and returns the recent trades data for a given market.
export const getTradesTool = { name: "GET_TRADES", description: "Get recent trades for a 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, "/trades/ticks", { params: { market }, }); return JSON.stringify(data, null, 2); }, - src/tools/get-trades.ts:5-7 (schema)Input validation schema requiring 'market' (string, min 3 chars, e.g., KRW-BTC).
const paramsSchema = z.object({ market: z.string().min(3).describe("Upbit market code, e.g., KRW-BTC"), }); - src/index.ts:33-33 (registration)Registration of getTradesTool via server.addTool() in main()
server.addTool(getTradesTool); - src/lib/http.ts:16-30 (helper)createHttpClient helper used by the handler to build the Axios HTTP client
export function createHttpClient(baseURL?: string): AxiosInstance { const client = axios.create({ baseURL, timeout: 15_000 }); axiosRetry(client, { retries: 3, retryDelay: axiosRetry.exponentialDelay, retryCondition: (error) => { if (axiosRetry.isNetworkOrIdempotentRequestError(error)) return true; const status = error.response?.status ?? 0; return status === 429 || (status >= 500 && status < 600); }, }); return client; } - src/lib/http.ts:32-67 (helper)fetchJson helper used by the handler to execute the GET request and parse the response
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; } }