Skip to main content
Glama
nonnname

T-Invest MCP Server

by nonnname

get_positions

Retrieve account positions including cash, securities, and futures from T-Invest to monitor portfolio holdings and investment status.

Instructions

Получить позиции счёта (деньги, ценные бумаги, фьючерсы) из Т-Инвестиций

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
accountIdYesИдентификатор счёта (можно получить через get_accounts)

Implementation Reference

  • The handler and registration function for the 'get_positions' tool. It fetches data from the T-Invest API and formats the response for MCP.
    export function registerGetPositions(server: McpServer, client: TInvestClient): void {
      server.tool(
        'get_positions',
        'Получить позиции счёта (деньги, ценные бумаги, фьючерсы) из Т-Инвестиций',
        {
          accountId: z.string().describe('Идентификатор счёта (можно получить через get_accounts)'),
        },
        READ_ONLY,
        async ({ accountId }) => {
          try {
            const response = await client.post<GetPositionsResponse>(
              API_PATHS.OPERATIONS.GET_POSITIONS,
              { accountId },
            );
    
            const lines: string[] = [];
    
            if (response.money && response.money.length > 0) {
              lines.push('Денежные позиции:');
              for (const m of response.money) lines.push(`  ${formatMoney(m)}`);
            }
    
            if (response.blocked && response.blocked.length > 0) {
              lines.push('\nЗаблокировано:');
              for (const m of response.blocked) lines.push(`  ${formatMoney(m)}`);
            }
    
            const allSecurities = [
              ...(response.securities ?? []).map((s) => ({ ...s, kind: 'Бумага' })),
              ...(response.futures ?? []).map((s) => ({ ...s, kind: 'Фьючерс' })),
              ...(response.options ?? []).map((s) => ({ ...s, kind: 'Опцион' })),
            ];
    
            if (allSecurities.length > 0) {
              const settled = await inBatches(
                allSecurities,
                (s) => resolveInstrumentByFigi(client, s.figi),
              );
    
              lines.push('\nЦенные бумаги:');
              for (let i = 0; i < allSecurities.length; i++) {
                const s = allSecurities[i];
                const result = settled[i];
                const ticker = (result.status === 'fulfilled' && result.value) ? result.value : s.figi;
                const blocked = parseInt(s.blocked) > 0 ? `, заблокировано: ${s.blocked}` : '';
                lines.push(`  ${ticker} (${s.kind}): ${s.balance} лот(ов)${blocked}`);
              }
            }
    
            if (response.limitsLoadingInProgress) {
              lines.push('\n⚠ Лимиты ещё загружаются...');
            }
    
            return {
              content: [{ type: 'text' as const, text: lines.length > 0 ? lines.join('\n') : 'Позиций нет.' }],
            };
          } 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