mirror of
https://github.com/NoFxAiOS/nofx.git
synced 2026-07-07 13:00:59 +08:00
- Candlestick chart + volume histogram - 8 trading pairs: BTC/ETH/SOL/BNB/XRP/DOGE/ADA/AVAX - 5 timeframes: 15m/1H/4H/1D/1W - Real-time price & 24h change display - Auto-refresh every 30s - Backend: /api/klines + /api/ticker (Binance futures API) - Dark trading terminal theme, responsive resize - Tab switching: Chat ↔ Chart
866 lines
24 KiB
HTML
866 lines
24 KiB
HTML
<!DOCTYPE html>
|
|
<html lang="zh">
|
|
<head>
|
|
<meta charset="UTF-8">
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
<title>NOFXi — AI Trading Agent</title>
|
|
<link rel="preconnect" href="https://fonts.googleapis.com">
|
|
<link href="https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700;800&family=JetBrains+Mono:wght@400;500&display=swap" rel="stylesheet">
|
|
<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; }
|
|
:root {
|
|
--bg: #09090b;
|
|
--bg2: #0f0f14;
|
|
--surface: #16161d;
|
|
--surface2: #1c1c27;
|
|
--border: #252530;
|
|
--border2: #2e2e3a;
|
|
--text: #f0f0f5;
|
|
--text2: #a0a0b0;
|
|
--text3: #666680;
|
|
--accent: #00e5a0;
|
|
--accent-dim: rgba(0,229,160,0.1);
|
|
--purple: #8b5cf6;
|
|
--purple-dim: rgba(139,92,246,0.1);
|
|
--blue: #3b82f6;
|
|
--red: #ef4444;
|
|
--green: #22c55e;
|
|
--orange: #f59e0b;
|
|
--radius: 12px;
|
|
--radius-sm: 8px;
|
|
--shadow: 0 4px 24px rgba(0,0,0,0.4);
|
|
}
|
|
body {
|
|
font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
|
|
background: var(--bg);
|
|
color: var(--text);
|
|
height: 100vh;
|
|
display: flex;
|
|
flex-direction: column;
|
|
overflow: hidden;
|
|
}
|
|
|
|
/* === Header === */
|
|
.header {
|
|
display: flex;
|
|
align-items: center;
|
|
justify-content: space-between;
|
|
padding: 12px 24px;
|
|
background: var(--bg2);
|
|
border-bottom: 1px solid var(--border);
|
|
backdrop-filter: blur(12px);
|
|
z-index: 10;
|
|
}
|
|
.header-left {
|
|
display: flex;
|
|
align-items: center;
|
|
gap: 16px;
|
|
}
|
|
.logo {
|
|
font-size: 22px;
|
|
font-weight: 800;
|
|
letter-spacing: -0.5px;
|
|
display: flex;
|
|
align-items: center;
|
|
gap: 8px;
|
|
}
|
|
.logo-icon {
|
|
width: 32px; height: 32px;
|
|
background: linear-gradient(135deg, var(--accent), var(--purple));
|
|
border-radius: 8px;
|
|
display: flex;
|
|
align-items: center;
|
|
justify-content: center;
|
|
font-size: 16px;
|
|
}
|
|
.logo span {
|
|
background: linear-gradient(135deg, var(--accent), var(--purple));
|
|
-webkit-background-clip: text;
|
|
-webkit-text-fill-color: transparent;
|
|
}
|
|
.nav-pills {
|
|
display: flex;
|
|
gap: 4px;
|
|
background: var(--surface);
|
|
border-radius: var(--radius);
|
|
padding: 3px;
|
|
}
|
|
.nav-pill {
|
|
padding: 6px 16px;
|
|
border-radius: var(--radius-sm);
|
|
font-size: 13px;
|
|
font-weight: 500;
|
|
color: var(--text3);
|
|
cursor: pointer;
|
|
transition: all 0.2s;
|
|
border: none;
|
|
background: none;
|
|
}
|
|
.nav-pill:hover { color: var(--text2); }
|
|
.nav-pill.active {
|
|
background: var(--surface2);
|
|
color: var(--text);
|
|
box-shadow: 0 1px 3px rgba(0,0,0,0.3);
|
|
}
|
|
.header-right {
|
|
display: flex;
|
|
align-items: center;
|
|
gap: 12px;
|
|
}
|
|
.status-badge {
|
|
display: flex;
|
|
align-items: center;
|
|
gap: 6px;
|
|
padding: 5px 12px;
|
|
background: rgba(34,197,94,0.1);
|
|
border: 1px solid rgba(34,197,94,0.2);
|
|
border-radius: 20px;
|
|
font-size: 12px;
|
|
font-weight: 500;
|
|
color: var(--green);
|
|
}
|
|
.status-badge.offline {
|
|
background: rgba(239,68,68,0.1);
|
|
border-color: rgba(239,68,68,0.2);
|
|
color: var(--red);
|
|
}
|
|
.status-dot {
|
|
width: 6px; height: 6px;
|
|
border-radius: 50%;
|
|
background: currentColor;
|
|
}
|
|
|
|
/* === Main Layout === */
|
|
.main {
|
|
flex: 1;
|
|
display: flex;
|
|
overflow: hidden;
|
|
}
|
|
|
|
/* === Sidebar === */
|
|
.sidebar {
|
|
width: 280px;
|
|
background: var(--bg2);
|
|
border-right: 1px solid var(--border);
|
|
display: flex;
|
|
flex-direction: column;
|
|
overflow-y: auto;
|
|
}
|
|
.sidebar-section {
|
|
padding: 16px;
|
|
border-bottom: 1px solid var(--border);
|
|
}
|
|
.sidebar-title {
|
|
font-size: 11px;
|
|
font-weight: 600;
|
|
text-transform: uppercase;
|
|
letter-spacing: 1.2px;
|
|
color: var(--text3);
|
|
margin-bottom: 10px;
|
|
}
|
|
.action-grid {
|
|
display: grid;
|
|
grid-template-columns: 1fr 1fr;
|
|
gap: 6px;
|
|
}
|
|
.action-btn {
|
|
display: flex;
|
|
flex-direction: column;
|
|
align-items: center;
|
|
gap: 4px;
|
|
padding: 12px 8px;
|
|
background: var(--surface);
|
|
border: 1px solid var(--border);
|
|
border-radius: var(--radius-sm);
|
|
color: var(--text2);
|
|
font-size: 11px;
|
|
font-weight: 500;
|
|
cursor: pointer;
|
|
transition: all 0.15s;
|
|
}
|
|
.action-btn:hover {
|
|
background: var(--surface2);
|
|
border-color: var(--border2);
|
|
color: var(--text);
|
|
transform: translateY(-1px);
|
|
}
|
|
.action-btn .emoji { font-size: 20px; }
|
|
.action-list {
|
|
display: flex;
|
|
flex-direction: column;
|
|
gap: 2px;
|
|
}
|
|
.action-item {
|
|
display: flex;
|
|
align-items: center;
|
|
gap: 10px;
|
|
padding: 8px 10px;
|
|
border-radius: var(--radius-sm);
|
|
color: var(--text2);
|
|
font-size: 13px;
|
|
cursor: pointer;
|
|
transition: all 0.15s;
|
|
border: none;
|
|
background: none;
|
|
width: 100%;
|
|
text-align: left;
|
|
}
|
|
.action-item:hover {
|
|
background: var(--surface);
|
|
color: var(--text);
|
|
}
|
|
.action-item .icon {
|
|
width: 28px; height: 28px;
|
|
border-radius: 6px;
|
|
display: flex;
|
|
align-items: center;
|
|
justify-content: center;
|
|
font-size: 14px;
|
|
flex-shrink: 0;
|
|
}
|
|
.action-item .icon.green { background: rgba(34,197,94,0.1); }
|
|
.action-item .icon.blue { background: rgba(59,130,246,0.1); }
|
|
.action-item .icon.purple { background: rgba(139,92,246,0.1); }
|
|
.action-item .icon.orange { background: rgba(245,158,11,0.1); }
|
|
|
|
/* === Chat === */
|
|
.chat-area {
|
|
flex: 1;
|
|
display: flex;
|
|
flex-direction: column;
|
|
background: var(--bg);
|
|
}
|
|
.messages {
|
|
flex: 1;
|
|
overflow-y: auto;
|
|
padding: 24px 20px;
|
|
scroll-behavior: smooth;
|
|
}
|
|
.messages::-webkit-scrollbar { width: 4px; }
|
|
.messages::-webkit-scrollbar-thumb { background: var(--border); border-radius: 4px; }
|
|
|
|
.msg {
|
|
display: flex;
|
|
gap: 12px;
|
|
margin-bottom: 20px;
|
|
animation: fadeIn 0.3s ease;
|
|
}
|
|
.msg.user { flex-direction: row-reverse; }
|
|
@keyframes fadeIn {
|
|
from { opacity: 0; transform: translateY(8px); }
|
|
to { opacity: 1; transform: translateY(0); }
|
|
}
|
|
.msg-avatar {
|
|
width: 36px; height: 36px;
|
|
border-radius: 10px;
|
|
display: flex;
|
|
align-items: center;
|
|
justify-content: center;
|
|
font-size: 18px;
|
|
flex-shrink: 0;
|
|
}
|
|
.msg.bot .msg-avatar {
|
|
background: linear-gradient(135deg, var(--accent-dim), var(--purple-dim));
|
|
border: 1px solid var(--border);
|
|
}
|
|
.msg.user .msg-avatar {
|
|
background: var(--purple-dim);
|
|
border: 1px solid rgba(139,92,246,0.2);
|
|
}
|
|
.msg-body { max-width: 680px; }
|
|
.msg-name {
|
|
font-size: 12px;
|
|
font-weight: 600;
|
|
margin-bottom: 4px;
|
|
color: var(--text3);
|
|
}
|
|
.msg.user .msg-name { text-align: right; }
|
|
.msg-bubble {
|
|
padding: 14px 18px;
|
|
border-radius: 16px;
|
|
font-size: 14px;
|
|
line-height: 1.7;
|
|
white-space: pre-wrap;
|
|
word-break: break-word;
|
|
}
|
|
.msg.bot .msg-bubble {
|
|
background: var(--surface);
|
|
border: 1px solid var(--border);
|
|
border-top-left-radius: 4px;
|
|
color: var(--text);
|
|
}
|
|
.msg.user .msg-bubble {
|
|
background: linear-gradient(135deg, var(--purple), #6d28d9);
|
|
border-top-right-radius: 4px;
|
|
color: #fff;
|
|
}
|
|
.msg-time {
|
|
font-size: 11px;
|
|
color: var(--text3);
|
|
margin-top: 4px;
|
|
}
|
|
.msg.user .msg-time { text-align: right; }
|
|
|
|
/* Typing indicator */
|
|
.typing-indicator {
|
|
display: none;
|
|
padding: 0 24px 12px;
|
|
color: var(--text3);
|
|
font-size: 13px;
|
|
align-items: center;
|
|
gap: 8px;
|
|
}
|
|
.typing-indicator.active { display: flex; }
|
|
.typing-dots {
|
|
display: flex;
|
|
gap: 3px;
|
|
}
|
|
.typing-dots span {
|
|
width: 5px; height: 5px;
|
|
background: var(--accent);
|
|
border-radius: 50%;
|
|
animation: bounce 1.4s infinite;
|
|
}
|
|
.typing-dots span:nth-child(2) { animation-delay: 0.2s; }
|
|
.typing-dots span:nth-child(3) { animation-delay: 0.4s; }
|
|
@keyframes bounce {
|
|
0%, 60%, 100% { transform: translateY(0); opacity: 0.4; }
|
|
30% { transform: translateY(-6px); opacity: 1; }
|
|
}
|
|
|
|
/* === Input === */
|
|
.input-bar {
|
|
padding: 16px 20px 20px;
|
|
background: var(--bg2);
|
|
border-top: 1px solid var(--border);
|
|
}
|
|
.input-container {
|
|
display: flex;
|
|
align-items: center;
|
|
gap: 10px;
|
|
background: var(--surface);
|
|
border: 1px solid var(--border);
|
|
border-radius: 16px;
|
|
padding: 4px 4px 4px 18px;
|
|
transition: border-color 0.2s;
|
|
max-width: 900px;
|
|
margin: 0 auto;
|
|
}
|
|
.input-container:focus-within {
|
|
border-color: var(--accent);
|
|
box-shadow: 0 0 0 3px var(--accent-dim);
|
|
}
|
|
.input-container input {
|
|
flex: 1;
|
|
background: none;
|
|
border: none;
|
|
color: var(--text);
|
|
font-size: 14px;
|
|
font-family: inherit;
|
|
outline: none;
|
|
padding: 10px 0;
|
|
}
|
|
.input-container input::placeholder { color: var(--text3); }
|
|
.send-btn {
|
|
width: 40px; height: 40px;
|
|
border-radius: 12px;
|
|
border: none;
|
|
background: linear-gradient(135deg, var(--accent), #00c896);
|
|
color: #000;
|
|
font-size: 18px;
|
|
cursor: pointer;
|
|
display: flex;
|
|
align-items: center;
|
|
justify-content: center;
|
|
transition: all 0.15s;
|
|
flex-shrink: 0;
|
|
}
|
|
.send-btn:hover { transform: scale(1.05); box-shadow: 0 2px 12px rgba(0,229,160,0.3); }
|
|
.send-btn:disabled { opacity: 0.4; cursor: not-allowed; transform: none; }
|
|
.input-hint {
|
|
font-size: 11px;
|
|
color: var(--text3);
|
|
text-align: center;
|
|
margin-top: 8px;
|
|
}
|
|
.input-hint kbd {
|
|
background: var(--surface);
|
|
padding: 1px 5px;
|
|
border-radius: 4px;
|
|
border: 1px solid var(--border);
|
|
font-family: 'JetBrains Mono', monospace;
|
|
font-size: 10px;
|
|
}
|
|
|
|
/* === Chart Panel === */
|
|
.chart-panel {
|
|
flex: 1;
|
|
display: none;
|
|
flex-direction: column;
|
|
background: var(--bg);
|
|
}
|
|
.chart-panel.active { display: flex; }
|
|
.chat-area.hidden { display: none; }
|
|
.chart-header {
|
|
display: flex;
|
|
align-items: center;
|
|
justify-content: space-between;
|
|
padding: 12px 20px;
|
|
border-bottom: 1px solid var(--border);
|
|
background: var(--bg2);
|
|
}
|
|
.chart-symbol-group {
|
|
display: flex;
|
|
align-items: center;
|
|
gap: 16px;
|
|
}
|
|
.chart-symbol {
|
|
font-size: 18px;
|
|
font-weight: 700;
|
|
letter-spacing: -0.3px;
|
|
}
|
|
.chart-price {
|
|
font-size: 24px;
|
|
font-weight: 700;
|
|
font-family: 'JetBrains Mono', monospace;
|
|
}
|
|
.chart-price.up { color: var(--green); }
|
|
.chart-price.down { color: var(--red); }
|
|
.chart-change {
|
|
font-size: 13px;
|
|
font-weight: 500;
|
|
padding: 3px 8px;
|
|
border-radius: 6px;
|
|
}
|
|
.chart-change.up { color: var(--green); background: rgba(34,197,94,0.1); }
|
|
.chart-change.down { color: var(--red); background: rgba(239,68,68,0.1); }
|
|
.chart-controls {
|
|
display: flex;
|
|
gap: 4px;
|
|
}
|
|
.tf-btn {
|
|
padding: 5px 12px;
|
|
border: 1px solid var(--border);
|
|
border-radius: 6px;
|
|
background: none;
|
|
color: var(--text3);
|
|
font-size: 12px;
|
|
font-weight: 500;
|
|
cursor: pointer;
|
|
transition: all 0.15s;
|
|
font-family: 'JetBrains Mono', monospace;
|
|
}
|
|
.tf-btn:hover { color: var(--text); border-color: var(--border2); }
|
|
.tf-btn.active { background: var(--accent); color: #000; border-color: var(--accent); }
|
|
.symbol-select {
|
|
padding: 5px 10px;
|
|
border: 1px solid var(--border);
|
|
border-radius: 6px;
|
|
background: var(--surface);
|
|
color: var(--text);
|
|
font-size: 12px;
|
|
font-family: 'JetBrains Mono', monospace;
|
|
cursor: pointer;
|
|
outline: none;
|
|
}
|
|
.chart-container {
|
|
flex: 1;
|
|
position: relative;
|
|
}
|
|
.chart-volume-label {
|
|
position: absolute;
|
|
top: 8px;
|
|
right: 12px;
|
|
font-size: 11px;
|
|
color: var(--text3);
|
|
z-index: 5;
|
|
pointer-events: none;
|
|
}
|
|
|
|
/* === Mobile === */
|
|
@media (max-width: 768px) {
|
|
.sidebar { display: none; }
|
|
.nav-pills { display: none; }
|
|
.header { padding: 10px 16px; }
|
|
.messages { padding: 16px 12px; }
|
|
.input-bar { padding: 10px 12px 14px; }
|
|
.msg-body { max-width: 90%; }
|
|
}
|
|
</style>
|
|
</head>
|
|
<body>
|
|
|
|
<div class="header">
|
|
<div class="header-left">
|
|
<div class="logo">
|
|
<div class="logo-icon">⚡</div>
|
|
<span>NOFXi</span>
|
|
</div>
|
|
<div class="nav-pills">
|
|
<button class="nav-pill active" onclick="switchTab('chat')">Chat</button>
|
|
<button class="nav-pill" onclick="switchTab('chart')">Chart</button>
|
|
<button class="nav-pill" onclick="send('/positions');switchTab('chat')">Positions</button>
|
|
</div>
|
|
</div>
|
|
<div class="header-right">
|
|
<div class="status-badge" id="statusBadge">
|
|
<div class="status-dot"></div>
|
|
<span id="statusText">Connecting...</span>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<div class="main">
|
|
<div class="sidebar">
|
|
<div class="sidebar-section">
|
|
<div class="sidebar-title">Quick Trade</div>
|
|
<div class="action-grid">
|
|
<button class="action-btn" onclick="send('/analyze BTC')">
|
|
<span class="emoji">₿</span>BTC Analysis
|
|
</button>
|
|
<button class="action-btn" onclick="send('/analyze ETH')">
|
|
<span class="emoji">Ξ</span>ETH Analysis
|
|
</button>
|
|
<button class="action-btn" onclick="send('/analyze SOL')">
|
|
<span class="emoji">◎</span>SOL Analysis
|
|
</button>
|
|
<button class="action-btn" onclick="send('/price BTCUSDT')">
|
|
<span class="emoji">💲</span>BTC Price
|
|
</button>
|
|
</div>
|
|
</div>
|
|
|
|
<div class="sidebar-section">
|
|
<div class="sidebar-title">Portfolio</div>
|
|
<div class="action-list">
|
|
<button class="action-item" onclick="send('/positions')">
|
|
<div class="icon green">💼</div>
|
|
<span>Open Positions</span>
|
|
</button>
|
|
<button class="action-item" onclick="send('/balance')">
|
|
<div class="icon blue">💰</div>
|
|
<span>Account Balance</span>
|
|
</button>
|
|
<button class="action-item" onclick="send('/pnl')">
|
|
<div class="icon purple">📊</div>
|
|
<span>P/L History</span>
|
|
</button>
|
|
</div>
|
|
</div>
|
|
|
|
<div class="sidebar-section">
|
|
<div class="sidebar-title">Monitor</div>
|
|
<div class="action-list">
|
|
<button class="action-item" onclick="send('/watch BTCUSDT')">
|
|
<div class="icon orange">👁️</div>
|
|
<span>Watch BTC</span>
|
|
</button>
|
|
<button class="action-item" onclick="send('/watch ETHUSDT')">
|
|
<div class="icon orange">👁️</div>
|
|
<span>Watch ETH</span>
|
|
</button>
|
|
<button class="action-item" onclick="send('/watch')">
|
|
<div class="icon blue">📋</div>
|
|
<span>Watchlist</span>
|
|
</button>
|
|
</div>
|
|
</div>
|
|
|
|
<div class="sidebar-section">
|
|
<div class="sidebar-title">Strategy</div>
|
|
<div class="action-list">
|
|
<button class="action-item" onclick="send('/strategy list')">
|
|
<div class="icon purple">🤖</div>
|
|
<span>Active Strategies</span>
|
|
</button>
|
|
<button class="action-item" onclick="send('/strategy start BTC 1h')">
|
|
<div class="icon green">🚀</div>
|
|
<span>Start BTC Strategy</span>
|
|
</button>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<div class="chart-panel" id="chartPanel">
|
|
<div class="chart-header">
|
|
<div class="chart-symbol-group">
|
|
<select class="symbol-select" id="symbolSelect" onchange="loadChart()">
|
|
<option value="BTCUSDT">BTC/USDT</option>
|
|
<option value="ETHUSDT">ETH/USDT</option>
|
|
<option value="SOLUSDT">SOL/USDT</option>
|
|
<option value="BNBUSDT">BNB/USDT</option>
|
|
<option value="XRPUSDT">XRP/USDT</option>
|
|
<option value="DOGEUSDT">DOGE/USDT</option>
|
|
<option value="ADAUSDT">ADA/USDT</option>
|
|
<option value="AVAXUSDT">AVAX/USDT</option>
|
|
</select>
|
|
<span class="chart-price" id="chartPrice">--</span>
|
|
<span class="chart-change" id="chartChange">--</span>
|
|
</div>
|
|
<div class="chart-controls">
|
|
<button class="tf-btn" onclick="setTF('15m')">15m</button>
|
|
<button class="tf-btn active" onclick="setTF('1h')">1H</button>
|
|
<button class="tf-btn" onclick="setTF('4h')">4H</button>
|
|
<button class="tf-btn" onclick="setTF('1d')">1D</button>
|
|
<button class="tf-btn" onclick="setTF('1w')">1W</button>
|
|
</div>
|
|
</div>
|
|
<div class="chart-container" id="chartContainer"></div>
|
|
</div>
|
|
|
|
<div class="chat-area" id="chatPanel">
|
|
<div class="messages" id="messages">
|
|
<div class="msg bot">
|
|
<div class="msg-avatar">⚡</div>
|
|
<div class="msg-body">
|
|
<div class="msg-name">NOFXi</div>
|
|
<div class="msg-bubble">Hey! 👋 I'm NOFXi, your AI trading agent.
|
|
|
|
I can analyze markets, monitor prices, manage trades, and run automated strategies. Just ask me anything — in English or 中文.
|
|
|
|
Try: "分析一下BTC" or use the quick actions on the left.</div>
|
|
<div class="msg-time">Just now</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<div class="typing-indicator" id="typing">
|
|
<div class="typing-dots"><span></span><span></span><span></span></div>
|
|
NOFXi is thinking...
|
|
</div>
|
|
|
|
<div class="input-bar">
|
|
<div class="input-container">
|
|
<input type="text" id="input" placeholder="Ask NOFXi anything..."
|
|
onkeydown="if(event.key==='Enter'&&!event.shiftKey){event.preventDefault();send()}"
|
|
autocomplete="off">
|
|
<button class="send-btn" id="sendBtn" onclick="send()">➤</button>
|
|
</div>
|
|
<div class="input-hint">
|
|
<kbd>Enter</kbd> to send · Try: /help, /analyze BTC, /buy ETH 0.1 2x
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<script>
|
|
const API = window.location.origin;
|
|
const messagesEl = document.getElementById('messages');
|
|
const inputEl = document.getElementById('input');
|
|
const typingEl = document.getElementById('typing');
|
|
const sendBtn = document.getElementById('sendBtn');
|
|
const statusBadge = document.getElementById('statusBadge');
|
|
const statusTextEl = document.getElementById('statusText');
|
|
|
|
async function checkHealth() {
|
|
try {
|
|
const r = await fetch(API + '/health');
|
|
const d = await r.json();
|
|
statusBadge.classList.remove('offline');
|
|
statusTextEl.textContent = 'Online';
|
|
} catch {
|
|
statusBadge.classList.add('offline');
|
|
statusTextEl.textContent = 'Offline';
|
|
}
|
|
}
|
|
checkHealth();
|
|
setInterval(checkHealth, 30000);
|
|
|
|
function timeNow() {
|
|
return new Date().toLocaleTimeString('zh-CN', { hour: '2-digit', minute: '2-digit' });
|
|
}
|
|
|
|
function addMsg(role, text) {
|
|
const div = document.createElement('div');
|
|
const isUser = role === 'user';
|
|
div.className = 'msg ' + (isUser ? 'user' : 'bot');
|
|
|
|
const avatar = isUser ? '👤' : '⚡';
|
|
const name = isUser ? 'You' : 'NOFXi';
|
|
|
|
div.innerHTML = `
|
|
<div class="msg-avatar">${avatar}</div>
|
|
<div class="msg-body">
|
|
<div class="msg-name">${name}</div>
|
|
<div class="msg-bubble">${escHtml(text)}</div>
|
|
<div class="msg-time">${timeNow()}</div>
|
|
</div>`;
|
|
|
|
messagesEl.appendChild(div);
|
|
messagesEl.scrollTop = messagesEl.scrollHeight;
|
|
}
|
|
|
|
function escHtml(t) {
|
|
const d = document.createElement('div');
|
|
d.textContent = t;
|
|
return d.innerHTML;
|
|
}
|
|
|
|
async function send(text) {
|
|
if (!text) {
|
|
text = inputEl.value.trim();
|
|
if (!text) return;
|
|
inputEl.value = '';
|
|
}
|
|
|
|
addMsg('user', text);
|
|
typingEl.classList.add('active');
|
|
sendBtn.disabled = true;
|
|
inputEl.focus();
|
|
|
|
try {
|
|
const r = await fetch(API + '/api/chat', {
|
|
method: 'POST',
|
|
headers: { 'Content-Type': 'application/json' },
|
|
body: JSON.stringify({ message: text, user_id: 1 })
|
|
});
|
|
const d = await r.json();
|
|
addMsg('bot', d.response || d.error || 'No response');
|
|
} catch (e) {
|
|
addMsg('bot', '⚠️ Connection error: ' + e.message);
|
|
}
|
|
|
|
typingEl.classList.remove('active');
|
|
sendBtn.disabled = false;
|
|
inputEl.focus();
|
|
}
|
|
|
|
inputEl.focus();
|
|
|
|
// === Chart ===
|
|
let chart = null;
|
|
let candleSeries = null;
|
|
let volumeSeries = null;
|
|
let currentTF = '1h';
|
|
let chartRefreshTimer = null;
|
|
|
|
function switchTab(tab) {
|
|
document.querySelectorAll('.nav-pill').forEach((p,i) => {
|
|
p.classList.toggle('active', (tab==='chat'&&i===0)||(tab==='chart'&&i===1));
|
|
});
|
|
const chatPanel = document.getElementById('chatPanel');
|
|
const chartPanel = document.getElementById('chartPanel');
|
|
if (tab === 'chart') {
|
|
chatPanel.classList.add('hidden');
|
|
chartPanel.classList.add('active');
|
|
if (!chart) initChart();
|
|
loadChart();
|
|
} else {
|
|
chatPanel.classList.remove('hidden');
|
|
chartPanel.classList.remove('active');
|
|
if (chartRefreshTimer) clearInterval(chartRefreshTimer);
|
|
}
|
|
}
|
|
|
|
function initChart() {
|
|
const container = document.getElementById('chartContainer');
|
|
chart = LightweightCharts.createChart(container, {
|
|
width: container.clientWidth,
|
|
height: container.clientHeight,
|
|
layout: {
|
|
background: { color: '#09090b' },
|
|
textColor: '#666680',
|
|
fontFamily: "'JetBrains Mono', monospace",
|
|
fontSize: 11,
|
|
},
|
|
grid: {
|
|
vertLines: { color: '#1a1a24' },
|
|
horzLines: { color: '#1a1a24' },
|
|
},
|
|
crosshair: {
|
|
mode: LightweightCharts.CrosshairMode.Normal,
|
|
vertLine: { color: '#333345', labelBackgroundColor: '#252530' },
|
|
horzLine: { color: '#333345', labelBackgroundColor: '#252530' },
|
|
},
|
|
rightPriceScale: {
|
|
borderColor: '#252530',
|
|
scaleMargins: { top: 0.1, bottom: 0.25 },
|
|
},
|
|
timeScale: {
|
|
borderColor: '#252530',
|
|
timeVisible: true,
|
|
secondsVisible: false,
|
|
},
|
|
});
|
|
|
|
candleSeries = chart.addCandlestickSeries({
|
|
upColor: '#22c55e',
|
|
downColor: '#ef4444',
|
|
borderUpColor: '#22c55e',
|
|
borderDownColor: '#ef4444',
|
|
wickUpColor: '#22c55e',
|
|
wickDownColor: '#ef4444',
|
|
});
|
|
|
|
volumeSeries = chart.addHistogramSeries({
|
|
priceFormat: { type: 'volume' },
|
|
priceScaleId: 'volume',
|
|
});
|
|
chart.priceScale('volume').applyOptions({
|
|
scaleMargins: { top: 0.8, bottom: 0 },
|
|
});
|
|
|
|
new ResizeObserver(() => {
|
|
chart.applyOptions({ width: container.clientWidth, height: container.clientHeight });
|
|
}).observe(container);
|
|
}
|
|
|
|
function setTF(tf) {
|
|
currentTF = tf;
|
|
document.querySelectorAll('.tf-btn').forEach(b => {
|
|
b.classList.toggle('active', b.textContent.toLowerCase() === tf.toLowerCase() || b.textContent === tf.toUpperCase());
|
|
});
|
|
loadChart();
|
|
}
|
|
|
|
async function loadChart() {
|
|
const symbol = document.getElementById('symbolSelect').value;
|
|
try {
|
|
const [klineRes, tickerRes] = await Promise.all([
|
|
fetch(`${API}/api/klines?symbol=${symbol}&interval=${currentTF}&limit=300`),
|
|
fetch(`${API}/api/ticker?symbol=${symbol}`)
|
|
]);
|
|
const klines = await klineRes.json();
|
|
const ticker = await tickerRes.json();
|
|
|
|
if (klines && klines.length > 0) {
|
|
candleSeries.setData(klines.map(k => ({
|
|
time: k.time,
|
|
open: k.open,
|
|
high: k.high,
|
|
low: k.low,
|
|
close: k.close,
|
|
})));
|
|
volumeSeries.setData(klines.map(k => ({
|
|
time: k.time,
|
|
value: k.volume,
|
|
color: k.close >= k.open ? 'rgba(34,197,94,0.3)' : 'rgba(239,68,68,0.3)',
|
|
})));
|
|
}
|
|
|
|
// Update price display
|
|
if (ticker && ticker.lastPrice) {
|
|
const price = parseFloat(ticker.lastPrice);
|
|
const change = parseFloat(ticker.priceChangePercent);
|
|
const priceEl = document.getElementById('chartPrice');
|
|
const changeEl = document.getElementById('chartChange');
|
|
|
|
priceEl.textContent = '$' + price.toLocaleString('en-US', {minimumFractionDigits: 2, maximumFractionDigits: price > 100 ? 2 : 4});
|
|
priceEl.className = 'chart-price ' + (change >= 0 ? 'up' : 'down');
|
|
|
|
changeEl.textContent = (change >= 0 ? '+' : '') + change.toFixed(2) + '%';
|
|
changeEl.className = 'chart-change ' + (change >= 0 ? 'up' : 'down');
|
|
}
|
|
} catch (e) {
|
|
console.error('Load chart error:', e);
|
|
}
|
|
|
|
// Auto refresh every 30s
|
|
if (chartRefreshTimer) clearInterval(chartRefreshTimer);
|
|
chartRefreshTimer = setInterval(loadChart, 30000);
|
|
}
|
|
</script>
|
|
</body>
|
|
</html>
|