barChart
Retrieve historical price bars and candlestick data for trading symbols to analyze market trends and patterns.
Instructions
Get historical price bars/candles
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| symbol | Yes | Trading symbol | |
| interval | Yes | Bar interval value (e.g., 1, 5, 15) | |
| unit | Yes | Bar interval unit | |
| beginTime | No | Begin time in ISO format (optional) | |
| endTime | No | End time in ISO format (optional) | |
| barsBack | No | Number of bars to return (optional) |
Implementation Reference
- index.js:462-501 (handler)Handler function that parses input parameters, constructs the TradeStation API endpoint for bar chart data, authenticates and fetches the historical price bars, and returns the JSON response or error.
async ({ arguments: args }) => { try { const { symbol, interval, unit, beginTime, endTime, barsBack } = args; const userId = args.userId; // You might need to pass this differently let endpoint = `/marketdata/barcharts/${encodeURIComponent(symbol)}?interval=${interval}&unit=${unit}`; if (beginTime) { endpoint += `&begin=${encodeURIComponent(beginTime)}`; } if (endTime) { endpoint += `&end=${encodeURIComponent(endTime)}`; } if (barsBack) { endpoint += `&barsback=${barsBack}`; } const bars = await makeAuthenticatedRequest(userId, endpoint); return { content: [ { type: "text", text: JSON.stringify(bars, null, 2) } ] }; } catch (error) { return { content: [ { type: "text", text: `Failed to fetch bar chart data: ${error.message}` } ], isError: true }; } } - index.js:78-85 (schema)Zod schema defining the input parameters for the barChart tool: symbol (required), interval (number), unit (enum), and optional beginTime, endTime, barsBack.
const barChartSchema = z.object({ symbol: z.string().describe('Trading symbol'), interval: z.number().describe('Bar interval value (e.g., 1, 5, 15)'), unit: z.enum(['Minute', 'Daily', 'Weekly', 'Monthly']).describe('Bar interval unit'), beginTime: z.string().optional().describe('Begin time in ISO format (optional)'), endTime: z.string().optional().describe('End time in ISO format (optional)'), barsBack: z.number().optional().describe('Number of bars to return (optional)') }); - index.js:458-502 (registration)Registers the barChart tool with the MCP server using server.tool(), providing name, description, input schema, and handler function.
server.tool( "barChart", "Get historical price bars/candles", barChartSchema, async ({ arguments: args }) => { try { const { symbol, interval, unit, beginTime, endTime, barsBack } = args; const userId = args.userId; // You might need to pass this differently let endpoint = `/marketdata/barcharts/${encodeURIComponent(symbol)}?interval=${interval}&unit=${unit}`; if (beginTime) { endpoint += `&begin=${encodeURIComponent(beginTime)}`; } if (endTime) { endpoint += `&end=${encodeURIComponent(endTime)}`; } if (barsBack) { endpoint += `&barsback=${barsBack}`; } const bars = await makeAuthenticatedRequest(userId, endpoint); return { content: [ { type: "text", text: JSON.stringify(bars, null, 2) } ] }; } catch (error) { return { content: [ { type: "text", text: `Failed to fetch bar chart data: ${error.message}` } ], isError: true }; } } ); - src/index.ts:295-333 (handler)TypeScript handler function for barChart tool, similar to JS version, constructs endpoint and fetches data using makeAuthenticatedRequest.
async (args) => { try { const { symbol, interval, unit, beginTime, endTime, barsBack } = args; let endpoint = `/marketdata/barcharts/${encodeURIComponent(symbol)}?interval=${interval}&unit=${unit}`; if (beginTime) { endpoint += `&begin=${encodeURIComponent(beginTime)}`; } if (endTime) { endpoint += `&end=${encodeURIComponent(endTime)}`; } if (barsBack) { endpoint += `&barsback=${barsBack}`; } const bars = await makeAuthenticatedRequest(endpoint); return { content: [ { type: "text", text: JSON.stringify(bars, null, 2) } ] }; } catch (error: unknown) { return { content: [ { type: "text", text: `Failed to fetch bar chart data: ${error instanceof Error ? error.message : 'Unknown error'}` } ], isError: true }; } } - src/index.ts:76-83 (schema)Input schema object for barChart tool parameters in TypeScript version.
const barChartSchema = { symbol: z.string().describe('Trading symbol'), interval: z.number().describe('Bar interval value (e.g., 1, 5, 15)'), unit: z.enum(['Minute', 'Daily', 'Weekly', 'Monthly']).describe('Bar interval unit'), beginTime: z.string().optional().describe('Begin time in ISO format (optional)'), endTime: z.string().optional().describe('End time in ISO format (optional)'), barsBack: z.number().optional().describe('Number of bars to return (optional)') };