491 lines
21 KiB
HTML
491 lines
21 KiB
HTML
<!DOCTYPE html>
|
|
<html lang="en">
|
|
<head>
|
|
<meta charset="UTF-8">
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
<link rel="manifest" href="{{ url_for('static', filename='site.webmanifest') }}?v=1">
|
|
<link rel="apple-touch-icon" href="{{ url_for('static', filename='apple-touch-icon.png') }}?v=1">
|
|
<link rel="icon" type="image/png" sizes="32x32" href="{{ url_for('static', filename='favicon-32x32.png') }}?v=1">
|
|
<link rel="icon" type="image/png" sizes="16x16" href="{{ url_for('static', filename='favicon-16x16.png') }}?v=1">
|
|
<link rel="shortcut icon" href="{{ url_for('static', filename='favicon.ico') }}?v=1">
|
|
<title>Financial Dashboard</title>
|
|
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css" rel="stylesheet">
|
|
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.11.0/font/bootstrap-icons.css">
|
|
<style>
|
|
:root {
|
|
--header-bg: #4a5568;
|
|
--text-up: #28a745;
|
|
--text-down: #dc3545;
|
|
--sticky-bg: #ffffff;
|
|
--sticky-bg-alt: #f9f9f9; /* For zebra stripes */
|
|
}
|
|
|
|
body {
|
|
background-color: #f4f7f6;
|
|
font-family: -apple-system, system-ui, BlinkMacSystemFont, "Segoe UI", Roboto;
|
|
margin: 0;
|
|
padding: 10px;
|
|
}
|
|
|
|
/* Card Styling */
|
|
.card {
|
|
/*max-width: 1100px; /* Limits how wide the table grows on a desktop */
|
|
/*margin: 0 auto; /* Centers the table on the screen */
|
|
border: none;
|
|
border-radius: 12px;
|
|
box-shadow: 0 4px 15px rgba(0,0,0,0.1);
|
|
overflow: hidden;
|
|
}
|
|
|
|
.card-header {
|
|
background-color: white !important;
|
|
border-bottom: 1px solid #eee;
|
|
padding: 15px;
|
|
}
|
|
|
|
/* 1. Fixed Table Layout Strategy */
|
|
.table-responsive {
|
|
border-radius: 8px;
|
|
overflow-x: auto;
|
|
}
|
|
|
|
.table {
|
|
/*table-layout: fixed;
|
|
/* table-layout: auto; */ /* Default - let it be auto for data safety */
|
|
width: 100%;
|
|
|
|
/* This MUST match the sum of your column min-widths */
|
|
min-width: 600px;
|
|
|
|
/* Critical for the 'Sticky' column borders to look right */
|
|
border-collapse: separate;
|
|
border-spacing: 0;
|
|
}
|
|
|
|
/* 2. Header & Cell Styling */
|
|
.table thead th {
|
|
background-color: var(--header-bg) !important;
|
|
color: white !important;
|
|
font-size: 0.7rem;
|
|
text-transform: uppercase;
|
|
letter-spacing: 0.5px;
|
|
text-align: center;
|
|
padding: 12px 8px;
|
|
border: none;
|
|
white-space: nowrap;
|
|
}
|
|
|
|
.table td {
|
|
text-align: center;
|
|
vertical-align: middle;
|
|
font-size: 0.85rem;
|
|
white-space: nowrap;
|
|
border-bottom: 1px solid #f1f1f1;
|
|
padding: 10px 8px;
|
|
}
|
|
/* Price Trend Colors */
|
|
.text-up { color: #28a745 !important; } /* Success Green */
|
|
.text-down { color: #dc3545 !important; } /* Danger Red */
|
|
|
|
/* Table Cell Styling */
|
|
#tableBody td {
|
|
padding: 8px 4px;
|
|
font-size: 0.85rem;
|
|
white-space: nowrap;
|
|
transition: all 0.2s ease;
|
|
}
|
|
|
|
/* Custom heatmaps for Z-score */
|
|
.bg-oversold { background-color: #d1e7dd !important; color: #0f5132 !important; }
|
|
.bg-overbought { background-color: #f8d7da !important; color: #842029 !important; }
|
|
|
|
/* 3. Sticky Column Logic (Instrument) */
|
|
.table td:first-child,
|
|
.table th:first-child {
|
|
position: sticky;
|
|
text-align: left !important; /* Force left alignment */
|
|
padding-left: 15px;
|
|
color: #2d3748/* Add space so text doesn't touch the edge */
|
|
left: 0;
|
|
z-index: 10;
|
|
background-color: var(--sticky-bg);
|
|
font-weight: 700;
|
|
|
|
/* THE SHADOW EFFECT */
|
|
/* This adds a 4px blur shadow to the right side of the column */
|
|
box-shadow: 4px 0 8px -2px rgba(0, 0, 0, 0.15);
|
|
|
|
/* Clean border to define the edge */
|
|
border-right: 1px solid #ddd;
|
|
}
|
|
/* Specific fix for Close and Chg% columns readability */
|
|
.table td:nth-child(3),
|
|
.table td:nth-child(4) {
|
|
font-weight: 600;
|
|
color: #1a202c !important; /* Extra bold and dark */
|
|
}
|
|
|
|
/* Navbar fix: Ensure buttons don't disappear on tiny screens */
|
|
.navbar-nav {
|
|
flex-direction: row !important; /* Keep links side-by-side on mobile */
|
|
gap: 10px;
|
|
}
|
|
|
|
.nav-link {
|
|
padding: 0.5rem !important;
|
|
font-size: 0.85rem;
|
|
}
|
|
|
|
/* 4. Zebra Striping + Sticky Fix */
|
|
.table-striped tbody tr:nth-of-type(odd) {
|
|
background-color: rgba(0, 0, 0, 0.03);
|
|
}
|
|
|
|
.table-striped tbody tr:nth-of-type(odd) td:first-child {
|
|
background-color: var(--sticky-bg-alt); /* Matches stripe color */
|
|
}
|
|
|
|
/* Custom Colors & UI */
|
|
.text-up { color: var(--text-up); font-weight: 600; }
|
|
.text-down { color: var(--text-down); font-weight: 600; }
|
|
|
|
.table-date {
|
|
font-size: 0.8rem !important; /* Increased slightly to make it obvious */
|
|
font-weight: 800 !important; /* Extra bold */
|
|
font-family: 'Courier New', monospace !important;
|
|
display: inline-block; /* Sometimes helps with sizing */
|
|
white-space: nowrap; /* Prevents the date from snapping to 2 lines */
|
|
}
|
|
.status-dot {
|
|
width: 8px;
|
|
height: 8px;
|
|
background-color: #39FF14; /* Neon green for better visibility */
|
|
border-radius: 50%;
|
|
display: inline-block;
|
|
box-shadow: 0 0 10px rgba(57, 255, 20, 0.4);
|
|
animation: status-pulse 2s infinite;
|
|
}
|
|
|
|
/* Custom text class if Bootstrap classes aren't bright enough */
|
|
.text-white-50 {
|
|
color: rgba(255, 255, 255, 0.7) !important; /* Increased from 0.5 to 0.7 for clarity */
|
|
}
|
|
|
|
@keyframes status-pulse {
|
|
0% { transform: scale(0.95); opacity: 1; }
|
|
50% { transform: scale(1.1); opacity: 0.7; }
|
|
100% { transform: scale(0.95); opacity: 1; }
|
|
}
|
|
|
|
#lastSyncTime {
|
|
font-size: 0.85rem;
|
|
letter-spacing: 0.5px;
|
|
}
|
|
/* High Contrast Signal Colors - Works in Light & Dark Mode */
|
|
.signal-up {
|
|
color: #00ff88 !important; /* Vibrant Mint (Visible on any dark bg) */
|
|
font-weight: bold !important;
|
|
}
|
|
.signal-down {
|
|
color: #ff4d4d !important; /* Vibrant Coral/Red */
|
|
font-weight: bold !important;
|
|
}
|
|
.signal-neutral {
|
|
color: #e2e8f0 !important;
|
|
}
|
|
|
|
@media (prefers-color-scheme: dark) {
|
|
body { background-color: #121212 !important; color: #e2e8f0; }
|
|
.card { background-color: #1a202c !important; border: 1px solid #2d3748; }
|
|
|
|
/* Ensure table text doesn't turn grey on mobile */
|
|
.table { color: #e2e8f0 !important; }
|
|
}
|
|
|
|
|
|
</style>
|
|
</head>
|
|
<body>
|
|
<nav class="navbar navbar-dark mb-4" style="background-color: #1a202c !important;">
|
|
<div class="container-fluid d-flex justify-content-between align-items-center">
|
|
<div class="d-flex align-items-center">
|
|
<a class="navbar-brand me-4" href="/">
|
|
<i class="bi bi-graph-up-arrow me-2"></i>Finance Suite
|
|
</a>
|
|
<div class="d-flex gap-2">
|
|
<a class="btn btn-sm btn-outline-light border-secondary" href="/">Dashboard</a>
|
|
<a class="btn btn-sm btn-outline-light border-secondary" href="/backtest">Backtest</a>
|
|
</div>
|
|
</div>
|
|
|
|
<div class="d-flex align-items-center" style="font-size: 0.8rem; letter-spacing: 0.3px;">
|
|
<div class="status-dot me-2"></div>
|
|
<span class="text-white-50">System Online</span>
|
|
<span class="mx-2 text-white-50 opacity-25">|</span>
|
|
<span class="text-white-50">Last Sync:</span>
|
|
<span id="lastSyncTime" class="ms-1 fw-bold text-white font-monospace">--:--:--</span>
|
|
</div>
|
|
</div>
|
|
</nav>
|
|
<div class="container-fluid p-0">
|
|
<div class="card">
|
|
<div class="card-header d-flex justify-content-between align-items-center">
|
|
<h5 class="mb-0 p-2 shadow-sm" style="background: linear-gradient(90deg, #007bff, #6610f2); -webkit-background-clip: text; -webkit-text-fill-color: transparent; font-weight: bold;">
|
|
Portfolio Signals
|
|
</h5>
|
|
<div class="d-flex align-items-center gap-2">
|
|
<span id="loading">Updating...</span>
|
|
<button class="btn btn-outline-secondary btn-sm" onclick="loadData()">
|
|
<i class="bi bi-arrow-clockwise"></i> Refresh
|
|
</button>
|
|
<button id="syncBtn" class="btn btn-primary btn-sm" onclick="runGlobalSync()">
|
|
<i class="bi bi-cloud-download"></i> Sync Data
|
|
</button>
|
|
</div>
|
|
</div>
|
|
<div class="card-body p-0">
|
|
<div class="table-responsive">
|
|
<table class="table table-hover table-striped mb-0">
|
|
<thead>
|
|
<tr>
|
|
<th style="min-width: 50px;">Instrument</th>
|
|
<th style="min-width: 25px;">Date</th>
|
|
<th style="min-width: 25px;">Close</th>
|
|
<th style="min-width: 25px;">Chg%</th>
|
|
<th style="min-width: 25px;">L--52W--H</th>
|
|
<th class="min-width: 50px;">RSI</th>
|
|
<th class="min-width: 25px;">BB %B</th>
|
|
<th class="min-width: 25px;">Z60</th>
|
|
<th class="min-width: 25px;">Z120</th>
|
|
<th style="min-width: 25px;">25 EMA%</th>
|
|
<th style="min-width: 25px;">50 EMA%</th>
|
|
<th style="min-width: 25px;">100 EMA%</th>
|
|
<th style="min-width: 25px;">200 EMA</th>
|
|
<th style="min-width: 60px;">K/D</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody id="tableBody">
|
|
<tr><td colspan="10" class="p-4">Initializing data engine...</td></tr>
|
|
</tbody>
|
|
</table>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
<script>
|
|
console.log("Script block loaded successfully.");
|
|
|
|
// --- 1. Helper Function for K/D Styling ---
|
|
function formatKD(val) {
|
|
if (!val || val === "N/A" || !val.includes('/')) return `<span class="text-muted">N/A</span>`;
|
|
const [k, d] = val.split('/').map(v => parseFloat(v));
|
|
let colorClass = 'text-dark';
|
|
if (k >= 80) colorClass = 'text-danger fw-bold';
|
|
else if (k <= 20) colorClass = 'text-success fw-bold';
|
|
return `<span class="${colorClass}">${val}</span>`;
|
|
}
|
|
|
|
// --- 2. EMA Formatter ---
|
|
const formatEma = (val) => {
|
|
if (val === "N/A" || val === null || val === undefined) return `<span class="text-muted">N/A</span>`;
|
|
const num = parseFloat(val);
|
|
const sign = num > 0 ? "+" : "";
|
|
const colorClass = num >= 0 ? 'text-up' : 'text-down';
|
|
return `<span class="${colorClass}">${sign}${num.toFixed(1)}%</span>`;
|
|
};
|
|
// Function for Z-Score (Heatmap style)
|
|
const getZColor = (val) => {
|
|
if (val === "N/A") return "";
|
|
if (val >= 2) return 'style="background-color: #ffcccc; color: #cc0000; font-weight: bold;"'; // Overbought
|
|
if (val <= -2) return 'style="background-color: #ccffcc; color: #006600; font-weight: bold;"'; // Oversold
|
|
return "";
|
|
};
|
|
// Function for RSI (Text-only Traffic Ligh style)
|
|
const getRSIColor = (val) => {
|
|
if (val === "N/A") return "";
|
|
if (val >= 70) return 'class="text-danger fw-bold"'; // Red Text
|
|
if (val <= 30) return 'class="text-success fw-bold"'; // Green Text
|
|
return "";
|
|
};
|
|
// Function for BB (Text-only Traffic Ligh style)
|
|
const getBBColor = (val) => {
|
|
if (val === "N/A" || val === null) return "";
|
|
const numericVal = parseFloat(val);
|
|
// Traffic Light Logic
|
|
if (numericVal >= 1.0) return 'class="text-danger fw-bold"'; // Above Upper Band
|
|
if (numericVal <= 0.0) return 'class="text-success fw-bold"'; // Below Lower Band
|
|
return 'class="text-muted"'; // Neutral
|
|
};
|
|
|
|
async function loadData() {
|
|
console.log("Starting loadData...");
|
|
const loading = document.getElementById('loading');
|
|
const tbody = document.getElementById('tableBody');
|
|
const syncDisplay = document.getElementById('lastSyncTime');
|
|
|
|
if (loading) loading.style.display = 'inline';
|
|
|
|
try { // <--- THIS WAS MISSING
|
|
const response = await fetch('/api/summary');
|
|
const result = await response.json();
|
|
|
|
// --- 1. DATE & TIMEZONE FIX ---
|
|
if (syncDisplay && result.last_sync) {
|
|
const dateStr = result.last_sync.trim().replace(' ', 'T');
|
|
const dateObj = new Date(dateStr + (dateStr.includes('Z') ? '' : 'Z'));
|
|
|
|
syncDisplay.innerText = dateObj.toLocaleString([], {
|
|
month: 'short', day: '2-digit',
|
|
hour: '2-digit', minute: '2-digit', second: '2-digit',
|
|
hour12: false
|
|
});
|
|
|
|
syncDisplay.classList.add('text-success');
|
|
setTimeout(() => syncDisplay.classList.remove('text-success'), 2000);
|
|
}
|
|
|
|
// --- 2. Extract data from result ---
|
|
const data = result.data;
|
|
let htmlContent = '';
|
|
const todayStr = new Date().toISOString().split('T')[0];
|
|
|
|
if (data && data.length > 0) {
|
|
data.forEach(item => {
|
|
// --- A. Error Handling ---
|
|
if (item.error || !item.last_close || item.last_close === 'N/A') {
|
|
htmlContent += `
|
|
<tr>
|
|
<td><div class="fw-bold text-muted">${item.name || item.symbol}</div></td>
|
|
<td colspan="13" class="text-center p-3">
|
|
<span class="badge bg-warning text-dark">Needs Sync</span>
|
|
<small class="text-muted ms-2">Data not found or corrupted.</small>
|
|
</td>
|
|
</tr>`;
|
|
return;
|
|
}
|
|
|
|
// --- B. Preparation & Math ---
|
|
let displayDate = item.last_date || "N/A";
|
|
let dateColor = '#dc3545';
|
|
if (item.last_date && item.last_date.includes('-')) {
|
|
const parts = item.last_date.split('-');
|
|
displayDate = `${parts[2]}/${parts[1]}`;
|
|
dateColor = (item.last_date === todayStr) ? '#28a745' : '#dc3545';
|
|
}
|
|
|
|
const current = parseFloat(item.last_close) || 0;
|
|
const low = parseFloat(item.low_52) || 0;
|
|
const high = parseFloat(item.high_52) || 0;
|
|
|
|
let rangePct = high > low ? Math.min(Math.max(((current - low) / (high - low)) * 100, 0), 100) : 0;
|
|
const rangeColor = rangePct > 80 ? 'text-danger' : (rangePct < 20 ? 'text-success' : 'text-muted');
|
|
|
|
const rsiVal = item.rsi !== null ? item.rsi : "N/A";
|
|
const bbRaw = parseFloat(item.bb_pct);
|
|
const bbDisplay = !isNaN(bbRaw) ? (bbRaw * 100).toFixed(0) + '%' : 'N/A';
|
|
const z60Val = item.z60 !== null ? item.z60 : "N/A";
|
|
const z120Val = item.z120 !== null ? item.z120 : "N/A";
|
|
|
|
const isFresh = item.last_date === todayStr;
|
|
const dateBadgeClass = isFresh ? 'badge bg-success-subtle text-success border border-success-subtle' : 'text-muted';
|
|
|
|
// --- C. Construct Row ---
|
|
htmlContent += `
|
|
<tr>
|
|
<td><div class="fw-bold">${item.name || item.symbol}</div></td>
|
|
<td><span class="table-date ${dateBadgeClass}" style="color: ${dateColor} !important;">${displayDate}</span></td>
|
|
<td class="fw-bold">${item.last_close}</td>
|
|
<td class="${item.change_pct >= 0 ? 'text-up' : 'text-down'}">
|
|
${item.change_pct >= 0 ? '+' : ''}${item.change_pct}%
|
|
</td>
|
|
<td class="${rangeColor} small">
|
|
<div class="d-flex justify-content-between mb-1" style="min-width: 100px; font-size: 0.7rem;">
|
|
<span>${item.low_52}</span><span>${item.high_52}</span>
|
|
</div>
|
|
<div class="progress" style="height: 4px;">
|
|
<div class="progress-bar bg-primary" style="width: ${rangePct}%"></div>
|
|
</div>
|
|
</td>
|
|
<td ${getRSIColor(rsiVal)} class="text-center">${rsiVal}</td>
|
|
<td ${getBBColor(item.bb_pct)} class="text-center">${bbDisplay}</td>
|
|
<td ${getZColor(z60Val)} class="text-center">${z60Val}</td>
|
|
<td ${getZColor(z120Val)} class="text-center">${z120Val}</td>
|
|
<td>${typeof formatEma === 'function' ? formatEma(item.last_ema20) : item.last_ema20}</td>
|
|
<td>${typeof formatEma === 'function' ? formatEma(item.last_ema50) : item.last_ema50}</td>
|
|
<td>${typeof formatEma === 'function' ? formatEma(item.last_ema100) : item.last_ema100}</td>
|
|
<td>${typeof formatEma === 'function' ? formatEma(item.last_ema200) : item.last_ema200}</td>
|
|
<td>${typeof formatKD === 'function' ? formatKD(item.kd_values) : 'N/A'}</td>
|
|
</tr>`;
|
|
});
|
|
} else {
|
|
htmlContent = '<tr><td colspan="14" class="text-center">No data available</td></tr>';
|
|
}
|
|
|
|
tbody.innerHTML = htmlContent;
|
|
|
|
} catch (error) {
|
|
console.error("Fetch error:", error);
|
|
if (tbody) tbody.innerHTML = '<tr><td colspan="14" class="text-danger p-4 text-center">API Error: Check Console</td></tr>';
|
|
} finally {
|
|
if (loading) loading.style.display = 'none';
|
|
}
|
|
}
|
|
// --- 4. Global Sync ---
|
|
async function runGlobalSync() {
|
|
console.log("Sync triggered...");
|
|
const syncBtn = document.getElementById('syncBtn');
|
|
const loading = document.getElementById('loading');
|
|
if (!syncBtn) return;
|
|
|
|
syncBtn.disabled = true;
|
|
const originalText = syncBtn.innerHTML;
|
|
syncBtn.innerHTML = `<span class="spinner-border spinner-border-sm"></span> Syncing...`;
|
|
if (loading) loading.style.display = 'inline';
|
|
|
|
try {
|
|
const response = await fetch('/api/sync', { method: 'POST' });
|
|
if (!response.ok) throw new Error("Sync failed");
|
|
await loadData();
|
|
alert("Sync Complete!");
|
|
} catch (error) {
|
|
console.error("Sync error:", error);
|
|
alert("Sync failed. Check terminal.");
|
|
} finally {
|
|
syncBtn.disabled = false;
|
|
syncBtn.innerHTML = originalText;
|
|
if (loading) loading.style.display = 'none';
|
|
}
|
|
}
|
|
// This checks if the Flask server is responding every 30 seconds
|
|
async function checkStatus() {
|
|
const indicator = document.getElementById('statusIndicator');
|
|
|
|
// GUARD: If the element is missing from HTML, exit immediately
|
|
if (!indicator) return;
|
|
|
|
try {
|
|
const response = await fetch('/api/summary');
|
|
if (response.ok) {
|
|
// Using a span for the dot allows us to animate it separately if desired
|
|
indicator.innerHTML = '<span class="status-dot-pulse">●</span> Online';
|
|
indicator.className = 'text-success fw-bold';
|
|
} else {
|
|
throw new Error();
|
|
}
|
|
} catch (e) {
|
|
if (indicator) {
|
|
indicator.innerHTML = '● Offline';
|
|
indicator.className = 'text-danger fw-bold';
|
|
}
|
|
}
|
|
}
|
|
|
|
setInterval(checkStatus, 300000);
|
|
checkStatus(); // Initial check
|
|
|
|
// --- 5. Initial Load ---
|
|
window.addEventListener('load', loadData);
|
|
</script>
|
|
|
|
</body>
|
|
</html> |