getOrders
Retrieve order history from TradeStation accounts with status filtering options to track trading activity.
Instructions
Get order history with optional status filter
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": "getOrders"
}
}Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| accountId | No | Account ID (optional, uses TRADESTATION_ACCOUNT_ID from env if not provided) | |
| status | No | Filter orders by status | All |
Implementation Reference
- src/index.ts:551-587 (handler)Handler function that fetches account orders from TradeStation API, optionally filtering by status (Open, Filled, etc.). Uses makeAuthenticatedRequest helper.
async (args) => { try { const accountId = args.accountId || TS_ACCOUNT_ID; const { status } = args; if (!accountId) { throw new Error('Account ID is required. Either provide accountId parameter or set TRADESTATION_ACCOUNT_ID in .env file.'); } let endpoint = `/brokerage/accounts/${encodeURIComponent(accountId)}/orders`; if (status && status !== 'All') { endpoint += `?status=${status}`; } const orders = await makeAuthenticatedRequest(endpoint); return { content: [ { type: "text", text: JSON.stringify(orders, null, 2) } ] }; } catch (error: unknown) { return { content: [ { type: "text", text: `Failed to fetch orders: ${error instanceof Error ? error.message : 'Unknown error'}` } ], isError: true }; } } - src/index.ts:112-117 (schema)Input schema for getOrders tool using Zod validation: optional accountId and status filter (defaults to 'All').
const ordersSchema = { accountId: z.string().optional().describe('Account ID (optional, uses TRADESTATION_ACCOUNT_ID from env if not provided)'), status: z.enum(['Open', 'Filled', 'Canceled', 'Rejected', 'All']) .default('All') .describe('Filter orders by status') }; - src/index.ts:547-588 (registration)MCP server registration of the 'getOrders' tool with description, schema reference, and inline handler function.
server.tool( "getOrders", "Get order history with optional status filter", ordersSchema, async (args) => { try { const accountId = args.accountId || TS_ACCOUNT_ID; const { status } = args; if (!accountId) { throw new Error('Account ID is required. Either provide accountId parameter or set TRADESTATION_ACCOUNT_ID in .env file.'); } let endpoint = `/brokerage/accounts/${encodeURIComponent(accountId)}/orders`; if (status && status !== 'All') { endpoint += `?status=${status}`; } const orders = await makeAuthenticatedRequest(endpoint); return { content: [ { type: "text", text: JSON.stringify(orders, null, 2) } ] }; } catch (error: unknown) { return { content: [ { type: "text", text: `Failed to fetch orders: ${error instanceof Error ? error.message : 'Unknown error'}` } ], isError: true }; } } );