obv 그래프 오류

This commit is contained in:
Macbook
2026-06-09 02:25:59 +09:00
parent 8670e58c78
commit 7c1cc2ee4b
4 changed files with 58 additions and 13 deletions
+25 -5
View File
@@ -15,6 +15,10 @@ import { fetchUpbitCandlesCached } from '../utils/requestCache';
/** 초기 렌더 최소 봉 수 — 미만이면 업비트 REST 폴백 */
const MIN_INITIAL_BARS = Math.min(50, Math.floor(DISPLAY_COUNT / 4));
function barsHaveVolume(bars: OHLCVBar[]): boolean {
return bars.some(b => (Number(b.volume) || 0) > 0);
}
/** 백엔드 BarBuilder 는 틱마다 1m 만 STOMP 발행 — 차트 분봉은 클라이언트에서 집계 */
const STOMP_TICK_CANDLE_TYPE = '1m';
@@ -106,29 +110,45 @@ async function fetchInitialBarsWithRetry(
throw lastErr ?? new Error('history fetch failed');
}
/** 백엔드 history → 부족·실패 시 업비트 REST 폴백 (종목별 Ta4j 미적재 대응) */
/** 백엔드 history → 부족·거래량 0·실패 시 업비트 REST 폴백 */
async function loadInitialBars(
market: string,
timeframe: Timeframe,
count: number,
marketChanged: boolean,
preferUpbit = false,
): Promise<OHLCVBar[]> {
const candleType = timeframeToCandleType(timeframe);
const upbitCount = Math.min(count, OBV_DEEP_HISTORY);
if (preferUpbit) {
try {
const upbit = await fetchUpbitCandlesCached(market, timeframe, upbitCount, marketChanged);
if (upbit.length >= MIN_INITIAL_BARS && barsHaveVolume(upbit)) return upbit;
} catch {
/* Upbit 실패 시 backend 시도 */
}
}
let bars: OHLCVBar[] = [];
try {
bars = await fetchInitialBarsWithRetry(market, candleType, count);
} catch {
bars = [];
}
if (bars.length < MIN_INITIAL_BARS) {
const needsUpbitFallback = bars.length < MIN_INITIAL_BARS || !barsHaveVolume(bars);
if (needsUpbitFallback) {
try {
const fallback = await fetchUpbitCandlesCached(
market,
timeframe,
Math.min(count, 200),
upbitCount,
marketChanged,
);
if (fallback.length > bars.length) bars = fallback;
if (fallback.length > bars.length || (barsHaveVolume(fallback) && !barsHaveVolume(bars))) {
bars = fallback;
}
} catch {
/* 폴백 실패 시 backend 결과 유지 */
}
@@ -182,7 +202,7 @@ export function useStompChartData(
const count = opts.deepObvHistory
? OBV_DEEP_HISTORY
: DISPLAY_COUNT + WARMUP_COUNT;
loadInitialBars(market, timeframe, count, marketChanged)
loadInitialBars(market, timeframe, count, marketChanged, opts.deepObvHistory === true)
.then(newBars => {
if (cancelled) return;
barsRef.current = newBars;