get_operations
Retrieve historical investment account operations from T-Invest within specified date ranges to track transactions and analyze portfolio activity.
Instructions
Получить историю операций по счёту в Т-Инвестициях
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| accountId | Yes | Идентификатор счёта (можно получить через get_accounts) | |
| from | No | Начало периода (ISO 8601, например 2024-01-01T00:00:00Z) | |
| to | No | Конец периода (ISO 8601) | |
| limit | No | Максимальное количество операций |
Implementation Reference
- src/tools/get-operations.ts:10-63 (handler)The `registerGetOperations` function registers the `get_operations` MCP tool and contains the core logic for fetching and formatting operations from the T-Invest API.
export function registerGetOperations(server: McpServer, client: TInvestClient): void { server.tool( 'get_operations', 'Получить историю операций по счёту в Т-Инвестициях', { accountId: z.string().describe('Идентификатор счёта (можно получить через get_accounts)'), from: z.string().optional().describe('Начало периода (ISO 8601, например 2024-01-01T00:00:00Z)'), to: z.string().optional().describe('Конец периода (ISO 8601)'), limit: z.number().int().min(1).max(1000).default(50).describe('Максимальное количество операций'), }, READ_ONLY, async ({ accountId, from, to, limit }) => { try { const body: Record<string, unknown> = { accountId, limit }; if (from) body.from = from; if (to) body.to = to; const response = await client.post<GetOperationsByCursorResponse>( API_PATHS.OPERATIONS.GET_OPERATIONS_BY_CURSOR, body, ); if (!response.items || response.items.length === 0) { return { content: [{ type: 'text' as const, text: 'Операции не найдены.' }] }; } const lines = response.items.map((op) => { const parts = [ `Дата: ${formatDateTime(op.date)}`, `Тип: ${OPERATION_TYPE_LABELS[op.type] ?? op.type}`, ]; if (op.name) parts.push(`Инструмент: ${op.name}`); if (op.payment) parts.push(`Сумма: ${formatMoney(op.payment)}`); if (op.price && op.quantity) { parts.push(`Цена: ${formatMoney(op.price)}, Количество: ${op.quantityDone ?? op.quantity}`); } if (op.commissionSum) parts.push(`Комиссия: ${formatMoney(op.commissionSum)}`); return parts.join('\n'); }); let text = lines.join(SEPARATOR); if (response.hasnext) { text += '\n\n(Есть ещё операции. Уточните период или уменьшите limit.)'; } return { content: [{ type: 'text' as const, text }] }; } catch (error) { return { content: [{ type: 'text' as const, text: `Ошибка: ${error instanceof Error ? error.message : String(error)}` }], isError: true, }; } }, );