전략 시간봉 오류 수정
This commit is contained in:
@@ -1,56 +1,8 @@
|
||||
import { loadStrategyTimeframes, saveLiveStrategySettings } from './backendApi';
|
||||
import { collectDslBranches } from './strategyConditionSerde';
|
||||
import { saveLiveStrategySettings } from './backendApi';
|
||||
import { pinStrategyEvaluationTimeframes } from './strategyTimeframePin';
|
||||
import { normalizeStartCandleType } from './strategyStartNodes';
|
||||
import type { StrategyDto } from './backendApi';
|
||||
import type { LogicNode } from './strategyTypes';
|
||||
import type { VirtualSessionConfig, VirtualTargetItem } from './virtualTradingStorage';
|
||||
import { resolveVirtualTargetStrategyId } from './virtualTargetStrategy';
|
||||
|
||||
function collectUiTimeframes(strategy: StrategyDto | null | undefined): string[] {
|
||||
if (!strategy) return [];
|
||||
const set = new Set<string>();
|
||||
const buy = strategy.buyCondition as LogicNode | null | undefined;
|
||||
const sell = strategy.sellCondition as LogicNode | null | undefined;
|
||||
for (const b of [
|
||||
...collectDslBranches(buy ?? null),
|
||||
...collectDslBranches(sell ?? null),
|
||||
]) {
|
||||
const types = b.candleTypes?.length ? b.candleTypes : [b.candleType];
|
||||
for (const ct of types) set.add(normalizeStartCandleType(ct));
|
||||
}
|
||||
return [...set];
|
||||
}
|
||||
|
||||
/**
|
||||
* UI(편집기)와 서버 DSL의 평가 분봉이 다르면 안내.
|
||||
* @returns false — 계속 진행 불가(재저장 필요)
|
||||
*/
|
||||
export async function warnStrategyTimeframeMismatch(
|
||||
strategy: StrategyDto | null | undefined,
|
||||
strategyId: number,
|
||||
): Promise<boolean> {
|
||||
if (!strategy) return true;
|
||||
const uiTfs = collectUiTimeframes(strategy);
|
||||
if (uiTfs.length === 0 || (uiTfs.length === 1 && uiTfs[0] === '1m')) return true;
|
||||
|
||||
let serverTfs: string[];
|
||||
try {
|
||||
serverTfs = await loadStrategyTimeframes(strategyId);
|
||||
} catch {
|
||||
return true;
|
||||
}
|
||||
const serverSet = new Set(serverTfs.map(tf => normalizeStartCandleType(tf)));
|
||||
const missingOnServer = uiTfs.filter(tf => !serverSet.has(tf));
|
||||
if (missingOnServer.length === 0) return true;
|
||||
|
||||
window.alert(
|
||||
`전략 화면에는 ${uiTfs.join(', ')} 봉으로 보이지만, 서버에는 ${[...serverSet].join(', ') || '1m'} 만 저장되어 있습니다.\n\n`
|
||||
+ '전략편집기에서 「저장」을 눌러 다시 저장한 뒤 가상매매를 시작하세요.',
|
||||
);
|
||||
return false;
|
||||
}
|
||||
|
||||
/** 가상투자 대상 종목을 백엔드 live strategy 설정과 동기화 */
|
||||
export async function syncVirtualTargetsToBackend(
|
||||
targets: VirtualTargetItem[],
|
||||
|
||||
Reference in New Issue
Block a user