feat(dashboard): add paper/live toggle
- /api/live endpoint serves copybot_live_real.json (live bot feed) - Toggle button switches between paper (/api/feed) and live (/api/live) - Live mode shows red button label for visual distinction
This commit is contained in:
+14
-2
@@ -53,8 +53,9 @@ footer{text-align:center;color:var(--dim);font-size:12px;margin-top:30px}
|
||||
<h1>Polymarket 跟单 Bot · 实时</h1>
|
||||
<div class="sub">
|
||||
<span class="live-dot"></span><span id="status">连接中…</span>
|
||||
· 数据更新于 <span id="updated">—</span>
|
||||
· 数据更新于 <span id="updated">-</span>
|
||||
· 浏览器每 30 秒自动拉取
|
||||
· <button id="toggle-mode" onclick="toggleMode()" style="background:var(--line);color:var(--fg);border:1px solid var(--line);border-radius:4px;padding:3px 12px;cursor:pointer;font-size:12px;">PAPER</button>
|
||||
</div>
|
||||
|
||||
<div class="cards">
|
||||
@@ -102,8 +103,19 @@ footer{text-align:center;color:var(--dim);font-size:12px;margin-top:30px}
|
||||
</div>
|
||||
|
||||
<script>
|
||||
let currentMode = 'paper';
|
||||
function toggleMode() {
|
||||
currentMode = currentMode === 'paper' ? 'live' : 'paper';
|
||||
const btn = document.getElementById('toggle-mode');
|
||||
btn.textContent = currentMode.toUpperCase();
|
||||
btn.style.background = currentMode === 'live' ? '#3a1a1a' : 'var(--line)';
|
||||
btn.style.color = currentMode === 'live' ? 'var(--red)' : 'var(--fg)';
|
||||
render();
|
||||
}
|
||||
|
||||
async function fetchFeed() {
|
||||
const r = await fetch('/api/feed', {cache: 'no-store'});
|
||||
const endpoint = currentMode === 'live' ? '/api/live' : '/api/feed';
|
||||
const r = await fetch(endpoint, {cache: 'no-store'});
|
||||
if (!r.ok) throw new Error('HTTP ' + r.status);
|
||||
return await r.json();
|
||||
}
|
||||
|
||||
@@ -34,7 +34,10 @@ class Handler(http.server.SimpleHTTPRequestHandler):
|
||||
if self.path in ("/", "/bot.html"):
|
||||
self.path = "/bot_dashboard.html"
|
||||
elif self.path == "/api/feed":
|
||||
self._serve_json("copybot_live.json", "feed")
|
||||
self._serve_json("copybot_live.json", "paper feed")
|
||||
return
|
||||
elif self.path == "/api/live":
|
||||
self._serve_json("copybot_live_real.json", "live feed")
|
||||
return
|
||||
elif self.path == "/api/portfolio":
|
||||
self._serve_json("portfolio.json", "portfolio")
|
||||
|
||||
Reference in New Issue
Block a user