get_open_orders
Retrieve all currently open orders from your OKX trading account to monitor active trades and manage your portfolio effectively.
Instructions
Get all currently open orders
Tool call template
This tool declares no required parameters. Add optional parameters from the input schema as needed.
{
"id": 1,
"jsonrpc": "2.0",
"method": "tools/call",
"params": {
"arguments": {},
"name": "get_open_orders"
}
}Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
No arguments | |||
Implementation Reference
- src/tools/get_open_orders.ts:21-33 (handler)The main handler function for the 'get_open_orders' tool. It calls the OKX API client to fetch open orders and returns them as formatted JSON or an error message.
export default async function get_open_orders({}: InferSchema<typeof schema>) { try { const openOrders = await okxApiClient.getOpenOrders(); return { content: [{ type: 'text', text: JSON.stringify(openOrders, null, 2) }], }; } catch (error) { const message = error instanceof Error ? error.message : 'An unknown error occurred'; return { content: [{ type: 'text', text: JSON.stringify({ error: message }, null, 2) }], }; } } - src/tools/get_open_orders.ts:8-8 (schema)The input schema for the tool, which is empty indicating no input parameters are required.
export const schema = {}; - src/tools/get_open_orders.ts:10-19 (registration)Metadata object that registers the tool with MCP, including name, description, and annotations.
export const metadata = { name: 'get_open_orders', description: 'Get all currently open orders', annotations: { title: 'Get Open Orders', readOnlyHint: true, destructiveHint: false, idempotentHint: true, }, }; - src/services/okxApiClient.ts:57-72 (helper)Supporting helper method in the OKX API client class that retrieves the list of open orders from the OKX exchange.
async getOpenOrders() { try { const response = await client.getOrderList(); return response.map((order) => ({ orderId: order.ordId, symbol: order.instId, type: order.ordType, price: parseFloat(order.px), amount: parseFloat(order.sz), side: order.side, status: order.state, })); } catch (error) { console.error("Error fetching open orders:", error); throw error; }