소스 검색

优化事件标记显示:根据event_type而非side确定方向,调整符号大小

skyfffire 14 시간 전
부모
커밋
6ed2a0adb9
2개의 변경된 파일30개의 추가작업 그리고 34개의 파일을 삭제
  1. 1 0
      src/leadlag/strategy.py
  2. 29 34
      src/leadlag/templates/dashboard.html

+ 1 - 0
src/leadlag/strategy.py

@@ -10,6 +10,7 @@ from enum import Enum
 import os
 import lighter
 import time
+import json
 from database import TradingDatabase
 
 

+ 29 - 34
src/leadlag/templates/dashboard.html

@@ -555,27 +555,29 @@
                 console.log('   准备添加', tradingEventsData.length, '个事件标记到价格图表');
                 tradingEventsData.forEach(event => {
                     const timestamp = event.timestamp * 1000;
-                    const side = event.side;
                     const eventType = event.event_type;
 
                     let color, symbol, symbolSize, label, symbolRotate = 0;
 
-                    if (side === 'long') {
+                    // 根据 event_type 确定方向
+                    // open_long 和 close_short 是买入(向上箭头)
+                    // open_short 和 close_long 是卖出(向下箭头)
+                    if (eventType === 'open_long' || eventType === 'close_short') {
                         symbol = 'arrow';
-                        symbolSize = 15;
+                        symbolSize = 12;
                         symbolRotate = 0;
                         color = '#28a745';
                         label = '买入';
-                    } else if (side === 'short') {
+                    } else if (eventType === 'open_short' || eventType === 'close_long') {
                         symbol = 'arrow';
-                        symbolSize = 15;
+                        symbolSize = 12;
                         symbolRotate = 180;
                         color = '#dc3545';
                         label = '卖出';
                     } else {
                         color = '#6c757d';
                         symbol = 'circle';
-                        symbolSize = 10;
+                        symbolSize = 8;
                         label = '其他';
                     }
 
@@ -793,27 +795,29 @@
                 console.log('   准备添加', tradingEventsData.length, '个事件标记到BPS图表');
                 tradingEventsData.forEach(event => {
                     const timestamp = event.timestamp * 1000;
-                    const side = event.side;
                     const eventType = event.event_type;
 
                     let color, symbol, symbolSize, label, symbolRotate = 0;
 
-                    if (side === 'long') {
+                    // 根据 event_type 确定方向
+                    // open_long 和 close_short 是买入(向上箭头)
+                    // open_short 和 close_long 是卖出(向下箭头)
+                    if (eventType === 'open_long' || eventType === 'close_short') {
                         symbol = 'arrow';
-                        symbolSize = 15;
+                        symbolSize = 12;
                         symbolRotate = 0;
                         color = '#28a745';
                         label = '买入';
-                    } else if (side === 'short') {
+                    } else if (eventType === 'open_short' || eventType === 'close_long') {
                         symbol = 'arrow';
-                        symbolSize = 15;
+                        symbolSize = 12;
                         symbolRotate = 180;
                         color = '#dc3545';
                         label = '卖出';
                     } else {
                         color = '#6c757d';
                         symbol = 'circle';
-                        symbolSize = 10;
+                        symbolSize = 8;
                         label = '其他';
                     }
 
@@ -1058,38 +1062,29 @@
             tradingEventsData.forEach(event => {
                 const timestamp = event.timestamp * 1000; // 转换为毫秒
                 const eventType = event.event_type;
-                const side = event.side; // long 或 short
 
-                // 确定颜色和符号 - 根据方向:买=向上,卖=向下
+                // 确定颜色和符号
                 let color, symbol, symbolSize, label, symbolRotate = 0;
 
-                // 判断是开仓还是平仓
-                const isOpen = eventType.includes('open');
-                const isClose = eventType.includes('close');
-
-                // 根据side确定箭头方向
-                if (side === 'long') {
-                    // 买入 = 向上箭头
+                // 根据 event_type 确定方向
+                // open_long 和 close_short 是买入(向上箭头)
+                // open_short 和 close_long 是卖出(向下箭头)
+                if (eventType === 'open_long' || eventType === 'close_short') {
                     symbol = 'arrow';
-                    symbolSize = 15;
-                    symbolRotate = 0; // 向上
-
+                    symbolSize = 12;
+                    symbolRotate = 0;
                     color = '#28a745';
                     label = '买入';
-                } else if (side === 'short') {
-                    // 卖出 = 向下箭头
+                } else if (eventType === 'open_short' || eventType === 'close_long') {
                     symbol = 'arrow';
-                    symbolSize = 15;
-                    symbolRotate = 180; // 向下
-
+                    symbolSize = 12;
+                    symbolRotate = 180;
                     color = '#dc3545';
                     label = '卖出';
                 } else {
-                    // 未知方向
-                    color = '#6c757d'; // 灰色
+                    color = '#6c757d';
                     symbol = 'circle';
-                    symbolSize = 10;
-                    symbolRotate = 0;
+                    symbolSize = 8;
                     label = '其他';
                 }
 
@@ -1099,7 +1094,7 @@
                     value: label,
                     symbol: symbol,
                     symbolSize: symbolSize,
-                    symbolRotate: symbolRotate, // 使用计算好的旋转角度
+                    symbolRotate: symbolRotate,
                     itemStyle: {
                         color: color,
                         borderColor: '#fff',