1602 lines
53 KiB
Python
1602 lines
53 KiB
Python
#!/usr/bin/env python3
|
|
|
|
"""
|
|
ui_template_dashboard.py - Dashboard HTML Template
|
|
|
|
Contains the main dashboard interface with charts, status, and improved trading view
|
|
"""
|
|
|
|
def get_dashboard_html():
|
|
"""Return the main dashboard HTML"""
|
|
return """
|
|
<!DOCTYPE html>
|
|
<html lang="en">
|
|
<head>
|
|
<meta charset="UTF-8">
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
<title>Trading Intelligence System - Dashboard</title>
|
|
|
|
<!-- Lightweight Charts for candlestick display -->
|
|
<script src="https://unpkg.com/lightweight-charts@4.1.3/dist/lightweight-charts.standalone.production.js"></script>
|
|
|
|
<style>
|
|
* {
|
|
margin: 0;
|
|
padding: 0;
|
|
box-sizing: border-box;
|
|
}
|
|
|
|
body {
|
|
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
|
|
background: linear-gradient(135deg, #1e3c72 0%, #2a5298 100%);
|
|
color: #e0e0e0;
|
|
min-height: 100vh;
|
|
padding: 20px;
|
|
}
|
|
|
|
.container {
|
|
max-width: 1600px;
|
|
margin: 0 auto;
|
|
}
|
|
|
|
.header {
|
|
background: rgba(255, 255, 255, 0.1);
|
|
backdrop-filter: blur(10px);
|
|
border-radius: 15px;
|
|
padding: 25px;
|
|
margin-bottom: 25px;
|
|
box-shadow: 0 8px 32px rgba(0, 0, 0, 0.3);
|
|
border: 1px solid rgba(255, 255, 255, 0.1);
|
|
}
|
|
|
|
.header h1 {
|
|
font-size: 2.2em;
|
|
background: linear-gradient(to right, #4facfe, #00f2fe);
|
|
-webkit-background-clip: text;
|
|
-webkit-text-fill-color: transparent;
|
|
margin-bottom: 10px;
|
|
}
|
|
|
|
.nav-tabs {
|
|
display: flex;
|
|
gap: 15px;
|
|
margin-top: 20px;
|
|
}
|
|
|
|
.nav-tab {
|
|
padding: 12px 24px;
|
|
background: rgba(255, 255, 255, 0.1);
|
|
border: 1px solid rgba(255, 255, 255, 0.2);
|
|
border-radius: 8px;
|
|
color: #e0e0e0;
|
|
text-decoration: none;
|
|
font-weight: 500;
|
|
transition: all 0.3s ease;
|
|
cursor: pointer;
|
|
}
|
|
|
|
.nav-tab:hover {
|
|
background: rgba(255, 255, 255, 0.2);
|
|
transform: translateY(-2px);
|
|
box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
|
|
}
|
|
|
|
.nav-tab.active {
|
|
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
|
|
border-color: #667eea;
|
|
}
|
|
|
|
/* Compact Stats Grid at Top */
|
|
.stats-grid {
|
|
display: grid;
|
|
grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
|
|
gap: 15px;
|
|
margin-bottom: 25px;
|
|
}
|
|
|
|
.stat-card {
|
|
background: rgba(255, 255, 255, 0.1);
|
|
backdrop-filter: blur(10px);
|
|
border-radius: 10px;
|
|
padding: 15px;
|
|
border: 1px solid rgba(255, 255, 255, 0.1);
|
|
transition: all 0.3s ease;
|
|
}
|
|
|
|
.stat-card:hover {
|
|
transform: translateY(-3px);
|
|
box-shadow: 0 6px 20px rgba(0, 0, 0, 0.3);
|
|
}
|
|
|
|
.stat-card h3 {
|
|
font-size: 0.85em;
|
|
text-transform: uppercase;
|
|
letter-spacing: 1px;
|
|
color: #a0a0a0;
|
|
margin-bottom: 8px;
|
|
}
|
|
|
|
.stat-card .value {
|
|
font-size: 1.5em;
|
|
font-weight: bold;
|
|
background: linear-gradient(to right, #4facfe, #00f2fe);
|
|
-webkit-background-clip: text;
|
|
-webkit-text-fill-color: transparent;
|
|
}
|
|
|
|
.card {
|
|
background: rgba(255, 255, 255, 0.1);
|
|
backdrop-filter: blur(10px);
|
|
border-radius: 15px;
|
|
padding: 25px;
|
|
margin-bottom: 25px;
|
|
box-shadow: 0 8px 32px rgba(0, 0, 0, 0.3);
|
|
border: 1px solid rgba(255, 255, 255, 0.1);
|
|
}
|
|
|
|
.card h2 {
|
|
margin-bottom: 20px;
|
|
font-size: 1.5em;
|
|
color: #ffffff;
|
|
}
|
|
|
|
.controls {
|
|
display: flex;
|
|
gap: 15px;
|
|
margin-bottom: 20px;
|
|
flex-wrap: wrap;
|
|
align-items: center;
|
|
}
|
|
|
|
.btn {
|
|
padding: 12px 24px;
|
|
border: none;
|
|
border-radius: 8px;
|
|
font-weight: 600;
|
|
cursor: pointer;
|
|
transition: all 0.3s ease;
|
|
font-size: 0.95em;
|
|
}
|
|
|
|
.btn-primary {
|
|
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
|
|
color: white;
|
|
}
|
|
|
|
.btn-primary:hover {
|
|
transform: translateY(-2px);
|
|
box-shadow: 0 6px 20px rgba(102, 126, 234, 0.4);
|
|
}
|
|
|
|
.btn-success {
|
|
background: linear-gradient(135deg, #11998e 0%, #38ef7d 100%);
|
|
color: white;
|
|
}
|
|
|
|
.btn-success:hover {
|
|
transform: translateY(-2px);
|
|
box-shadow: 0 6px 20px rgba(56, 239, 125, 0.4);
|
|
}
|
|
|
|
.btn-danger {
|
|
background: linear-gradient(135deg, #eb3349 0%, #f45c43 100%);
|
|
color: white;
|
|
}
|
|
|
|
.btn-danger:hover {
|
|
transform: translateY(-2px);
|
|
box-shadow: 0 6px 20px rgba(235, 51, 73, 0.4);
|
|
}
|
|
|
|
.btn-info {
|
|
background: linear-gradient(135deg, #4facfe 0%, #00f2fe 100%);
|
|
color: white;
|
|
}
|
|
|
|
.btn-info:hover {
|
|
transform: translateY(-2px);
|
|
box-shadow: 0 6px 20px rgba(79, 172, 254, 0.4);
|
|
}
|
|
|
|
.btn-secondary {
|
|
background: rgba(255, 255, 255, 0.1);
|
|
color: #e0e0e0;
|
|
border: 1px solid rgba(255, 255, 255, 0.2);
|
|
}
|
|
|
|
.btn-secondary:hover {
|
|
background: rgba(255, 255, 255, 0.2);
|
|
}
|
|
|
|
.btn-warning {
|
|
background: linear-gradient(135deg, #f093fb 0%, #f5576c 100%);
|
|
color: white;
|
|
}
|
|
|
|
.btn-warning:hover {
|
|
transform: translateY(-2px);
|
|
box-shadow: 0 6px 20px rgba(245, 87, 108, 0.4);
|
|
}
|
|
|
|
select, input {
|
|
padding: 12px;
|
|
border-radius: 8px;
|
|
border: 1px solid rgba(255, 255, 255, 0.2);
|
|
background: rgba(255, 255, 255, 0.1);
|
|
color: #e0e0e0;
|
|
font-size: 0.95em;
|
|
min-width: 150px;
|
|
}
|
|
|
|
select:focus, input:focus {
|
|
outline: none;
|
|
border-color: #667eea;
|
|
background: rgba(255, 255, 255, 0.15);
|
|
}
|
|
|
|
.chart-container {
|
|
position: relative;
|
|
height: 600px;
|
|
margin-top: 20px;
|
|
background: #131722;
|
|
border-radius: 12px;
|
|
padding: 15px;
|
|
}
|
|
|
|
#chart {
|
|
width: 100%;
|
|
height: 100%;
|
|
}
|
|
|
|
.loading {
|
|
text-align: center;
|
|
padding: 40px;
|
|
color: #a0a0a0;
|
|
font-size: 1.1em;
|
|
}
|
|
|
|
.status-indicator {
|
|
display: inline-block;
|
|
width: 12px;
|
|
height: 12px;
|
|
border-radius: 50%;
|
|
margin-right: 8px;
|
|
}
|
|
|
|
.status-running {
|
|
background: #38ef7d;
|
|
box-shadow: 0 0 10px #38ef7d;
|
|
}
|
|
|
|
.status-stopped {
|
|
background: #eb3349;
|
|
box-shadow: 0 0 10px #eb3349;
|
|
}
|
|
|
|
/* Trading Pairs Table */
|
|
.pairs-table-container {
|
|
overflow-x: auto;
|
|
margin-top: 20px;
|
|
}
|
|
|
|
.pairs-table {
|
|
width: 100%;
|
|
border-collapse: separate;
|
|
border-spacing: 0;
|
|
background: rgba(0, 0, 0, 0.3);
|
|
border-radius: 10px;
|
|
overflow: hidden;
|
|
}
|
|
|
|
.pairs-table thead {
|
|
background: rgba(255, 255, 255, 0.1);
|
|
}
|
|
|
|
.pairs-table th {
|
|
padding: 15px 12px;
|
|
text-align: left;
|
|
font-weight: 600;
|
|
color: #4facfe;
|
|
text-transform: uppercase;
|
|
font-size: 0.85em;
|
|
letter-spacing: 0.5px;
|
|
border-bottom: 2px solid rgba(79, 172, 254, 0.3);
|
|
white-space: nowrap;
|
|
}
|
|
|
|
.pairs-table td {
|
|
padding: 12px;
|
|
border-bottom: 1px solid rgba(255, 255, 255, 0.05);
|
|
transition: background 0.3s ease;
|
|
font-size: 0.95em;
|
|
}
|
|
|
|
.pairs-table tbody tr {
|
|
transition: all 0.3s ease;
|
|
}
|
|
|
|
.pairs-table tbody tr:hover {
|
|
background: rgba(255, 255, 255, 0.05);
|
|
}
|
|
|
|
.pair-symbol {
|
|
font-weight: bold;
|
|
color: #4facfe;
|
|
font-size: 1.05em;
|
|
}
|
|
|
|
.crypto-icon {
|
|
display: inline-block;
|
|
width: 20px;
|
|
height: 20px;
|
|
margin-right: 8px;
|
|
vertical-align: middle;
|
|
}
|
|
|
|
.price-value {
|
|
font-family: 'Courier New', monospace;
|
|
font-weight: 600;
|
|
color: #fff;
|
|
font-size: 1em;
|
|
}
|
|
|
|
.price-zeros {
|
|
font-size: 0.7em;
|
|
vertical-align: super;
|
|
color: #a0a0a0;
|
|
}
|
|
|
|
.trend-cell {
|
|
text-align: center;
|
|
font-weight: 600;
|
|
font-family: 'Courier New', monospace;
|
|
}
|
|
|
|
.trend-positive {
|
|
color: #38ef7d;
|
|
}
|
|
|
|
.trend-negative {
|
|
color: #eb3349;
|
|
}
|
|
|
|
.trend-neutral {
|
|
color: #a0a0a0;
|
|
}
|
|
|
|
.volume-badge {
|
|
display: inline-block;
|
|
padding: 4px 10px;
|
|
border-radius: 12px;
|
|
font-size: 0.8em;
|
|
font-weight: 600;
|
|
text-align: center;
|
|
}
|
|
|
|
.volume-unusually-low {
|
|
background: rgba(235, 51, 73, 0.3);
|
|
color: #eb3349;
|
|
border: 1px solid rgba(235, 51, 73, 0.5);
|
|
}
|
|
|
|
.volume-low {
|
|
background: rgba(255, 165, 0, 0.3);
|
|
color: #ffa500;
|
|
border: 1px solid rgba(255, 165, 0, 0.5);
|
|
}
|
|
|
|
.volume-average {
|
|
background: rgba(79, 172, 254, 0.3);
|
|
color: #4facfe;
|
|
border: 1px solid rgba(79, 172, 254, 0.5);
|
|
}
|
|
|
|
.volume-high {
|
|
background: rgba(56, 239, 125, 0.3);
|
|
color: #38ef7d;
|
|
border: 1px solid rgba(56, 239, 125, 0.5);
|
|
}
|
|
|
|
.volume-unusually-high {
|
|
background: rgba(56, 239, 125, 0.5);
|
|
color: #38ef7d;
|
|
border: 1px solid #38ef7d;
|
|
animation: pulse-volume 2s ease-in-out infinite;
|
|
}
|
|
|
|
@keyframes pulse-volume {
|
|
0%, 100% { opacity: 1; }
|
|
50% { opacity: 0.7; }
|
|
}
|
|
|
|
.active-icon {
|
|
display: inline-block;
|
|
width: 10px;
|
|
height: 10px;
|
|
border-radius: 50%;
|
|
margin: 0 auto;
|
|
}
|
|
|
|
.active-icon.active {
|
|
background: #38ef7d;
|
|
box-shadow: 0 0 8px #38ef7d;
|
|
}
|
|
|
|
.active-icon.inactive {
|
|
background: #eb3349;
|
|
box-shadow: 0 0 8px #eb3349;
|
|
}
|
|
|
|
.modal {
|
|
display: none;
|
|
position: fixed;
|
|
z-index: 1000;
|
|
left: 0;
|
|
top: 0;
|
|
width: 100%;
|
|
height: 100%;
|
|
background: rgba(0, 0, 0, 0.7);
|
|
backdrop-filter: blur(5px);
|
|
}
|
|
|
|
.modal-content {
|
|
background: linear-gradient(135deg, #1e3c72 0%, #2a5298 100%);
|
|
margin: 5% auto;
|
|
padding: 30px;
|
|
border: 1px solid rgba(255, 255, 255, 0.2);
|
|
border-radius: 15px;
|
|
width: 90%;
|
|
max-width: 600px;
|
|
box-shadow: 0 10px 40px rgba(0, 0, 0, 0.5);
|
|
}
|
|
|
|
.close {
|
|
color: #aaa;
|
|
float: right;
|
|
font-size: 28px;
|
|
font-weight: bold;
|
|
cursor: pointer;
|
|
transition: color 0.3s;
|
|
}
|
|
|
|
.close:hover {
|
|
color: #fff;
|
|
}
|
|
|
|
.form-group {
|
|
margin-bottom: 20px;
|
|
}
|
|
|
|
.form-group label {
|
|
display: block;
|
|
margin-bottom: 8px;
|
|
color: #e0e0e0;
|
|
font-weight: 500;
|
|
}
|
|
|
|
.form-group input,
|
|
.form-group select {
|
|
width: 100%;
|
|
}
|
|
|
|
.alert {
|
|
padding: 15px;
|
|
border-radius: 8px;
|
|
margin-bottom: 20px;
|
|
display: none;
|
|
}
|
|
|
|
.alert-success {
|
|
background: rgba(56, 239, 125, 0.2);
|
|
border: 1px solid #38ef7d;
|
|
color: #38ef7d;
|
|
}
|
|
|
|
.alert-error {
|
|
background: rgba(235, 51, 73, 0.2);
|
|
border: 1px solid #eb3349;
|
|
color: #eb3349;
|
|
}
|
|
|
|
.alert-info {
|
|
background: rgba(79, 172, 254, 0.2);
|
|
border: 1px solid #4facfe;
|
|
color: #4facfe;
|
|
}
|
|
|
|
@keyframes fadeIn {
|
|
from {
|
|
opacity: 0;
|
|
transform: translateY(-10px);
|
|
}
|
|
to {
|
|
opacity: 1;
|
|
transform: translateY(0);
|
|
}
|
|
}
|
|
|
|
.pairs-table tbody tr {
|
|
animation: fadeIn 0.3s ease-in-out;
|
|
}
|
|
|
|
/* Scrollbar styling */
|
|
::-webkit-scrollbar {
|
|
width: 10px;
|
|
height: 10px;
|
|
}
|
|
|
|
::-webkit-scrollbar-track {
|
|
background: rgba(255, 255, 255, 0.1);
|
|
border-radius: 5px;
|
|
}
|
|
|
|
::-webkit-scrollbar-thumb {
|
|
background: rgba(102, 126, 234, 0.5);
|
|
border-radius: 5px;
|
|
}
|
|
|
|
::-webkit-scrollbar-thumb:hover {
|
|
background: rgba(102, 126, 234, 0.7);
|
|
}
|
|
|
|
/* Download Progress Styles */
|
|
.download-item {
|
|
background: rgba(255, 255, 255, 0.05);
|
|
border: 1px solid rgba(255, 255, 255, 0.1);
|
|
border-radius: 10px;
|
|
padding: 15px;
|
|
margin-bottom: 15px;
|
|
}
|
|
|
|
.download-header {
|
|
display: flex;
|
|
justify-content: space-between;
|
|
align-items: center;
|
|
margin-bottom: 15px;
|
|
padding-bottom: 10px;
|
|
border-bottom: 1px solid rgba(255, 255, 255, 0.1);
|
|
}
|
|
|
|
.download-symbol {
|
|
font-weight: bold;
|
|
font-size: 1.2em;
|
|
color: #4facfe;
|
|
}
|
|
|
|
.download-status {
|
|
padding: 5px 15px;
|
|
border-radius: 20px;
|
|
font-size: 0.9em;
|
|
font-weight: 600;
|
|
}
|
|
|
|
.status-running {
|
|
background: rgba(79, 172, 254, 0.3);
|
|
color: #4facfe;
|
|
animation: pulse 2s ease-in-out infinite;
|
|
}
|
|
|
|
.status-completed {
|
|
background: rgba(56, 239, 125, 0.3);
|
|
color: #38ef7d;
|
|
}
|
|
|
|
.status-error {
|
|
background: rgba(235, 51, 73, 0.3);
|
|
color: #eb3349;
|
|
}
|
|
|
|
@keyframes pulse {
|
|
0%, 100% { opacity: 1; }
|
|
50% { opacity: 0.6; }
|
|
}
|
|
|
|
.download-intervals {
|
|
margin-top: 10px;
|
|
}
|
|
|
|
.interval-progress {
|
|
display: flex;
|
|
justify-content: space-between;
|
|
align-items: center;
|
|
padding: 8px 0;
|
|
border-bottom: 1px solid rgba(255, 255, 255, 0.05);
|
|
}
|
|
|
|
.interval-progress:last-child {
|
|
border-bottom: none;
|
|
}
|
|
|
|
.interval-name {
|
|
font-weight: 600;
|
|
color: #4facfe;
|
|
min-width: 60px;
|
|
}
|
|
|
|
.interval-status {
|
|
flex: 1;
|
|
text-align: center;
|
|
color: #a0a0a0;
|
|
font-size: 0.9em;
|
|
}
|
|
|
|
.interval-records {
|
|
color: #e0e0e0;
|
|
font-size: 0.9em;
|
|
}
|
|
|
|
.download-time {
|
|
font-size: 0.85em;
|
|
color: #a0a0a0;
|
|
margin-top: 8px;
|
|
}
|
|
|
|
.download-error {
|
|
background: rgba(235, 51, 73, 0.2);
|
|
border: 1px solid #eb3349;
|
|
color: #eb3349;
|
|
padding: 8px;
|
|
border-radius: 5px;
|
|
margin-top: 10px;
|
|
font-size: 0.9em;
|
|
}
|
|
|
|
.chart-controls {
|
|
display: flex;
|
|
gap: 10px;
|
|
align-items: center;
|
|
flex-wrap: wrap;
|
|
margin-bottom: 15px;
|
|
}
|
|
|
|
.chart-controls label {
|
|
display: flex;
|
|
align-items: center;
|
|
gap: 8px;
|
|
color: #e0e0e0;
|
|
font-size: 0.9em;
|
|
}
|
|
|
|
.date-input {
|
|
padding: 8px;
|
|
border-radius: 6px;
|
|
border: 1px solid rgba(255, 255, 255, 0.2);
|
|
background: rgba(255, 255, 255, 0.1);
|
|
color: #e0e0e0;
|
|
font-size: 0.9em;
|
|
}
|
|
|
|
.indicator-toggle {
|
|
display: flex;
|
|
gap: 10px;
|
|
flex-wrap: wrap;
|
|
margin-top: 10px;
|
|
}
|
|
|
|
.indicator-btn {
|
|
padding: 8px 16px;
|
|
border-radius: 6px;
|
|
border: 1px solid rgba(255, 255, 255, 0.2);
|
|
background: rgba(255, 255, 255, 0.1);
|
|
color: #e0e0e0;
|
|
cursor: pointer;
|
|
transition: all 0.3s ease;
|
|
font-size: 0.85em;
|
|
}
|
|
|
|
.indicator-btn.active {
|
|
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
|
|
border-color: #667eea;
|
|
}
|
|
|
|
.indicator-btn:hover {
|
|
background: rgba(255, 255, 255, 0.2);
|
|
}
|
|
</style>
|
|
</head>
|
|
<body>
|
|
<div class="container">
|
|
<!-- Header -->
|
|
<div class="header">
|
|
<h1>📈 Trading Intelligence System</h1>
|
|
<p>Real-time market data collection and analysis platform</p>
|
|
<div class="nav-tabs">
|
|
<a href="/" class="nav-tab active">Dashboard</a>
|
|
<a href="/config" class="nav-tab">Configuration</a>
|
|
<a href="/gaps" class="nav-tab">Gaps</a>
|
|
</div>
|
|
</div>
|
|
|
|
<!-- Alert Messages -->
|
|
<div id="alertContainer"></div>
|
|
|
|
<!-- Compact Statistics at Top -->
|
|
<div class="stats-grid">
|
|
<div class="stat-card">
|
|
<h3>Status</h3>
|
|
<div class="value" id="collectionStatus">
|
|
<span class="status-indicator status-stopped"></span> Loading...
|
|
</div>
|
|
</div>
|
|
<div class="stat-card">
|
|
<h3>Total Records</h3>
|
|
<div class="value" id="totalRecords">0</div>
|
|
</div>
|
|
<div class="stat-card">
|
|
<h3>Active Pairs</h3>
|
|
<div class="value" id="activePairs">0</div>
|
|
</div>
|
|
<div class="stat-card">
|
|
<h3>Last Update</h3>
|
|
<div class="value" style="font-size: 1.2em;" id="lastUpdate">Never</div>
|
|
</div>
|
|
</div>
|
|
|
|
<!-- Collection Controls -->
|
|
<div class="card">
|
|
<h2>⚙️ Collection Controls</h2>
|
|
<div class="controls">
|
|
<button class="btn btn-success" onclick="startCollection()">▶ Start Collection</button>
|
|
<button class="btn btn-danger" onclick="stopCollection()">⏹ Stop Collection</button>
|
|
<button class="btn btn-info" onclick="refreshStats()">🔄 Refresh Stats</button>
|
|
<button class="btn btn-warning" onclick="showBulkDownloadModal()">📥 Bulk Download</button>
|
|
<button class="btn btn-info" onclick="showDownloadProgressModal()">📊 View Downloads</button>
|
|
</div>
|
|
</div>
|
|
|
|
<!-- Active Trading Pairs Table -->
|
|
<div class="card">
|
|
<h2>💹 Active Trading Pairs</h2>
|
|
<div class="pairs-table-container">
|
|
<table class="pairs-table" id="pairsTable">
|
|
<thead>
|
|
<tr>
|
|
<th>Pair</th>
|
|
<th>Price</th>
|
|
<th>15M</th>
|
|
<th>1H</th>
|
|
<th>1D</th>
|
|
<th>1W</th>
|
|
<th>Volume Status</th>
|
|
<th style="text-align: center;">Active</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody id="pairsTableBody">
|
|
<tr>
|
|
<td colspan="8" class="loading">Loading pairs...</td>
|
|
</tr>
|
|
</tbody>
|
|
</table>
|
|
</div>
|
|
</div>
|
|
|
|
<!-- Price Chart -->
|
|
<div class="card">
|
|
<h2>📊 Advanced Price Chart</h2>
|
|
<div class="chart-controls">
|
|
<select id="chartSymbol">
|
|
<option value="">Select Symbol</option>
|
|
</select>
|
|
<select id="chartInterval">
|
|
<option value="1m">1 Minute</option>
|
|
<option value="5m">5 Minutes</option>
|
|
<option value="15m">15 Minutes</option>
|
|
<option value="1h" selected>1 Hour</option>
|
|
<option value="4h">4 Hours</option>
|
|
<option value="1d">1 Day</option>
|
|
</select>
|
|
<label>
|
|
Candles:
|
|
<input type="number" id="chartLimit" value="500" min="50" max="5000" style="width: 100px;">
|
|
</label>
|
|
<button class="btn btn-primary" onclick="loadChartData()">📈 Load Chart</button>
|
|
</div>
|
|
|
|
<!-- Technical Indicators Toggle -->
|
|
<div class="indicator-toggle">
|
|
<button class="indicator-btn" id="volumeIndicator" onclick="toggleIndicator('volume')">
|
|
Volume
|
|
</button>
|
|
<button class="indicator-btn" id="smaIndicator" onclick="toggleIndicator('sma')">
|
|
SMA (20)
|
|
</button>
|
|
<button class="indicator-btn" id="emaIndicator" onclick="toggleIndicator('ema')">
|
|
EMA (20)
|
|
</button>
|
|
</div>
|
|
|
|
<div class="chart-container">
|
|
<div id="chart"></div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<!-- Bulk Download Modal - UPDATED -->
|
|
<div id="bulkDownloadModal" class="modal">
|
|
<div class="modal-content">
|
|
<span class="close" onclick="closeBulkDownloadModal()">×</span>
|
|
<h2>Bulk Historical Download</h2>
|
|
|
|
<div class="form-group">
|
|
<label for="bulkSymbol">Trading Pairs (hold Ctrl/Cmd to select multiple)</label>
|
|
<select id="bulkSymbol" multiple size="6" style="height: 150px;">
|
|
<option value="">Loading symbols...</option>
|
|
</select>
|
|
<small style="color: #a0a0a0; display: block; margin-top: 5px;">
|
|
Hold Ctrl (Windows/Linux) or Cmd (Mac) to select multiple pairs
|
|
</small>
|
|
</div>
|
|
|
|
<div class="form-group">
|
|
<label for="bulkStartDate">Start Date</label>
|
|
<input type="datetime-local" id="bulkStartDate" value="2020-01-01T00:00">
|
|
</div>
|
|
|
|
<div class="form-group">
|
|
<label for="bulkEndDate">End Date (Optional - defaults to now)</label>
|
|
<input type="datetime-local" id="bulkEndDate">
|
|
<small style="color: #a0a0a0; display: block; margin-top: 5px;">
|
|
Leave empty to download up to current time
|
|
</small>
|
|
</div>
|
|
|
|
<div class="form-group">
|
|
<label>Intervals</label>
|
|
<div style="display: flex; gap: 10px; flex-wrap: wrap; margin-top: 10px;">
|
|
<label style="display: flex; align-items: center; gap: 5px;">
|
|
<input type="checkbox" value="1m" checked> 1m
|
|
</label>
|
|
<label style="display: flex; align-items: center; gap: 5px;">
|
|
<input type="checkbox" value="5m" checked> 5m
|
|
</label>
|
|
<label style="display: flex; align-items: center; gap: 5px;">
|
|
<input type="checkbox" value="15m" checked> 15m
|
|
</label>
|
|
<label style="display: flex; align-items: center; gap: 5px;">
|
|
<input type="checkbox" value="1h" checked> 1h
|
|
</label>
|
|
<label style="display: flex; align-items: center; gap: 5px;">
|
|
<input type="checkbox" value="4h" checked> 4h
|
|
</label>
|
|
<label style="display: flex; align-items: center; gap: 5px;">
|
|
<input type="checkbox" value="1d" checked> 1d
|
|
</label>
|
|
</div>
|
|
</div>
|
|
|
|
<button class="btn btn-primary" onclick="startBulkDownload()">Start Download</button>
|
|
</div>
|
|
</div>
|
|
|
|
<!-- Download Progress Modal - NEW -->
|
|
<div id="downloadProgressModal" class="modal">
|
|
<div class="modal-content">
|
|
<span class="close" onclick="closeDownloadProgressModal()">×</span>
|
|
<h2>Download Progress</h2>
|
|
<p style="margin-bottom: 20px; color: #a0a0a0;">
|
|
Live status of all bulk download operations
|
|
</p>
|
|
<div id="downloadProgressList" style="max-height: 500px; overflow-y: auto;">
|
|
<div style="text-align: center; padding: 40px;">Loading...</div>
|
|
</div>
|
|
<button class="btn btn-secondary" onclick="closeDownloadProgressModal()">Close</button>
|
|
</div>
|
|
</div>
|
|
|
|
<script>
|
|
let chart = null;
|
|
let candlestickSeries = null;
|
|
let volumeSeries = null;
|
|
let smaSeries = null;
|
|
let emaSeries = null;
|
|
let pairsData = {}; // Store pairs data for smooth updates
|
|
let currentSymbol = null;
|
|
let currentInterval = null;
|
|
let activeIndicators = {
|
|
volume: false,
|
|
sma: false,
|
|
ema: false
|
|
};
|
|
|
|
// Initialize on page load
|
|
document.addEventListener('DOMContentLoaded', function() {
|
|
loadSymbols();
|
|
refreshStats();
|
|
loadPairsWithTrends();
|
|
setInterval(refreshStats, 5000); // Refresh every 5 seconds
|
|
setInterval(updatePairsData, 3000); // Update pairs every 3 seconds
|
|
|
|
// Load saved symbol from cookie
|
|
const savedSymbol = getCookie('selectedSymbol');
|
|
if (savedSymbol) {
|
|
document.getElementById('chartSymbol').value = savedSymbol;
|
|
}
|
|
});
|
|
|
|
// Cookie functions
|
|
function setCookie(name, value, days = 30) {
|
|
const expires = new Date(Date.now() + days * 864e5).toUTCString();
|
|
document.cookie = name + '=' + encodeURIComponent(value) + '; expires=' + expires + '; path=/';
|
|
}
|
|
|
|
function getCookie(name) {
|
|
return document.cookie.split('; ').reduce((r, v) => {
|
|
const parts = v.split('=');
|
|
return parts[0] === name ? decodeURIComponent(parts[1]) : r;
|
|
}, '');
|
|
}
|
|
|
|
// Show alert message
|
|
function showAlert(message, type = 'info') {
|
|
const container = document.getElementById('alertContainer');
|
|
const alert = document.createElement('div');
|
|
alert.className = `alert alert-${type}`;
|
|
alert.textContent = message;
|
|
alert.style.display = 'block';
|
|
container.appendChild(alert);
|
|
setTimeout(() => alert.remove(), 5000);
|
|
}
|
|
|
|
// Load available symbols
|
|
async function loadSymbols() {
|
|
try {
|
|
const response = await fetch('/api/symbols');
|
|
const data = await response.json();
|
|
|
|
if (data.status === 'success' && data.symbols) {
|
|
const chartSymbol = document.getElementById('chartSymbol');
|
|
const bulkSymbol = document.getElementById('bulkSymbol');
|
|
|
|
data.symbols.forEach(symbol => {
|
|
chartSymbol.innerHTML += `<option value="${symbol}">${symbol}</option>`;
|
|
bulkSymbol.innerHTML += `<option value="${symbol}">${symbol}</option>`;
|
|
});
|
|
}
|
|
} catch (error) {
|
|
console.error('Error loading symbols:', error);
|
|
}
|
|
}
|
|
|
|
// Time ago helper function
|
|
function timeAgo(dateString) {
|
|
if (!dateString || dateString === 'Never') return 'Never';
|
|
const now = new Date();
|
|
const past = new Date(dateString);
|
|
const diffMs = now - past;
|
|
const diffSecs = Math.floor(diffMs / 1000);
|
|
const diffMins = Math.floor(diffSecs / 60);
|
|
const diffHours = Math.floor(diffMins / 60);
|
|
const diffDays = Math.floor(diffHours / 24);
|
|
|
|
if (diffSecs < 60) return `${diffSecs}s ago`;
|
|
if (diffMins < 60) return `${diffMins}m ago`;
|
|
if (diffHours < 24) return `${diffHours}h ago`;
|
|
return `${diffDays}d ago`;
|
|
}
|
|
|
|
// Refresh statistics
|
|
async function refreshStats() {
|
|
try {
|
|
const response = await fetch('/api/stats');
|
|
const data = await response.json();
|
|
|
|
// Update status
|
|
const statusEl = document.getElementById('collectionStatus');
|
|
const isRunning = data.is_collecting || false;
|
|
const statusClass = isRunning ? 'status-running' : 'status-stopped';
|
|
const statusText = isRunning ? 'Running' : 'Stopped';
|
|
statusEl.innerHTML = `<span class="status-indicator ${statusClass}"></span>${statusText}`;
|
|
|
|
// Update stats
|
|
document.getElementById('totalRecords').textContent = (data.total_records || 0).toLocaleString();
|
|
document.getElementById('activePairs').textContent = data.active_pairs || 0;
|
|
document.getElementById('lastUpdate').textContent = timeAgo(data.last_update);
|
|
} catch (error) {
|
|
console.error('Error refreshing stats:', error);
|
|
}
|
|
}
|
|
|
|
// Format price with smart zero handling
|
|
function formatPrice(price, symbol) {
|
|
if (!price || price === 0) return '$0.00';
|
|
|
|
const priceStr = price.toString();
|
|
const parts = priceStr.split('.');
|
|
|
|
if (parts.length === 1 || !parts[1]) {
|
|
return '$' + price.toFixed(2);
|
|
}
|
|
|
|
const decimals = parts[1];
|
|
let zeroCount = 0;
|
|
|
|
// Count leading zeros
|
|
for (let i = 0; i < decimals.length; i++) {
|
|
if (decimals[i] === '0') zeroCount++;
|
|
else break;
|
|
}
|
|
|
|
// If more than 3 leading zeros, use ellipsis notation
|
|
if (zeroCount > 3) {
|
|
const significantPart = decimals.substring(zeroCount, zeroCount + 3);
|
|
return `$0.0<span class="price-zeros">${zeroCount}</span>${significantPart}`;
|
|
}
|
|
|
|
// Otherwise, show normally with max 8 decimals
|
|
return '$' + price.toFixed(Math.min(8, decimals.length));
|
|
}
|
|
|
|
// Get crypto icon
|
|
function getCryptoIcon(symbol) {
|
|
// Extract base currency
|
|
const base = symbol.replace('USDT', '').replace('BTC', '').replace('ETH', '').replace('BUSD', '');
|
|
|
|
// Map common cryptos to their symbols
|
|
const iconMap = {
|
|
'BTC': '₿',
|
|
'ETH': 'Ξ',
|
|
'BNB': '⚡',
|
|
'XRP': '✕',
|
|
'ADA': '₳',
|
|
'SOL': '◎',
|
|
'DOT': '●',
|
|
'DOGE': 'Ð',
|
|
'MATIC': '⬡',
|
|
'LTC': 'Ł'
|
|
};
|
|
|
|
return iconMap[base] || '●';
|
|
}
|
|
|
|
// Load pairs with trends - initial load
|
|
async function loadPairsWithTrends() {
|
|
try {
|
|
const response = await fetch('/api/symbols');
|
|
const data = await response.json();
|
|
|
|
if (data.status !== 'success' || !data.symbols || data.symbols.length === 0) {
|
|
document.getElementById('pairsTableBody').innerHTML =
|
|
'<tr><td colspan="8" class="loading">No trading pairs configured</td></tr>';
|
|
return;
|
|
}
|
|
|
|
// Initial load - create table structure
|
|
const tbody = document.getElementById('pairsTableBody');
|
|
tbody.innerHTML = '';
|
|
|
|
for (const symbol of data.symbols) {
|
|
const row = createPairRow(symbol, null);
|
|
tbody.innerHTML += row;
|
|
// Fetch data for this symbol
|
|
fetchPairData(symbol);
|
|
}
|
|
} catch (error) {
|
|
console.error('Error loading pairs:', error);
|
|
document.getElementById('pairsTableBody').innerHTML =
|
|
'<tr><td colspan="8" class="loading">Error loading pairs</td></tr>';
|
|
}
|
|
}
|
|
|
|
// Fetch data for a single pair
|
|
async function fetchPairData(symbol) {
|
|
try {
|
|
const response = await fetch(`/api/price-trends/${symbol}`);
|
|
const data = await response.json();
|
|
|
|
if (data.status === 'success') {
|
|
pairsData[symbol] = data.data;
|
|
updatePairRow(symbol, data.data);
|
|
}
|
|
} catch (error) {
|
|
console.error(`Error fetching data for ${symbol}:`, error);
|
|
}
|
|
}
|
|
|
|
// Update pairs data (called periodically)
|
|
async function updatePairsData() {
|
|
for (const symbol in pairsData) {
|
|
fetchPairData(symbol);
|
|
}
|
|
}
|
|
|
|
// Create pair row (skeleton or with data)
|
|
function createPairRow(symbol, data) {
|
|
const icon = getCryptoIcon(symbol);
|
|
|
|
if (!data) {
|
|
return `
|
|
<tr id="pair-${symbol}">
|
|
<td><span class="crypto-icon">${icon}</span><span class="pair-symbol">${symbol}</span></td>
|
|
<td class="price-value">Loading...</td>
|
|
<td class="trend-cell trend-neutral">--</td>
|
|
<td class="trend-cell trend-neutral">--</td>
|
|
<td class="trend-cell trend-neutral">--</td>
|
|
<td class="trend-cell trend-neutral">--</td>
|
|
<td><span class="volume-badge volume-average">Loading</span></td>
|
|
<td style="text-align: center;"><div class="active-icon inactive"></div></td>
|
|
</tr>
|
|
`;
|
|
}
|
|
|
|
return getPairRowHTML(symbol, data);
|
|
}
|
|
|
|
// Get pair row HTML
|
|
function getPairRowHTML(symbol, data) {
|
|
const icon = getCryptoIcon(symbol);
|
|
const trends = data.trends;
|
|
const volumeClass = getVolumeClass(data.volume_status);
|
|
const activeClass = data.enabled ? 'active' : 'inactive';
|
|
|
|
function getTrendHTML(value) {
|
|
if (value === 0) return '<td class="trend-cell trend-neutral">0%</td>';
|
|
const cls = value > 0 ? 'trend-positive' : 'trend-negative';
|
|
const sign = value > 0 ? '+' : '';
|
|
return `<td class="trend-cell ${cls}">${sign}${value.toFixed(2)}%</td>`;
|
|
}
|
|
|
|
return `
|
|
<tr id="pair-${symbol}">
|
|
<td><span class="crypto-icon">${icon}</span><span class="pair-symbol">${symbol}</span></td>
|
|
<td class="price-value">${formatPrice(data.current_price, symbol)}</td>
|
|
${getTrendHTML(trends['15m'])}
|
|
${getTrendHTML(trends['1h'])}
|
|
${getTrendHTML(trends['1d'])}
|
|
${getTrendHTML(trends['1w'])}
|
|
<td><span class="volume-badge ${volumeClass}">${data.volume_status}</span></td>
|
|
<td style="text-align: center;"><div class="active-icon ${activeClass}"></div></td>
|
|
</tr>
|
|
`;
|
|
}
|
|
|
|
// Update existing pair row (smooth update without flicker)
|
|
function updatePairRow(symbol, data) {
|
|
const row = document.getElementById(`pair-${symbol}`);
|
|
if (!row) return;
|
|
|
|
const newRowHTML = getPairRowHTML(symbol, data);
|
|
const temp = document.createElement('tbody');
|
|
temp.innerHTML = newRowHTML;
|
|
const newRow = temp.firstElementChild;
|
|
|
|
// Update only changed cells to avoid flicker
|
|
const oldCells = row.querySelectorAll('td');
|
|
const newCells = newRow.querySelectorAll('td');
|
|
|
|
for (let i = 0; i < oldCells.length; i++) {
|
|
if (oldCells[i].innerHTML !== newCells[i].innerHTML) {
|
|
oldCells[i].innerHTML = newCells[i].innerHTML;
|
|
}
|
|
}
|
|
}
|
|
|
|
// Get volume class
|
|
function getVolumeClass(status) {
|
|
const map = {
|
|
'Unusually Low': 'volume-unusually-low',
|
|
'Low': 'volume-low',
|
|
'Average': 'volume-average',
|
|
'High': 'volume-high',
|
|
'Unusually High': 'volume-unusually-high'
|
|
};
|
|
return map[status] || 'volume-average';
|
|
}
|
|
|
|
// Start collection
|
|
async function startCollection() {
|
|
try {
|
|
const response = await fetch('/api/collection/start', { method: 'POST' });
|
|
const data = await response.json();
|
|
showAlert(data.message, data.status === 'success' ? 'success' : 'error');
|
|
refreshStats();
|
|
} catch (error) {
|
|
showAlert(`Error starting collection: ${error.message}`, 'error');
|
|
}
|
|
}
|
|
|
|
// Stop collection
|
|
async function stopCollection() {
|
|
try {
|
|
const response = await fetch('/api/collection/stop', { method: 'POST' });
|
|
const data = await response.json();
|
|
showAlert(data.message, data.status === 'success' ? 'success' : 'error');
|
|
refreshStats();
|
|
} catch (error) {
|
|
showAlert(`Error stopping collection: ${error.message}`, 'error');
|
|
}
|
|
}
|
|
|
|
// Calculate SMA
|
|
function calculateSMA(data, period = 20) {
|
|
const sma = [];
|
|
for (let i = 0; i < data.length; i++) {
|
|
if (i < period - 1) {
|
|
sma.push({ time: data[i].time, value: null });
|
|
continue;
|
|
}
|
|
|
|
let sum = 0;
|
|
for (let j = 0; j < period; j++) {
|
|
sum += data[i - j].close;
|
|
}
|
|
sma.push({ time: data[i].time, value: sum / period });
|
|
}
|
|
return sma.filter(d => d.value !== null);
|
|
}
|
|
|
|
// Calculate EMA
|
|
function calculateEMA(data, period = 20) {
|
|
const ema = [];
|
|
const multiplier = 2 / (period + 1);
|
|
|
|
// Start with SMA for first value
|
|
let sum = 0;
|
|
for (let i = 0; i < period; i++) {
|
|
sum += data[i].close;
|
|
}
|
|
let emaValue = sum / period;
|
|
ema.push({ time: data[period - 1].time, value: emaValue });
|
|
|
|
// Calculate EMA for rest
|
|
for (let i = period; i < data.length; i++) {
|
|
emaValue = (data[i].close - emaValue) * multiplier + emaValue;
|
|
ema.push({ time: data[i].time, value: emaValue });
|
|
}
|
|
|
|
return ema;
|
|
}
|
|
|
|
// Toggle indicator
|
|
function toggleIndicator(indicator) {
|
|
activeIndicators[indicator] = !activeIndicators[indicator];
|
|
const btn = document.getElementById(`${indicator}Indicator`);
|
|
|
|
if (activeIndicators[indicator]) {
|
|
btn.classList.add('active');
|
|
} else {
|
|
btn.classList.remove('active');
|
|
}
|
|
|
|
// Reload chart with updated indicators
|
|
if (currentSymbol && currentInterval) {
|
|
loadChartDataInternal(currentSymbol, currentInterval);
|
|
}
|
|
}
|
|
|
|
// Load chart data
|
|
async function loadChartData() {
|
|
const symbol = document.getElementById('chartSymbol').value;
|
|
const interval = document.getElementById('chartInterval').value;
|
|
|
|
if (!symbol) {
|
|
showAlert('Please select a symbol', 'error');
|
|
return;
|
|
}
|
|
|
|
// Save symbol to cookie
|
|
setCookie('selectedSymbol', symbol);
|
|
|
|
currentSymbol = symbol;
|
|
currentInterval = interval;
|
|
|
|
await loadChartDataInternal(symbol, interval);
|
|
}
|
|
|
|
// Internal chart loading function
|
|
async function loadChartDataInternal(symbol, interval) {
|
|
const limit = parseInt(document.getElementById('chartLimit').value);
|
|
|
|
try {
|
|
const response = await fetch('/api/chart-data', {
|
|
method: 'POST',
|
|
headers: { 'Content-Type': 'application/json' },
|
|
body: JSON.stringify({ symbol, interval, limit })
|
|
});
|
|
|
|
const data = await response.json();
|
|
|
|
if (data.status === 'success' && data.data) {
|
|
renderChart(data.data, symbol, interval);
|
|
showAlert('Chart loaded successfully', 'success');
|
|
} else {
|
|
showAlert(data.message || 'No data available', 'error');
|
|
}
|
|
} catch (error) {
|
|
showAlert(`Error loading chart: ${error.message}`, 'error');
|
|
}
|
|
}
|
|
|
|
// Render chart with Lightweight Charts
|
|
function renderChart(data, symbol, interval) {
|
|
const chartContainer = document.getElementById('chart');
|
|
|
|
// Clear existing chart
|
|
if (chart) {
|
|
chart.remove();
|
|
chart = null;
|
|
candlestickSeries = null;
|
|
volumeSeries = null;
|
|
smaSeries = null;
|
|
emaSeries = null;
|
|
}
|
|
|
|
// Create new chart
|
|
chart = LightweightCharts.createChart(chartContainer, {
|
|
width: chartContainer.clientWidth,
|
|
height: chartContainer.clientHeight,
|
|
layout: {
|
|
background: { color: '#131722' },
|
|
textColor: '#d1d4dc',
|
|
},
|
|
grid: {
|
|
vertLines: { color: 'rgba(42, 46, 57, 0.5)' },
|
|
horzLines: { color: 'rgba(42, 46, 57, 0.5)' },
|
|
},
|
|
crosshair: {
|
|
mode: LightweightCharts.CrosshairMode.Normal,
|
|
},
|
|
rightPriceScale: {
|
|
borderColor: 'rgba(197, 203, 206, 0.4)',
|
|
},
|
|
timeScale: {
|
|
borderColor: 'rgba(197, 203, 206, 0.4)',
|
|
timeVisible: true,
|
|
secondsVisible: false,
|
|
},
|
|
});
|
|
|
|
// Add candlestick series
|
|
candlestickSeries = chart.addCandlestickSeries({
|
|
upColor: '#26a69a',
|
|
downColor: '#ef5350',
|
|
borderVisible: false,
|
|
wickUpColor: '#26a69a',
|
|
wickDownColor: '#ef5350',
|
|
});
|
|
|
|
// Transform data for candlestick chart
|
|
const candleData = data.map(d => ({
|
|
time: new Date(d.timestamp).getTime() / 1000,
|
|
open: d.open,
|
|
high: d.high,
|
|
low: d.low,
|
|
close: d.close
|
|
}));
|
|
|
|
candlestickSeries.setData(candleData);
|
|
|
|
// Add volume series if enabled
|
|
if (activeIndicators.volume) {
|
|
volumeSeries = chart.addHistogramSeries({
|
|
color: '#26a69a',
|
|
priceFormat: {
|
|
type: 'volume',
|
|
},
|
|
priceScaleId: '',
|
|
scaleMargins: {
|
|
top: 0.8,
|
|
bottom: 0,
|
|
},
|
|
});
|
|
|
|
const volumeData = data.map(d => ({
|
|
time: new Date(d.timestamp).getTime() / 1000,
|
|
value: d.volume,
|
|
color: d.close >= d.open ? 'rgba(38, 166, 154, 0.5)' : 'rgba(239, 83, 80, 0.5)'
|
|
}));
|
|
|
|
volumeSeries.setData(volumeData);
|
|
}
|
|
|
|
// Add SMA if enabled
|
|
if (activeIndicators.sma) {
|
|
smaSeries = chart.addLineSeries({
|
|
color: '#2196F3',
|
|
lineWidth: 2,
|
|
title: 'SMA 20'
|
|
});
|
|
|
|
const smaData = calculateSMA(candleData, 20);
|
|
smaSeries.setData(smaData);
|
|
}
|
|
|
|
// Add EMA if enabled
|
|
if (activeIndicators.ema) {
|
|
emaSeries = chart.addLineSeries({
|
|
color: '#FF6D00',
|
|
lineWidth: 2,
|
|
title: 'EMA 20'
|
|
});
|
|
|
|
const emaData = calculateEMA(candleData, 20);
|
|
emaSeries.setData(emaData);
|
|
}
|
|
|
|
// Fit content
|
|
chart.timeScale().fitContent();
|
|
|
|
// Handle resize
|
|
window.addEventListener('resize', () => {
|
|
chart.applyOptions({
|
|
width: chartContainer.clientWidth,
|
|
height: chartContainer.clientHeight
|
|
});
|
|
});
|
|
}
|
|
|
|
// Bulk download modal
|
|
function showBulkDownloadModal() {
|
|
document.getElementById('bulkDownloadModal').style.display = 'block';
|
|
}
|
|
|
|
function closeBulkDownloadModal() {
|
|
document.getElementById('bulkDownloadModal').style.display = 'none';
|
|
}
|
|
|
|
// Updated bulk download function to support multiple symbols
|
|
async function startBulkDownload() {
|
|
const symbolSelect = document.getElementById('bulkSymbol');
|
|
const selectedSymbols = Array.from(symbolSelect.selectedOptions).map(opt => opt.value);
|
|
const startDate = document.getElementById('bulkStartDate').value;
|
|
let endDate = document.getElementById('bulkEndDate').value;
|
|
|
|
if (selectedSymbols.length === 0 || !startDate) {
|
|
showAlert('Please select at least one symbol and start date', 'error');
|
|
return;
|
|
}
|
|
|
|
// If no end date specified, use current date
|
|
if (!endDate) {
|
|
endDate = new Date().toISOString();
|
|
}
|
|
|
|
const intervals = Array.from(
|
|
document.querySelectorAll('#bulkDownloadModal input[type="checkbox"]:checked')
|
|
).map(cb => cb.value);
|
|
|
|
try {
|
|
showAlert('Starting bulk download...', 'info');
|
|
|
|
const response = await fetch('/api/bulk-download', {
|
|
method: 'POST',
|
|
headers: { 'Content-Type': 'application/json' },
|
|
body: JSON.stringify({
|
|
symbols: selectedSymbols,
|
|
start_date: startDate,
|
|
end_date: endDate,
|
|
intervals: intervals
|
|
})
|
|
});
|
|
|
|
const data = await response.json();
|
|
|
|
if (data.status === 'success') {
|
|
showAlert(data.message, 'success');
|
|
closeBulkDownloadModal();
|
|
// Show the download progress modal
|
|
setTimeout(showDownloadProgressModal, 500);
|
|
} else {
|
|
showAlert(data.message, 'error');
|
|
}
|
|
} catch (error) {
|
|
showAlert(`Error starting bulk download: ${error.message}`, 'error');
|
|
}
|
|
}
|
|
|
|
// Initialize date inputs with default times (00:00)
|
|
document.addEventListener('DOMContentLoaded', function() {
|
|
const bulkStartDate = document.getElementById('bulkStartDate');
|
|
const bulkEndDate = document.getElementById('bulkEndDate');
|
|
|
|
// Set default start date to beginning of 2020 at 00:00
|
|
if (bulkStartDate) {
|
|
bulkStartDate.value = '2020-01-01T00:00';
|
|
}
|
|
});
|
|
|
|
// Download Progress Modal Functions
|
|
function showDownloadProgressModal() {
|
|
const modal = document.getElementById('downloadProgressModal');
|
|
modal.style.display = 'block';
|
|
loadDownloadProgress();
|
|
|
|
// Auto-refresh every 2 seconds
|
|
if (!window.downloadProgressInterval) {
|
|
window.downloadProgressInterval = setInterval(loadDownloadProgress, 2000);
|
|
}
|
|
}
|
|
|
|
function closeDownloadProgressModal() {
|
|
const modal = document.getElementById('downloadProgressModal');
|
|
modal.style.display = 'none';
|
|
|
|
if (window.downloadProgressInterval) {
|
|
clearInterval(window.downloadProgressInterval);
|
|
window.downloadProgressInterval = null;
|
|
}
|
|
}
|
|
|
|
async function loadDownloadProgress() {
|
|
try {
|
|
const response = await fetch('/api/download-progress');
|
|
const data = await response.json();
|
|
|
|
if (data.status === 'success') {
|
|
displayDownloadProgress(data.downloads);
|
|
}
|
|
} catch (error) {
|
|
console.error('Error loading download progress:', error);
|
|
}
|
|
}
|
|
|
|
function displayDownloadProgress(downloads) {
|
|
const container = document.getElementById('downloadProgressList');
|
|
|
|
if (!downloads || Object.keys(downloads).length === 0) {
|
|
container.innerHTML = '<div style="text-align: center; padding: 40px; color: #a0a0a0;">No active downloads</div>';
|
|
return;
|
|
}
|
|
|
|
let html = '';
|
|
for (const [symbol, progress] of Object.entries(downloads)) {
|
|
const statusClass = progress.status === 'completed' ? 'status-completed' :
|
|
progress.status === 'error' ? 'status-error' : 'status-running';
|
|
const statusIcon = progress.status === 'completed' ? '✓' :
|
|
progress.status === 'error' ? '✗' : '⟳';
|
|
|
|
html += `
|
|
<div class="download-item">
|
|
<div class="download-header">
|
|
<span class="download-symbol">${symbol}</span>
|
|
<span class="download-status ${statusClass}">${statusIcon} ${progress.status}</span>
|
|
</div>
|
|
<div class="download-intervals">
|
|
`;
|
|
|
|
if (progress.intervals) {
|
|
for (const [interval, info] of Object.entries(progress.intervals)) {
|
|
const intervalStatus = info.status || 'pending';
|
|
const records = info.records || 0;
|
|
|
|
html += `
|
|
<div class="interval-progress">
|
|
<span class="interval-name">${interval}</span>
|
|
<span class="interval-status">${intervalStatus}</span>
|
|
<span class="interval-records">${records.toLocaleString()} records</span>
|
|
</div>
|
|
`;
|
|
}
|
|
}
|
|
|
|
if (progress.start_time) {
|
|
html += `<div class="download-time">Started: ${new Date(progress.start_time).toLocaleString()}</div>`;
|
|
}
|
|
|
|
if (progress.end_time) {
|
|
html += `<div class="download-time">Completed: ${new Date(progress.end_time).toLocaleString()}</div>`;
|
|
}
|
|
|
|
if (progress.error) {
|
|
html += `<div class="download-error">Error: ${progress.error}</div>`;
|
|
}
|
|
|
|
html += `
|
|
</div>
|
|
</div>
|
|
`;
|
|
}
|
|
|
|
container.innerHTML = html;
|
|
}
|
|
|
|
// Close modals on outside click
|
|
window.onclick = function(event) {
|
|
if (event.target.classList.contains('modal')) {
|
|
event.target.style.display = 'none';
|
|
}
|
|
};
|
|
</script>
|
|
</body>
|
|
</html>
|
|
"""
|