Ver Fonte

feat(仪表盘): 添加标记价格显示切换功能

在价格对比图和价格差异图中添加复选框,允许用户切换显示标记价格
调整数据收集间隔从200ms改为300ms,并移除不再使用的API和函数
skyfffire há 1 semana atrás
pai
commit
235041f8d5
2 ficheiros alterados com 42 adições e 64 exclusões
  1. 39 3
      src/dashboard/static/index.html
  2. 3 61
      src/record/market_data_recorder.py

+ 39 - 3
src/dashboard/static/index.html

@@ -371,6 +371,10 @@
                         <div class="chart-container">
                     <h3>价格对比图 
                         <button class="btn" style="float: right; padding: 8px 16px; font-size: 0.8em; margin-top: -5px;" onclick="resetPriceChartZoom()">重置缩放</button>
+                        <label style="float: right; margin-right: 10px; font-size: 0.8em; margin-top: 2px;">
+                            <input type="checkbox" id="showMarkPrices" onchange="toggleMarkPrices()" style="margin-right: 5px;">
+                            显示标记价格
+                        </label>
                         <span style="float: right; margin-right: 10px; font-size: 0.8em; color: #666; margin-top: 2px;">💡 拖拽框选区域可放大</span>
                     </h3>
                     <div class="chart-wrapper">
@@ -381,6 +385,10 @@
                 <div class="chart-container">
                     <h3>价格差异图
                         <button class="btn" style="float: right; padding: 8px 16px; font-size: 0.8em; margin-top: -5px;" onclick="resetDiffChartZoom()">重置缩放</button>
+                        <label style="float: right; margin-right: 10px; font-size: 0.8em; margin-top: 2px;">
+                            <input type="checkbox" id="showMarkPriceDiff" onchange="toggleMarkPriceDiff()" style="margin-right: 5px;">
+                            显示标记价格差
+                        </label>
                         <span style="float: right; margin-right: 10px; font-size: 0.8em; color: #666; margin-top: 2px;">💡 拖拽框选区域可放大</span>
                     </h3>
                     <div class="chart-wrapper">
@@ -647,7 +655,8 @@
                             borderColor: '#ff6384',
                             backgroundColor: 'rgba(255, 99, 132, 0.1)',
                             tension: 0.1,
-                            pointRadius: 0
+                            pointRadius: 0,
+                            hidden: true // 默认隐藏标记价格
                         },
                         {
                             label: 'Lighter 标记价格',
@@ -655,7 +664,8 @@
                             borderColor: '#36a2eb',
                             backgroundColor: 'rgba(54, 162, 235, 0.1)',
                             tension: 0.1,
-                            pointRadius: 0
+                            pointRadius: 0,
+                            hidden: true // 默认隐藏标记价格
                         },
                         {
                             label: 'Binance 最新价格',
@@ -786,7 +796,8 @@
                             borderColor: '#ffce56',
                             backgroundColor: 'rgba(255, 206, 86, 0.1)',
                             tension: 0.1,
-                            pointRadius: 0
+                            pointRadius: 0,
+                            hidden: true // 默认隐藏标记价格差
                         },
                         {
                             label: '价格差 (bps)',
@@ -994,6 +1005,31 @@
             
             setTimeout(() => { isSync = false; }, 100);
         }
+
+        // 切换标记价格显示的函数
+        function toggleMarkPrices() {
+            const checkbox = document.getElementById('showMarkPrices');
+            const isVisible = checkbox.checked;
+            
+            if (priceChart) {
+                // 切换 Binance 标记价格 (索引 0)
+                priceChart.setDatasetVisibility(0, isVisible);
+                // 切换 Lighter 标记价格 (索引 1)
+                priceChart.setDatasetVisibility(1, isVisible);
+                priceChart.update();
+            }
+        }
+
+        function toggleMarkPriceDiff() {
+            const checkbox = document.getElementById('showMarkPriceDiff');
+            const isVisible = checkbox.checked;
+            
+            if (diffChart) {
+                // 切换标记价格差 (索引 0)
+                diffChart.setDatasetVisibility(0, isVisible);
+                diffChart.update();
+            }
+        }
     </script>
 </body>
 </html>

