전략평가 MA 참조에러 수정

This commit is contained in:
Macbook
2026-06-13 01:25:56 +09:00
parent 24128e6a0a
commit 207374a08e
10 changed files with 451 additions and 77 deletions
@@ -18,7 +18,7 @@ import {
formatStrategyThreshold,
type ConditionMetric,
} from './virtualSignalMetrics';
import { nodeToText } from './strategyEditorShared';
import { nodeToText, buildDefFromGetParams, type DefType, DEF_DEFAULTS } from './strategyEditorShared';
export interface ConditionInterpretContext {
condition: ConditionDSL;
@@ -49,23 +49,24 @@ function walkContext(
side: 'buy' | 'sell',
out: Map<string, ConditionInterpretContext>,
seen: Set<string>,
def: DefType,
): void {
if (!node) return;
if (node.type === 'TIMEFRAME') {
const tf = normalizeStartCandleType(node.candleTypes?.[0] ?? node.candleType ?? timeframe);
node.children?.forEach(c => walkContext(c, tf, side, out, seen));
node.children?.forEach(c => walkContext(c, tf, side, out, seen, def));
return;
}
if (node.type === 'NOT') {
const child = node.children?.[0] ?? (node as LogicNode & { child?: LogicNode }).child;
if (child) walkContext(child, timeframe, side, out, seen);
if (child) walkContext(child, timeframe, side, out, seen, def);
return;
}
if (node.type === 'AND' || node.type === 'OR') {
node.children?.forEach(c => walkContext(c, timeframe, side, out, seen));
node.children?.forEach(c => walkContext(c, timeframe, side, out, seen, def));
return;
}
@@ -77,22 +78,24 @@ function walkContext(
seen.add(rowId);
out.set(rowId, {
condition: c,
summary: nodeToText(node),
summary: nodeToText(node, def),
timeframe: rowTf,
});
return;
}
node.children?.forEach(c => walkContext(c, timeframe, side, out, seen));
node.children?.forEach(c => walkContext(c, timeframe, side, out, seen, def));
}
export function buildConditionContextMap(
strategy: StrategyDto | null | undefined,
getParams?: (type: string, defaults?: Record<string, number | string | boolean>) => Record<string, number | string | boolean>,
): Map<string, ConditionInterpretContext> {
const def = getParams ? buildDefFromGetParams(getParams) : DEF_DEFAULTS;
const out = new Map<string, ConditionInterpretContext>();
const seen = new Set<string>();
walkContext(asLogicNode(strategy?.buyCondition), '1m', 'buy', out, seen);
walkContext(asLogicNode(strategy?.sellCondition), '1m', 'sell', out, seen);
walkContext(asLogicNode(strategy?.buyCondition), '1m', 'buy', out, seen, def);
walkContext(asLogicNode(strategy?.sellCondition), '1m', 'sell', out, seen, def);
return out;
}