get_aggregates
Retrieve aggregated financial market data for a specific ticker symbol over defined time periods. Specify ticker, time range, and interval to access historical price bars for analysis.
Instructions
Get aggregate bars for a ticker
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| ticker | Yes | Ticker symbol (e.g., AAPL) | |
| timespan | Yes | Size of the time window | |
| from | Yes | Start date (YYYY-MM-DD format) | |
| to | Yes | End date (YYYY-MM-DD format) | |
| adjusted | No | Whether to adjust for splits (default: true) | |
| sort | No | Sort order (default: asc) | |
| limit | No | Number of results (default: 120, max: 50000) |
Implementation Reference
- src/index.ts:82-117 (handler)The async handler function that implements the 'get_aggregates' tool logic, calling the Polygon API to retrieve aggregate bars (OHLCV data) for a ticker over a specified date range and timespan.get_aggregates: async (args: { ticker: string; timespan: string; from: string; to: string; adjusted?: boolean; sort?: string; limit?: number; }) => { try { const params: any = { adjusted: args.adjusted !== false, sort: args.sort || 'asc', limit: args.limit || 120 }; const response = await polygonApi.get( `/v2/aggs/ticker/${args.ticker}/range/1/${args.timespan}/${args.from}/${args.to}`, { params } ); return { content: [{ type: "text", text: JSON.stringify(response.data, null, 2) }] }; } catch (error: any) { return { content: [{ type: "text", text: `Error getting aggregates: ${error.response?.data?.message || error.message}` }], isError: true }; } },
- src/index.ts:275-310 (schema)The input schema definition for the 'get_aggregates' tool, specifying parameters like ticker, timespan, date range, and options for the API call.inputSchema: { type: "object", properties: { ticker: { type: "string", description: "Ticker symbol (e.g., AAPL)" }, timespan: { type: "string", enum: ["minute", "hour", "day", "week", "month", "quarter", "year"], description: "Size of the time window" }, from: { type: "string", description: "Start date (YYYY-MM-DD format)" }, to: { type: "string", description: "End date (YYYY-MM-DD format)" }, adjusted: { type: "boolean", description: "Whether to adjust for splits (default: true)" }, sort: { type: "string", enum: ["asc", "desc"], description: "Sort order (default: asc)" }, limit: { type: "number", description: "Number of results (default: 120, max: 50000)" } }, required: ["ticker", "timespan", "from", "to"] }
- src/index.ts:272-311 (registration)The tool registration in the ListTools response, including name, description, and input schema.{ name: "get_aggregates", description: "Get aggregate bars for a ticker", inputSchema: { type: "object", properties: { ticker: { type: "string", description: "Ticker symbol (e.g., AAPL)" }, timespan: { type: "string", enum: ["minute", "hour", "day", "week", "month", "quarter", "year"], description: "Size of the time window" }, from: { type: "string", description: "Start date (YYYY-MM-DD format)" }, to: { type: "string", description: "End date (YYYY-MM-DD format)" }, adjusted: { type: "boolean", description: "Whether to adjust for splits (default: true)" }, sort: { type: "string", enum: ["asc", "desc"], description: "Sort order (default: asc)" }, limit: { type: "number", description: "Number of results (default: 120, max: 50000)" } }, required: ["ticker", "timespan", "from", "to"] } },
- src/index.ts:405-407 (registration)The dynamic dispatch mechanism in the CallToolRequest handler that routes calls to the appropriate tool handler based on name.if (name in toolHandlers) { return await (toolHandlers as any)[name](args || {}); }