import type { Timeframe } from '../types'; import { formatTimeframeKo } from './backtestUiUtils'; /** 빠른 백테스팅 — 전략 DSL에 저장된 시간봉 사용 */ export const BACKTEST_STRATEGY_TIMEFRAME = '__strategy__' as const; export type BacktestRunTimeframeChoice = Timeframe | typeof BACKTEST_STRATEGY_TIMEFRAME; export const QUICK_RUN_TIMEFRAME_ITEMS: { value: Timeframe; label: string }[] = [ { value: '1m', label: '1분' }, { value: '3m', label: '3분' }, { value: '5m', label: '5분' }, { value: '10m', label: '10분' }, { value: '15m', label: '15분' }, { value: '30m', label: '30분' }, { value: '1h', label: '1시간' }, { value: '4h', label: '4시간' }, { value: '1D', label: '일봉' }, { value: '1W', label: '주봉' }, ]; export function isBacktestStrategyTimeframeChoice( value: string, ): value is typeof BACKTEST_STRATEGY_TIMEFRAME { return value === BACKTEST_STRATEGY_TIMEFRAME; } export function parseBacktestRunTimeframeChoice(value: string): BacktestRunTimeframeChoice { if (isBacktestStrategyTimeframeChoice(value)) return BACKTEST_STRATEGY_TIMEFRAME; return value as Timeframe; } /** UI 선택 → 실제 실행 시간봉 */ export function resolveBacktestExecTimeframe( choice: BacktestRunTimeframeChoice, strategyTimeframe: Timeframe, ): Timeframe { if (choice === BACKTEST_STRATEGY_TIMEFRAME) return strategyTimeframe; return choice; } export function buildQuickRunTimeframeSelectOptions(strategyTimeframe?: Timeframe) { const stratLabel = strategyTimeframe ? `전략 시간봉 (${formatTimeframeKo(strategyTimeframe)})` : '전략 시간봉'; return [ { value: BACKTEST_STRATEGY_TIMEFRAME, label: stratLabel }, ...QUICK_RUN_TIMEFRAME_ITEMS, ]; }