get_candles
Retrieve historical OHLCV candlestick data for financial instruments from T-Invest. Specify ticker, date range, and interval to analyze price movements and trends.
Instructions
Получить исторические свечи (OHLCV) по тикеру из Т-Инвестиций
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| ticker | Yes | Тикер инструмента | |
| from | Yes | Начало периода (ISO 8601, например 2024-01-01T00:00:00Z) | |
| to | Yes | Конец периода (ISO 8601) | |
| interval | No | Интервал свечи | day |
Implementation Reference
- src/tools/get-candles.ts:20-68 (handler)The `registerGetCandles` function registers the `get_candles` tool and defines its handler logic, which resolves a ticker to a figi, calls the API, and formats the candle output.
export function registerGetCandles(server: McpServer, client: TInvestClient): void { server.tool( 'get_candles', 'Получить исторические свечи (OHLCV) по тикеру из Т-Инвестиций', { ticker: z.string().describe('Тикер инструмента'), from: z.string().describe('Начало периода (ISO 8601, например 2024-01-01T00:00:00Z)'), to: z.string().describe('Конец периода (ISO 8601)'), interval: z .enum(['1min', '5min', '15min', 'hour', 'day', 'week', 'month']) .default('day') .describe('Интервал свечи'), }, READ_ONLY, async ({ ticker, from, to, interval }) => { try { const item = await resolveTickerToInstrument(client, ticker); if (!item) { return { content: [{ type: 'text' as const, text: `Инструмент "${ticker}" не найден.` }] }; } const response = await client.post<GetCandlesResponse>( API_PATHS.MARKET_DATA.GET_CANDLES, { figi: item.figi, from, to, interval: INTERVAL_MAP[interval] }, ); if (!response.candles || response.candles.length === 0) { return { content: [{ type: 'text' as const, text: 'Свечи не найдены для указанного периода.' }] }; } const lines = response.candles.map((c) => { const o = quotationToNumber(c.open).toFixed(2); const h = quotationToNumber(c.high).toFixed(2); const l = quotationToNumber(c.low).toFixed(2); const cl = quotationToNumber(c.close).toFixed(2); return `${formatDateTime(c.time)} | O:${o} H:${h} L:${l} C:${cl} V:${c.volume}`; }); const header = `${ticker} — ${interval} свечи (${response.candles.length} шт.)\n${'─'.repeat(50)}`; return { content: [{ type: 'text' as const, text: `${header}\n${lines.join('\n')}` }] }; } catch (error) { return { content: [{ type: 'text' as const, text: `Ошибка: ${error instanceof Error ? error.message : String(error)}` }], isError: true, }; } }, ); }