init: Market Assistant — этап 1 (позиции: FIFO-средняя, цена безубытка, ступеньки, маркеры ордеров) + этап 2 (отношения инструментов: лаг-корреляция)

This commit is contained in:
workD12 committed 2026-09-29 19:38:40 +03:00
commit 0af45d2902
46 files changed
+8105

No files matched your search

+49
View File
@@ -0,0 +1,49 @@
/**
* Диагностика sandbox-счёта: активные ордера, портфель, все операции.
*
* Запуск (из backend/): npm run sandbox-diag
* Только для TINKOFF_SANDBOX=true!
*/
import { config, hasTinkoffToken } from '../src/config.js';
import {
getAccounts,
getSandboxOperationsRaw,
getSandboxOrders,
getSandboxPortfolio,
} from '../src/tinkoff.js';
function short(value: unknown): string {
return JSON.stringify(value, null, 0).slice(0, 500);
}
async function main(): Promise<void> {
if (!hasTinkoffToken()) throw new Error('TINKOFF_TOKEN не задан в .env');
if (!config.tinkoffSandbox) throw new Error('Скрипт только для песочницы');
const account = (await getAccounts())[0];
if (!account) throw new Error('Нет sandbox-счётов');
console.log(`Счёт: ${account.id} (${account.name || account.type})`);
const orders = await getSandboxOrders(account.id);
console.log(`\nАктивные ордера: ${orders.length}`);
for (const o of orders) console.log(' ', short(o));
const portfolio = (await getSandboxPortfolio(account.id)) as {
positions?: unknown[];
totalAmountCurrencies?: unknown;
};
console.log(`\nПозиции портфеля: ${portfolio.positions?.length ?? 0}`);
for (const p of portfolio.positions ?? []) console.log(' ', short(p));
console.log('Деньги (totalAmountCurrencies):', short(portfolio.totalAmountCurrencies));
const toMs = Date.now();
const fromMs = account.openedMs ?? toMs - 30 * 86_400_000;
const ops = await getSandboxOperationsRaw(account.id, fromMs, toMs);
console.log(`\nВсе операции (без фильтра по статусу): ${ops.length}`);
for (const o of ops.slice(0, 30)) console.log(' ', short(o));
}
main().catch((err) => {
console.error(err instanceof Error ? err.message : err);
process.exit(1);
});