+ 3 - 61
src/record/market_data_recorder.py

@@ -38,7 +38,6 @@ logger = logging.getLogger("market_data_recorder")
 LIGHTER_API_URL = "https://mainnet.zklighter.elliot.ai/api/v1/exchangeStats"
 LIGHTER_ORDERBOOKS_URL = "https://mainnet.zklighter.elliot.ai/api/v1/orderBooks"
 LIGHTER_WEBSOCKET_URL = "wss://mainnet.zklighter.elliot.ai/stream"
-BINANCE_API_URL = "https://fapi.binance.com/fapi/v2/ticker/price"
 BINANCE_PREMIUM_INDEX_URL = "https://fapi.binance.com/fapi/v1/premiumIndex"
 BINANCE_TICKER_PRICE_URL = "https://fapi.binance.com/fapi/v2/ticker/price"
 
@@ -86,42 +85,6 @@ async def fetch_lighter_orderbooks(session):
         return None
 
 
-async def fetch_lighter_data(session):
-    """从Lighter交易所获取行情数据"""
-    try:
-        # 设置代理参数
-        proxy = 'http://' + PROXY_ADDRESS if PROXY_ADDRESS else None
-        async with session.get(LIGHTER_API_URL, proxy=proxy) as response:
-            if response.status == 200:
-                data = await response.json()
-                # logger.info(f"成功获取Lighter数据,包含 {len(data.get('order_book_stats', []))} 个交易对")
-                return data
-            else:
-                logger.error(f"获取Lighter数据失败: HTTP {response.status}")
-                return None
-    except Exception as e:
-        logger.error(f"获取Lighter数据时出错: {str(e)}")
-        return None
-
-
-async def fetch_binance_data(session):
-    """从Binance交易所获取行情数据"""
-    try:
-        # 设置代理参数
-        proxy = 'http://' + PROXY_ADDRESS if PROXY_ADDRESS else None
-        async with session.get(BINANCE_API_URL, proxy=proxy) as response:
-            if response.status == 200:
-                data = await response.json()
-                # logger.info(f"成功获取Binance数据,包含 {len(data)} 个交易对")
-                return data
-            else:
-                logger.error(f"获取Binance数据失败: HTTP {response.status}")
-                return None
-    except Exception as e:
-        logger.error(f"获取Binance数据时出错: {str(e)}")
-        return None
-
-
 async def fetch_binance_premium_index(session):
     """从Binance获取标记价格数据"""
     try:
@@ -155,7 +118,7 @@ async def fetch_binance_ticker_price(session):
 
 
 async def handle_binance_data_collection():
-    """处理Binance数据收集的主循环,每200ms请求一次"""
+    """处理Binance数据收集的主循环,每300ms请求一次"""
     logger.info("开始Binance数据收集任务")
     
     while True:
@@ -184,35 +147,14 @@ async def handle_binance_data_collection():
                         if symbol and price:
                             binance_data_cache['latest_prices'][symbol] = float(price)
                 
-                # 每200ms请求一次
-                await asyncio.sleep(0.2)
+                # 每300ms请求一次
+                await asyncio.sleep(0.3)
                 
         except Exception as e:
             logger.error(f"Binance数据收集出错: {str(e)}")
             await asyncio.sleep(1)  # 出错时等待1秒再重试
 
 
-async def fetch_all_data():
-    """同时从两个交易所获取数据"""
-    # 如果设置了代理,则使用代理
-    # if PROXY_ADDRESS:
-    #     logger.info(f"使用代理: {PROXY_ADDRESS}")
-    
-    # 创建会话时设置代理
-    connector = None
-    if PROXY_ADDRESS:
-        connector = aiohttp.TCPConnector(ssl=False)
-        
-    async with aiohttp.ClientSession(connector=connector) as session:
-        lighter_task = asyncio.create_task(fetch_lighter_data(session))
-        binance_task = asyncio.create_task(fetch_binance_data(session))
-        
-        # 等待两个任务完成
-        lighter_data, binance_data = await asyncio.gather(lighter_task, binance_task)
-        
-        return lighter_data, binance_data
-
-
 def update_market_id_mapping(orderbooks_data):
     """更新market_id到symbol的映射"""
     global market_id_to_symbol