getBalances
Retrieve account balances and available buying power to monitor your trading capital and make informed investment decisions.
Instructions
Get account balances and buying power
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| accountId | No | Account ID (optional, uses TRADESTATION_ACCOUNT_ID from env if not provided) |
Input Schema (JSON Schema)
{
"properties": {
"accountId": {
"description": "Account ID (optional, uses TRADESTATION_ACCOUNT_ID from env if not provided)",
"type": "string"
}
},
"type": "object"
}
Implementation Reference
- src/index.ts:475-506 (handler)The handler function that executes the getBalances tool logic, fetching account balances from the TradeStation API endpoint `/brokerage/accounts/{accountId}/balances` using the shared makeAuthenticatedRequest helper.async (args) => { try { const accountId = args.accountId || TS_ACCOUNT_ID; if (!accountId) { throw new Error('Account ID is required. Either provide accountId parameter or set TRADESTATION_ACCOUNT_ID in .env file.'); } const balances = await makeAuthenticatedRequest( `/brokerage/accounts/${encodeURIComponent(accountId)}/balances` ); return { content: [ { type: "text", text: JSON.stringify(balances, null, 2) } ] }; } catch (error: unknown) { return { content: [ { type: "text", text: `Failed to fetch balances: ${error instanceof Error ? error.message : 'Unknown error'}` } ], isError: true }; } }
- src/index.ts:104-106 (schema)The Zod schema defining the input parameters for the getBalances tool, including optional accountId.const balancesSchema = { accountId: z.string().optional().describe('Account ID (optional, uses TRADESTATION_ACCOUNT_ID from env if not provided)') };
- src/index.ts:471-507 (registration)The registration of the getBalances tool using server.tool(), including name, description, schema, and handler function.server.tool( "getBalances", "Get account balances and buying power", balancesSchema, async (args) => { try { const accountId = args.accountId || TS_ACCOUNT_ID; if (!accountId) { throw new Error('Account ID is required. Either provide accountId parameter or set TRADESTATION_ACCOUNT_ID in .env file.'); } const balances = await makeAuthenticatedRequest( `/brokerage/accounts/${encodeURIComponent(accountId)}/balances` ); return { content: [ { type: "text", text: JSON.stringify(balances, null, 2) } ] }; } catch (error: unknown) { return { content: [ { type: "text", text: `Failed to fetch balances: ${error instanceof Error ? error.message : 'Unknown error'}` } ], isError: true }; } } );