매매 시그널 알림 화면 수정

This commit is contained in:
Macbook
2026-05-29 00:46:20 +09:00
parent cbad62a5b0
commit e43b5cbd5a
45 changed files with 2186 additions and 415 deletions
@@ -0,0 +1,63 @@
/**
* 매매 시그널 알림 목록 행 — 종목×전략 실시간 신호 스냅샷 (가상매매 카드 요약형과 동일 소스)
*/
import { useCallback, useEffect, useRef, useState } from 'react';
import type { StrategyDto } from '../utils/backendApi';
import {
fetchLiveSnapshot,
type VirtualIndicatorSnapshot,
} from './useVirtualIndicatorSnapshots';
export function useTradeNotificationSignalSnapshot(
market: string,
strategyId: number | null | undefined,
strategy: StrategyDto | undefined,
enabled: boolean,
pollMs = 3000,
): { snapshot: VirtualIndicatorSnapshot | undefined; loading: boolean } {
const [snapshot, setSnapshot] = useState<VirtualIndicatorSnapshot | undefined>();
const [loading, setLoading] = useState(false);
const emptyRetryRef = useRef(0);
const genRef = useRef(0);
const refresh = useCallback(async () => {
if (!enabled || strategyId == null) {
setSnapshot(undefined);
setLoading(false);
return;
}
const gen = ++genRef.current;
setLoading(true);
const pinFirst = emptyRetryRef.current === 0;
const snap = await fetchLiveSnapshot(market, strategyId, strategy, pinFirst);
if (gen !== genRef.current) return;
if (snap && snap.rows.length > 0) {
emptyRetryRef.current = 0;
} else {
emptyRetryRef.current += 1;
}
setSnapshot(snap ?? undefined);
setLoading(false);
}, [market, strategyId, strategy, enabled]);
useEffect(() => {
if (!enabled || strategyId == null) {
setSnapshot(undefined);
setLoading(false);
emptyRetryRef.current = 0;
return;
}
emptyRetryRef.current = 0;
void refresh();
const id = window.setInterval(() => void refresh(), pollMs);
return () => {
clearInterval(id);
genRef.current += 1;
};
}, [market, strategyId, enabled, pollMs, refresh]);
return { snapshot, loading };
}