fetchOpenOrders
Retrieve all open orders from a cryptocurrency exchange account to monitor active trades and manage positions.
Instructions
Fetch all open 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:239-287 (handler)The main handler function for the 'fetchOpenOrders' MCP tool. It retrieves the authenticated CCXT exchange instance, checks if the exchange supports fetchOpenOrders, executes the method with provided parameters (symbol, since, limit, params), and returns the result as JSON or an error response.async ({ accountName, symbol, since, limit, params }) => { try { const exchange = ccxtServer.getExchangeInstance(accountName); // getExchangeInstance가 성공하면 인증은 보장됨 // fetchOpenOrders 메서드가 지원되는지 확인 if (!exchange.has["fetchOpenOrders"]) { return { content: [ { type: "text", text: `Account '${accountName}' (Exchange: ${exchange.id}) does not support fetching open orders`, }, ], isError: true, }; } const openOrders = await exchange.fetchOpenOrders( symbol, since, limit, params, ); return { content: [ { type: "text", text: JSON.stringify(openOrders, null, 2), }, ], }; } catch (error) { return { content: [ { type: "text", text: `Error fetching open orders for account '${accountName}': ${ (error as Error).message }`, }, ], isError: true, }; } }, );
- src/tools/order-tools.ts:216-238 (schema)Zod input schema defining parameters for the fetchOpenOrders tool: accountName (string, required), symbol (string, optional), since (number, optional), limit (number, optional), params (record, 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:213-287 (registration)Local registration of the fetchOpenOrders tool within the registerOrderTools function using server.tool(name, description, inputSchema, handler).server.tool( "fetchOpenOrders", "Fetch all open 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가 성공하면 인증은 보장됨 // fetchOpenOrders 메서드가 지원되는지 확인 if (!exchange.has["fetchOpenOrders"]) { return { content: [ { type: "text", text: `Account '${accountName}' (Exchange: ${exchange.id}) does not support fetching open orders`, }, ], isError: true, }; } const openOrders = await exchange.fetchOpenOrders( symbol, since, limit, params, ); return { content: [ { type: "text", text: JSON.stringify(openOrders, null, 2), }, ], }; } catch (error) { return { content: [ { type: "text", text: `Error fetching open orders for account '${accountName}': ${ (error as Error).message }`, }, ], isError: true, }; } }, );
- src/server.ts:373-373 (registration)Top-level registration call to registerOrderTools in CcxtMcpServer.registerTools(), which includes registering the fetchOpenOrders tool.registerOrderTools(this.server, this);
- src/server.ts:291-303 (helper)Helper method used by the handler to retrieve the pre-loaded, authenticated CCXT Exchange instance for the specified accountName.getExchangeInstance(accountName: string): Exchange { const instance = this.exchangeInstances[accountName]; if (!instance) { console.error( `No pre-loaded exchange instance found for account name: ${accountName}`, ); // Consider listing available account names: Object.keys(this.exchangeInstances).join(', ') throw new Error( `Account configuration not found or failed to load for: ${accountName}`, ); } return instance; }