get_stop_orders
Retrieve active stop orders for a T-Invest account to monitor pending trades and manage risk exposure.
Instructions
Получить активные стоп-заявки по счёту из Т-Инвестиций
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| accountId | Yes | Идентификатор счёта |
Implementation Reference
- src/tools/get-stop-orders.ts:13-60 (handler)The handler for 'get_stop_orders' tool, which fetches active stop orders from the T-Invest API and formats them for the user.
server.tool( 'get_stop_orders', 'Получить активные стоп-заявки по счёту из Т-Инвестиций', { accountId: z.string().describe('Идентификатор счёта'), }, READ_ONLY, async ({ accountId }) => { try { const response = await client.post<GetStopOrdersResponse>( API_PATHS.STOP_ORDERS.GET_STOP_ORDERS, { accountId }, ); if (!response.stopOrders || response.stopOrders.length === 0) { return { content: [{ type: 'text' as const, text: 'Активных стоп-заявок нет.' }] }; } const settled = await inBatches( response.stopOrders, (order) => resolveInstrumentByFigi(client, order.figi), ); const lines = response.stopOrders.map((order, i) => { const result = settled[i]; const ticker = (result.status === 'fulfilled' && result.value) ? result.value : order.figi; const parts = [ `Тикер: ${ticker}`, `ID: ${order.stopOrderId}`, `Тип: ${STOP_ORDER_TYPE_LABELS[order.orderType] ?? order.orderType}`, `Направление: ${DIRECTION_LABELS[order.direction] ?? order.direction}`, `Лотов: ${order.lotsRequested}`, ]; if (order.stopPrice) parts.push(`Стоп-цена: ${formatMoney(order.stopPrice)}`); if (order.price) parts.push(`Лимит-цена: ${formatMoney(order.price)}`); if (order.expirationTime) parts.push(`Истекает: ${formatDateTime(order.expirationTime)}`); return parts.join('\n'); }); return { content: [{ type: 'text' as const, text: lines.join(SEPARATOR) }] }; } catch (error) { return { content: [{ type: 'text' as const, text: `Ошибка: ${error instanceof Error ? error.message : String(error)}` }], isError: true, }; } }, ); - src/tools/get-stop-orders.ts:12-61 (registration)Function that registers the 'get_stop_orders' tool with the MCP server.
export function registerGetStopOrders(server: McpServer, client: TInvestClient): void { server.tool( 'get_stop_orders', 'Получить активные стоп-заявки по счёту из Т-Инвестиций', { accountId: z.string().describe('Идентификатор счёта'), }, READ_ONLY, async ({ accountId }) => { try { const response = await client.post<GetStopOrdersResponse>( API_PATHS.STOP_ORDERS.GET_STOP_ORDERS, { accountId }, ); if (!response.stopOrders || response.stopOrders.length === 0) { return { content: [{ type: 'text' as const, text: 'Активных стоп-заявок нет.' }] }; } const settled = await inBatches( response.stopOrders, (order) => resolveInstrumentByFigi(client, order.figi), ); const lines = response.stopOrders.map((order, i) => { const result = settled[i]; const ticker = (result.status === 'fulfilled' && result.value) ? result.value : order.figi; const parts = [ `Тикер: ${ticker}`, `ID: ${order.stopOrderId}`, `Тип: ${STOP_ORDER_TYPE_LABELS[order.orderType] ?? order.orderType}`, `Направление: ${DIRECTION_LABELS[order.direction] ?? order.direction}`, `Лотов: ${order.lotsRequested}`, ]; if (order.stopPrice) parts.push(`Стоп-цена: ${formatMoney(order.stopPrice)}`); if (order.price) parts.push(`Лимит-цена: ${formatMoney(order.price)}`); if (order.expirationTime) parts.push(`Истекает: ${formatDateTime(order.expirationTime)}`); return parts.join('\n'); }); return { content: [{ type: 'text' as const, text: lines.join(SEPARATOR) }] }; } catch (error) { return { content: [{ type: 'text' as const, text: `Ошибка: ${error instanceof Error ? error.message : String(error)}` }], isError: true, }; } }, ); }