feat(chart): expose bucketSeconds meta
This commit is contained in:
@@ -14,6 +14,7 @@ type Params = {
|
|||||||
type Result = {
|
type Result = {
|
||||||
candles: Candle[];
|
candles: Candle[];
|
||||||
indicators: ChartIndicators;
|
indicators: ChartIndicators;
|
||||||
|
meta: { tf: string; bucketSeconds: number } | null;
|
||||||
loading: boolean;
|
loading: boolean;
|
||||||
error: string | null;
|
error: string | null;
|
||||||
refresh: () => Promise<void>;
|
refresh: () => Promise<void>;
|
||||||
@@ -22,6 +23,7 @@ type Result = {
|
|||||||
export function useChartData({ symbol, source, tf, limit, pollMs }: Params): Result {
|
export function useChartData({ symbol, source, tf, limit, pollMs }: Params): Result {
|
||||||
const [candles, setCandles] = useState<Candle[]>([]);
|
const [candles, setCandles] = useState<Candle[]>([]);
|
||||||
const [indicators, setIndicators] = useState<ChartIndicators>({});
|
const [indicators, setIndicators] = useState<ChartIndicators>({});
|
||||||
|
const [meta, setMeta] = useState<{ tf: string; bucketSeconds: number } | null>(null);
|
||||||
const [loading, setLoading] = useState(false);
|
const [loading, setLoading] = useState(false);
|
||||||
const [error, setError] = useState<string | null>(null);
|
const [error, setError] = useState<string | null>(null);
|
||||||
const inFlight = useRef(false);
|
const inFlight = useRef(false);
|
||||||
@@ -34,6 +36,7 @@ export function useChartData({ symbol, source, tf, limit, pollMs }: Params): Res
|
|||||||
const res = await fetchChart({ symbol, source, tf, limit });
|
const res = await fetchChart({ symbol, source, tf, limit });
|
||||||
setCandles(res.candles);
|
setCandles(res.candles);
|
||||||
setIndicators(res.indicators);
|
setIndicators(res.indicators);
|
||||||
|
setMeta(res.meta);
|
||||||
setError(null);
|
setError(null);
|
||||||
} catch (e: any) {
|
} catch (e: any) {
|
||||||
setError(String(e?.message || e));
|
setError(String(e?.message || e));
|
||||||
@@ -50,8 +53,7 @@ export function useChartData({ symbol, source, tf, limit, pollMs }: Params): Res
|
|||||||
useInterval(() => void fetchOnce(), pollMs);
|
useInterval(() => void fetchOnce(), pollMs);
|
||||||
|
|
||||||
return useMemo(
|
return useMemo(
|
||||||
() => ({ candles, indicators, loading, error, refresh: fetchOnce }),
|
() => ({ candles, indicators, meta, loading, error, refresh: fetchOnce }),
|
||||||
[candles, indicators, loading, error, fetchOnce]
|
[candles, indicators, meta, loading, error, fetchOnce]
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user