Skip to main content
Glama
nonnname

T-Invest MCP Server

by nonnname

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
NameRequiredDescriptionDefault
accountIdYesИдентификатор счёта

Implementation Reference

  • 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,
          };
        }
      },
    );
  • 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,
            };
          }
        },
      );
    }

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/nonnname/t-invest-mcp-server'

If you have feedback or need assistance with the MCP directory API, please join our Discord server