Files
auto-trade/features/trade/hooks/useDomesticSession.ts

30 lines
1.0 KiB
TypeScript
Raw Normal View History

2026-02-13 12:17:35 +09:00
import { useState, useEffect } from "react";
import {
resolveDomesticKisSession,
type DomesticKisSession,
} from "@/lib/kis/domestic-market-session";
// 클라이언트 환경에서 현재 시간을 기준으로 세션을 계산합니다.
// 매 30초마다 갱신됩니다.
/**
* @description ( ) .
* client-side에서 ,
* 30 // .
*/
export function useDomesticSession() {
const [marketSession, setMarketSession] = useState<DomesticKisSession>(() =>
resolveDomesticKisSession(),
);
useEffect(() => {
const timerId = window.setInterval(() => {
const nextSession = resolveDomesticKisSession();
setMarketSession((prev) => (prev === nextSession ? prev : nextSession));
}, 30_000);
return () => window.clearInterval(timerId);
}, []);
return marketSession;
}