import { useState, useEffect, useCallback } from 'react';
export interface VolumeAnomaly {
marketId: string;
question: string | null;
category: string | null;
score: number; // e.g. 5.0 = 500% of avg
volume24h: number;
avgVolume: number;
liquidity: number;
detectedAt: string | null;
}
interface AnomaliesMeta {
minScore: number;
hours: number;
count: number;
}
export function useAnomalies(minScore = 3.0, hours = 24, limit = 20) {
const [anomalies, setAnomalies] = useState<VolumeAnomaly[]>([]);
const [meta, setMeta] = useState<AnomaliesMeta | null>(null);
const [loading, setLoading] = useState(true);
const fetch_ = useCallback(async () => {
setLoading(true);
try {
const res = await fetch(
`/api/signals/anomalies?min_score=${minScore}&hours=${hours}&limit=${limit}`
);
const d = await res.json();
if (d.success) {
setAnomalies(d.data ?? []);
setMeta(d.meta ?? null);
}
} catch { /* ignore */ }
finally { setLoading(false); }
}, [minScore, hours, limit]);
useEffect(() => {
const t = setTimeout(fetch_, 0);
const interval = setInterval(fetch_, 2 * 60_000);
return () => { clearTimeout(t); clearInterval(interval); };
}, [fetch_]);
return { anomalies, meta, loading, refresh: fetch_ };
}
📜 Git History
6c47fa4chore: local Polikopi project home + Phase 1 redesign artifacts12 days ago
Show last diff
Loading...