CANCEL_ORDER
Cancel an existing order on Upbit by providing its UUID. Requires private API authentication.
Instructions
Cancel an existing Upbit order (requires private API)
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| uuid | Yes |
Implementation Reference
- src/tools/cancel-order.ts:12-29 (handler)The cancelOrderTool object with name 'CANCEL_ORDER', description, params schema, and execute handler that cancels an Upbit order via DELETE request.
export const cancelOrderTool = { name: "CANCEL_ORDER", description: "Cancel an existing Upbit order (requires private API)", parameters: paramsSchema, execute: async ({ uuid }: Params) => { ensurePrivateEnabled(); const baseURL = `${config.upbit.baseUrl}${config.upbit.apiBasePath}`; const client = createHttpClient(baseURL); const query = { uuid }; const token = signJwtToken(query); const data = await fetchJson<unknown>(client, "/order", { method: "DELETE", params: query, headers: { Authorization: `Bearer ${token}` }, }); return JSON.stringify(data, null, 2); }, } as const; - src/tools/cancel-order.ts:6-8 (schema)Zod schema for CANCEL_ORDER input: requires a 'uuid' string (min length 1).
const paramsSchema = z.object({ uuid: z.string().min(1), }); - src/index.ts:38-38 (registration)Registration of cancelOrderTool on the FastMCP server at line 38.
server.addTool(cancelOrderTool); - src/lib/upbit-auth.ts:5-16 (helper)ensurePrivateEnabled helper called before executing the cancel order.
export function ensurePrivateEnabled(): void { if (!config.upbit.enablePrivate) { throw new Error( "Private trading tools are disabled. Set UPBIT_ENABLE_TRADING=true to enable.", ); } if (!config.upbit.accessKey || !config.upbit.secretKey) { throw new Error( "Upbit API keys are not configured. Set UPBIT_ACCESS_KEY and UPBIT_SECRET_KEY.", ); } } - src/lib/upbit-auth.ts:18-41 (helper)signJwtToken helper used to sign the JWT for authenticating the DELETE request.
export function signJwtToken( params?: Record<string, string | number | boolean | undefined>, ): string { const payload: Record<string, unknown> = { access_key: config.upbit.accessKey, nonce: crypto.randomUUID(), }; if (params && Object.keys(params).length > 0) { const searchParams = new URLSearchParams(); const sortedKeys = Object.keys(params).sort(); for (const key of sortedKeys) { const value = params[key]; if (value === undefined) continue; searchParams.append(key, String(value)); } const encoded = searchParams.toString(); const queryHash = crypto.createHash("sha512").update(encoded).digest("hex"); payload.query_hash = queryHash; payload.query_hash_alg = "SHA512"; } return jwt.sign(payload, config.upbit.secretKey as string); }