get_last_prices
Retrieve current market prices for specified tickers from T-Invest to monitor portfolio values and track financial instruments.
Instructions
Получить текущие рыночные цены по тикерам в Т-Инвестициях
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| tickers | Yes | Массив тикеров (до 100) |
Implementation Reference
- src/tools/get-last-prices.ts:11-58 (handler)The tool registration and handler implementation for "get_last_prices".
server.tool( 'get_last_prices', 'Получить текущие рыночные цены по тикерам в Т-Инвестициях', { tickers: z.array(z.string()).min(1).max(100).describe('Массив тикеров (до 100)'), }, READ_ONLY, async ({ tickers }) => { try { const instrumentMap = await resolveTickersToInstruments(client, tickers); const found = tickers .map((t) => ({ ticker: t, instrument: instrumentMap.get(t.toUpperCase()) })) .filter((r): r is { ticker: string; instrument: NonNullable<typeof r.instrument> } => r.instrument !== undefined); const notFound = tickers.filter((t) => !instrumentMap.has(t.toUpperCase())); if (found.length === 0) { return { content: [{ type: 'text' as const, text: 'Инструменты не найдены.' }] }; } const response = await client.post<GetLastPricesResponse>( API_PATHS.MARKET_DATA.GET_LAST_PRICES, { figi: found.map((f) => f.instrument.figi) }, ); const priceMap = new Map(response.lastPrices.map((lp) => [lp.figi, lp])); const lines = found.map(({ ticker, instrument }) => { const lp = priceMap.get(instrument.figi); if (!lp) return `${ticker}: цена недоступна`; const price = quotationToNumber(lp.price).toFixed(2); return `${ticker}: ${price} (обновлено ${formatDateTime(lp.time)})`; }); if (notFound.length > 0) { lines.push(`\nНе найдены: ${notFound.join(', ')}`); } return { content: [{ type: 'text' as const, text: lines.join('\n') }] }; } catch (error) { return { content: [{ type: 'text' as const, text: `Ошибка: ${error instanceof Error ? error.message : String(error)}` }], isError: true, }; } }, ); - src/tools/get-last-prices.ts:10-10 (registration)The registration function for the "get_last_prices" tool.
export function registerGetLastPrices(server: McpServer, client: TInvestClient): void {