Spaces:
Running
Running
Create Stock news screeer
Browse files- Stock news screeer +71 -0
Stock news screeer
ADDED
@@ -0,0 +1,71 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
// Wall Street Watchdog AI - React Frontend
|
2 |
+
// Uses TailwindCSS, TradingView widget, and fetches from backend every 5 min
|
3 |
+
|
4 |
+
import React, { useEffect, useState } from 'react';
|
5 |
+
import { Card, CardContent } from "@/components/ui/card";
|
6 |
+
import { Button } from "@/components/ui/button";
|
7 |
+
import { ReloadIcon } from "lucide-react";
|
8 |
+
import axios from 'axios';
|
9 |
+
|
10 |
+
const API_ENDPOINT = "/api/alerts"; // Your backend API route
|
11 |
+
|
12 |
+
export default function WatchdogApp() {
|
13 |
+
const [alerts, setAlerts] = useState([]);
|
14 |
+
const [loading, setLoading] = useState(false);
|
15 |
+
const [countdown, setCountdown] = useState(300);
|
16 |
+
|
17 |
+
const fetchAlerts = async () => {
|
18 |
+
setLoading(true);
|
19 |
+
try {
|
20 |
+
const res = await axios.get(API_ENDPOINT);
|
21 |
+
setAlerts(res.data.alerts);
|
22 |
+
} catch (err) {
|
23 |
+
console.error("Error fetching alerts:", err);
|
24 |
+
}
|
25 |
+
setLoading(false);
|
26 |
+
};
|
27 |
+
|
28 |
+
useEffect(() => {
|
29 |
+
fetchAlerts();
|
30 |
+
const interval = setInterval(fetchAlerts, 300000); // Every 5 minutes
|
31 |
+
const countdownInterval = setInterval(() => setCountdown((c) => (c > 0 ? c - 1 : 300)), 1000);
|
32 |
+
return () => {
|
33 |
+
clearInterval(interval);
|
34 |
+
clearInterval(countdownInterval);
|
35 |
+
};
|
36 |
+
}, []);
|
37 |
+
|
38 |
+
return (
|
39 |
+
<div className="p-6 bg-black text-white min-h-screen">
|
40 |
+
<h1 className="text-3xl font-bold mb-4">Wall Street Watchdog AI</h1>
|
41 |
+
<div className="flex justify-between items-center mb-2">
|
42 |
+
<p className="text-sm">Auto-refresh in {countdown}s</p>
|
43 |
+
<Button onClick={fetchAlerts} disabled={loading}>
|
44 |
+
{loading ? <ReloadIcon className="animate-spin" /> : "Refresh Now"}
|
45 |
+
</Button>
|
46 |
+
</div>
|
47 |
+
|
48 |
+
<div className="grid md:grid-cols-2 lg:grid-cols-3 gap-4">
|
49 |
+
{alerts.map((alert, idx) => (
|
50 |
+
<Card key={idx} className="bg-gray-900 border border-gray-700 rounded-2xl shadow-xl">
|
51 |
+
<CardContent className="p-4">
|
52 |
+
<p className="text-xl font-semibold">{alert.ticker} — {alert.action}</p>
|
53 |
+
<p className="text-sm text-gray-400">{alert.source}</p>
|
54 |
+
<p className="text-base mt-2">{alert.summary}</p>
|
55 |
+
<div className="mt-4">
|
56 |
+
<iframe
|
57 |
+
src={`https://s.tradingview.com/embed-widget/mini-symbol-overview/?symbol=${alert.ticker}&locale=en`}
|
58 |
+
width="100%"
|
59 |
+
height="100"
|
60 |
+
frameBorder="0"
|
61 |
+
allowTransparency
|
62 |
+
scrolling="no"
|
63 |
+
/>
|
64 |
+
</div>
|
65 |
+
</CardContent>
|
66 |
+
</Card>
|
67 |
+
))}
|
68 |
+
</div>
|
69 |
+
</div>
|
70 |
+
);
|
71 |
+
}
|