get_order_book
Retrieve real-time order book data for a specific ticker from T-Invest, showing bid and ask prices with customizable depth for market analysis.
Instructions
Получить стакан заявок (биржевой стакан) по тикеру из Т-Инвестиций
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| ticker | Yes | Тикер инструмента | |
| depth | No | Глубина стакана (1–50) |
Implementation Reference
- src/tools/get-order-book.ts:19-60 (handler)The core handler function for the `get_order_book` tool, which fetches the instrument's order book and formats the data for the user.
async ({ ticker, depth }) => { try { const item = await resolveTickerToInstrument(client, ticker); if (!item) { return { content: [{ type: 'text' as const, text: `Инструмент "${ticker}" не найден.` }], isError: true }; } const response = await client.post<GetOrderBookResponse>( API_PATHS.MARKET_DATA.GET_ORDER_BOOK, { figi: item.figi, depth }, ); const fmt = (q: Parameters<typeof quotationToNumber>[0]) => quotationToNumber(q).toFixed(2); const lines: string[] = [ `${ticker} — стакан (глубина ${depth})`, `Последняя цена: ${fmt(response.lastPrice)}`, `Цена закрытия: ${fmt(response.closePrice)}`, ]; if (response.limitUp) lines.push(`Планка вверх: ${fmt(response.limitUp)}`); if (response.limitDown) lines.push(`Планка вниз: ${fmt(response.limitDown)}`); lines.push('\nПродажа (asks):'); const asks = [...(response.asks ?? [])].reverse(); for (const ask of asks) { lines.push(` ${fmt(ask.price).padStart(12)} | ${ask.quantity} лот(ов)`); } lines.push('\nПокупка (bids):'); for (const bid of response.bids ?? []) { lines.push(` ${fmt(bid.price).padStart(12)} | ${bid.quantity} лот(ов)`); } 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-order-book.ts:10-62 (registration)Registration function for the `get_order_book` tool.
export function registerGetOrderBook(server: McpServer, client: TInvestClient): void { server.tool( 'get_order_book', 'Получить стакан заявок (биржевой стакан) по тикеру из Т-Инвестиций', { ticker: z.string().describe('Тикер инструмента'), depth: z.number().int().min(1).max(50).default(10).describe('Глубина стакана (1–50)'), }, READ_ONLY, async ({ ticker, depth }) => { try { const item = await resolveTickerToInstrument(client, ticker); if (!item) { return { content: [{ type: 'text' as const, text: `Инструмент "${ticker}" не найден.` }], isError: true }; } const response = await client.post<GetOrderBookResponse>( API_PATHS.MARKET_DATA.GET_ORDER_BOOK, { figi: item.figi, depth }, ); const fmt = (q: Parameters<typeof quotationToNumber>[0]) => quotationToNumber(q).toFixed(2); const lines: string[] = [ `${ticker} — стакан (глубина ${depth})`, `Последняя цена: ${fmt(response.lastPrice)}`, `Цена закрытия: ${fmt(response.closePrice)}`, ]; if (response.limitUp) lines.push(`Планка вверх: ${fmt(response.limitUp)}`); if (response.limitDown) lines.push(`Планка вниз: ${fmt(response.limitDown)}`); lines.push('\nПродажа (asks):'); const asks = [...(response.asks ?? [])].reverse(); for (const ask of asks) { lines.push(` ${fmt(ask.price).padStart(12)} | ${ask.quantity} лот(ов)`); } lines.push('\nПокупка (bids):'); for (const bid of response.bids ?? []) { lines.push(` ${fmt(bid.price).padStart(12)} | ${bid.quantity} лот(ов)`); } 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, }; } }, ); }