fetchClosedOrders
Retrieve all completed orders from cryptocurrency exchanges to track trading history, analyze performance, and maintain records using configured exchange accounts.
Instructions
Fetch all closed orders using a configured account
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| accountName | Yes | Account name defined in the configuration file (e.g., 'bybit_main') | |
| symbol | No | Trading symbol (e.g., 'BTC/USDT') | |
| since | No | Timestamp in ms to fetch orders since (optional) | |
| limit | No | Limit the number of orders returned (optional) | |
| params | No | Additional exchange-specific parameters |
Implementation Reference
- src/tools/order-tools.ts:316-363 (handler)The handler function that implements the fetchClosedOrders tool. It retrieves the CCXT exchange instance, checks if fetchClosedOrders is supported, fetches the closed orders, and returns them as JSON or an error message.async ({ accountName, symbol, since, limit, params }) => { try { const exchange = ccxtServer.getExchangeInstance(accountName); // getExchangeInstance가 성공하면 인증은 보장됨 // fetchClosedOrders 메서드가 지원되는지 확인 if (!exchange.has["fetchClosedOrders"]) { return { content: [ { type: "text", text: `Account '${accountName}' (Exchange: ${exchange.id}) does not support fetching closed orders`, }, ], isError: true, }; } const closedOrders = await exchange.fetchClosedOrders( symbol, since, limit, params, ); return { content: [ { type: "text", text: JSON.stringify(closedOrders, null, 2), }, ], }; } catch (error) { return { content: [ { type: "text", text: `Error fetching closed orders for account '${accountName}': ${ (error as Error).message }`, }, ], isError: true, }; } },
- src/tools/order-tools.ts:293-315 (schema)The Zod schema defining the input parameters for the fetchClosedOrders tool: accountName (required), symbol, since, limit, params (all optional).{ accountName: z .string() .describe( "Account name defined in the configuration file (e.g., 'bybit_main')" ), symbol: z .string() .optional() .describe("Trading symbol (e.g., 'BTC/USDT')"), since: z .number() .optional() .describe("Timestamp in ms to fetch orders since (optional)"), limit: z .number() .optional() .describe("Limit the number of orders returned (optional)"), params: z .record(z.any()) .optional() .describe("Additional exchange-specific parameters"), },
- src/tools/order-tools.ts:290-365 (registration)The registration of the fetchClosedOrders tool using server.tool(), including name, description, input schema, and handler function. This is within the registerOrderTools function.server.tool( "fetchClosedOrders", "Fetch all closed orders using a configured account", { accountName: z .string() .describe( "Account name defined in the configuration file (e.g., 'bybit_main')" ), symbol: z .string() .optional() .describe("Trading symbol (e.g., 'BTC/USDT')"), since: z .number() .optional() .describe("Timestamp in ms to fetch orders since (optional)"), limit: z .number() .optional() .describe("Limit the number of orders returned (optional)"), params: z .record(z.any()) .optional() .describe("Additional exchange-specific parameters"), }, async ({ accountName, symbol, since, limit, params }) => { try { const exchange = ccxtServer.getExchangeInstance(accountName); // getExchangeInstance가 성공하면 인증은 보장됨 // fetchClosedOrders 메서드가 지원되는지 확인 if (!exchange.has["fetchClosedOrders"]) { return { content: [ { type: "text", text: `Account '${accountName}' (Exchange: ${exchange.id}) does not support fetching closed orders`, }, ], isError: true, }; } const closedOrders = await exchange.fetchClosedOrders( symbol, since, limit, params, ); return { content: [ { type: "text", text: JSON.stringify(closedOrders, null, 2), }, ], }; } catch (error) { return { content: [ { type: "text", text: `Error fetching closed orders for account '${accountName}': ${ (error as Error).message }`, }, ], isError: true, }; } }, ); }