confirmOrder
Preview order costs and requirements before execution to verify trade details and avoid errors in the TradeStation MCP Server.
Instructions
Preview order costs and requirements (READ-ONLY - does not execute trades)
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| accountId | No | Account ID (optional, uses TRADESTATION_ACCOUNT_ID from env if not provided) | |
| symbol | Yes | Symbol to trade (e.g., SPY, SPY 251121C580) | |
| quantity | Yes | Order quantity | |
| orderType | Yes | Order type | |
| tradeAction | Yes | Trade action | |
| limitPrice | No | Limit price (required for Limit and StopLimit orders) | |
| stopPrice | No | Stop price (required for Stop and StopLimit orders) | |
| duration | No | Time in force duration | DAY |
Implementation Reference
- src/index.ts:706-767 (handler)Executes the confirmOrder tool logic: constructs order preview data based on parameters, calls TradeStation API endpoint '/orderexecution/orderconfirm' via POST, returns confirmation details or error.async (args) => { try { const accountId = args.accountId || TS_ACCOUNT_ID; const { symbol, quantity, orderType, tradeAction, limitPrice, stopPrice, duration } = args; if (!accountId) { throw new Error('Account ID is required. Either provide accountId parameter or set TRADESTATION_ACCOUNT_ID in .env file.'); } // Build order confirmation request body const orderData: any = { AccountID: accountId, Symbol: symbol, Quantity: quantity, OrderType: orderType, TradeAction: tradeAction, TimeInForce: { Duration: duration } }; // Add price fields based on order type if (orderType === 'Limit' || orderType === 'StopLimit') { if (!limitPrice) { throw new Error('limitPrice is required for Limit and StopLimit orders'); } orderData.LimitPrice = limitPrice; } if (orderType === 'Stop' || orderType === 'StopLimit') { if (!stopPrice) { throw new Error('stopPrice is required for Stop and StopLimit orders'); } orderData.StopPrice = stopPrice; } const confirmation = await makeAuthenticatedRequest( '/orderexecution/orderconfirm', 'POST', orderData ); return { content: [ { type: "text", text: JSON.stringify(confirmation, null, 2) } ] }; } catch (error: unknown) { return { content: [ { type: "text", text: `Failed to confirm order: ${error instanceof Error ? error.message : 'Unknown error'}` } ], isError: true }; } }
- src/index.ts:133-142 (schema)Zod schema defining the input parameters and validation for the confirmOrder tool.const confirmOrderSchema = { accountId: z.string().optional().describe('Account ID (optional, uses TRADESTATION_ACCOUNT_ID from env if not provided)'), symbol: z.string().describe('Symbol to trade (e.g., SPY, SPY 251121C580)'), quantity: z.number().describe('Order quantity'), orderType: z.enum(['Market', 'Limit', 'Stop', 'StopLimit']).describe('Order type'), tradeAction: z.enum(['BUY', 'SELL', 'BUYTOOPEN', 'BUYTOCLOSE', 'SELLTOOPEN', 'SELLTOCLOSE']).describe('Trade action'), limitPrice: z.number().optional().describe('Limit price (required for Limit and StopLimit orders)'), stopPrice: z.number().optional().describe('Stop price (required for Stop and StopLimit orders)'), duration: z.enum(['DAY', 'GTC', 'GTD', 'DYP', 'GCP']).default('DAY').describe('Time in force duration') };
- src/index.ts:702-768 (registration)Registers the confirmOrder tool with the MCP server using server.tool(), providing name, description, input schema, and handler function.server.tool( "confirmOrder", "Preview order costs and requirements (READ-ONLY - does not execute trades)", confirmOrderSchema, async (args) => { try { const accountId = args.accountId || TS_ACCOUNT_ID; const { symbol, quantity, orderType, tradeAction, limitPrice, stopPrice, duration } = args; if (!accountId) { throw new Error('Account ID is required. Either provide accountId parameter or set TRADESTATION_ACCOUNT_ID in .env file.'); } // Build order confirmation request body const orderData: any = { AccountID: accountId, Symbol: symbol, Quantity: quantity, OrderType: orderType, TradeAction: tradeAction, TimeInForce: { Duration: duration } }; // Add price fields based on order type if (orderType === 'Limit' || orderType === 'StopLimit') { if (!limitPrice) { throw new Error('limitPrice is required for Limit and StopLimit orders'); } orderData.LimitPrice = limitPrice; } if (orderType === 'Stop' || orderType === 'StopLimit') { if (!stopPrice) { throw new Error('stopPrice is required for Stop and StopLimit orders'); } orderData.StopPrice = stopPrice; } const confirmation = await makeAuthenticatedRequest( '/orderexecution/orderconfirm', 'POST', orderData ); return { content: [ { type: "text", text: JSON.stringify(confirmation, null, 2) } ] }; } catch (error: unknown) { return { content: [ { type: "text", text: `Failed to confirm order: ${error instanceof Error ? error.message : 'Unknown error'}` } ], isError: true }; } } );