전략평가 매매시그널 표시안되는 문제 수정

This commit is contained in:
Macbook
2026-06-13 00:00:39 +09:00
parent 2c0570c95e
commit 24128e6a0a
7 changed files with 55 additions and 90 deletions
+3 -44
View File
@@ -9,6 +9,7 @@ import { timeframeToCandleType } from '../utils/chartCandleType';
import { getCandleStart, TF_SECONDS } from '../utils/upbitApi';
import { DISPLAY_COUNT, WARMUP_COUNT, OBV_DEEP_HISTORY } from './useUpbitData';
import type { WsStatus } from './useUpbitData';
import { fetchBacktestHistoryCandles } from '../utils/backtestWarmup';
import { API_BASE } from '../utils/backendApi';
/** 백엔드 BarBuilder 는 틱마다 1m 만 STOMP 발행 — 차트 분봉은 클라이언트에서 집계 */
@@ -63,58 +64,16 @@ interface Return {
error: string | null;
}
async function fetchInitialBars(market: string, candleType: string, count: number): Promise<OHLCVBar[]> {
const params = new URLSearchParams({
market,
type: candleType,
count: String(count),
});
const res = await fetch(`${API_BASE}/candles/history?${params}`);
if (!res.ok) throw new Error(`history ${res.status}`);
const data = (await res.json()) as StompCandlePayload[];
return data.map(b => ({
time: b.time,
open: b.open,
high: b.high,
low: b.low,
close: b.close,
volume: b.volume,
}));
}
async function fetchInitialBarsWithRetry(
market: string,
candleType: string,
count: number,
attempts = 3,
): Promise<OHLCVBar[]> {
let lastErr: Error | null = null;
for (let i = 0; i < attempts; i++) {
try {
return await fetchInitialBars(market, candleType, count);
} catch (e) {
lastErr = e as Error;
if (i < attempts - 1) {
await new Promise(r => setTimeout(r, 400 * (i + 1)));
}
}
}
throw lastErr ?? new Error('history fetch failed');
}
/**
* 백엔드 /api/candles/history 에서만 초기 캔들을 로드한다.
* Upbit REST 직접 호출을 하지 않음 — 백엔드가 데이터를 아직 쌓지 못한 경우
* 빈 배열을 반환하고, 호출부에서 STOMP bootstrap 경로로 처리한다.
* 백엔드 /api/candles/history — 200봉 초과 시 페이지네이션 (워밍업·OBV 누적용)
*/
async function loadInitialBars(
market: string,
timeframe: Timeframe,
count: number,
): Promise<OHLCVBar[]> {
const candleType = timeframeToCandleType(timeframe);
try {
return await fetchInitialBarsWithRetry(market, candleType, count);
return await fetchBacktestHistoryCandles(market, timeframe, count);
} catch {
return [];
}