add Telegram alerts: qualified setups, S/R proximity, score drops, daily digest
Closes the action loop — instead of polling the dashboard, the platform pushes actionable signals to Telegram. New hourly 'alerts' job dispatches four toggleable triggers, deduped via a new alert_log table (cooldown-based for qualified/S-R/digest, watermark-based for score deterioration). Admin → Settings gains a Telegram panel (write-only bot token, chat ID, per-trigger toggles, Send Test). Credentials follow DB > env precedence (TELEGRAM_BOT_TOKEN / _CHAT_ID). Backend: alert_service + AlertLog model + migration 005, scheduler job, admin endpoints/schema. Frontend: AlertSettings panel, hooks, api, types. Deploy: run alembic upgrade (new alert_log table). Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
@@ -175,6 +175,45 @@ export function useTestSentimentProvider() {
|
||||
});
|
||||
}
|
||||
|
||||
export function useAlertSettings() {
|
||||
return useQuery({
|
||||
queryKey: ['admin', 'alert-settings'],
|
||||
queryFn: () => adminApi.getAlertSettings(),
|
||||
});
|
||||
}
|
||||
|
||||
export function useUpdateAlertSettings() {
|
||||
const qc = useQueryClient();
|
||||
const { addToast } = useToast();
|
||||
|
||||
return useMutation({
|
||||
mutationFn: (payload: Parameters<typeof adminApi.updateAlertSettings>[0]) =>
|
||||
adminApi.updateAlertSettings(payload),
|
||||
onSuccess: () => {
|
||||
qc.invalidateQueries({ queryKey: ['admin', 'alert-settings'] });
|
||||
addToast('success', 'Alert settings updated');
|
||||
},
|
||||
onError: (error: Error) => {
|
||||
addToast('error', error.message || 'Failed to update alert settings');
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
export function useTestAlert() {
|
||||
const { addToast } = useToast();
|
||||
|
||||
return useMutation({
|
||||
mutationFn: () => adminApi.testAlertSettings(),
|
||||
onSuccess: (result) => {
|
||||
if (result.ok) addToast('success', 'Test alert sent — check Telegram.');
|
||||
else addToast('error', result.error || 'Test alert failed');
|
||||
},
|
||||
onError: (error: Error) => {
|
||||
addToast('error', error.message || 'Test alert failed');
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
export function useTickerUniverseSetting() {
|
||||
return useQuery({
|
||||
queryKey: ['admin', 'ticker-universe'],
|
||||
|
||||
Reference in New Issue
Block a user