a
This commit is contained in:
parent
b48f555524
commit
75653be44c
|
|
@ -103,26 +103,28 @@ class TradingStrategy:
|
|||
# 使用技术指标判断交易信号(高胜率策略)
|
||||
trade_signal = await self._analyze_trade_signal(symbol_info)
|
||||
|
||||
# 记录交易信号到数据库
|
||||
try:
|
||||
import sys
|
||||
from pathlib import Path
|
||||
project_root = Path(__file__).parent.parent
|
||||
backend_path = project_root / 'backend'
|
||||
if backend_path.exists():
|
||||
sys.path.insert(0, str(backend_path))
|
||||
from database.models import TradingSignal
|
||||
TradingSignal.create(
|
||||
symbol=symbol,
|
||||
signal_direction=trade_signal.get('direction', ''),
|
||||
signal_strength=trade_signal.get('strength', 0),
|
||||
signal_reason=trade_signal.get('reason', ''),
|
||||
rsi=symbol_info.get('rsi'),
|
||||
macd_histogram=symbol_info.get('macd', {}).get('histogram') if symbol_info.get('macd') else None,
|
||||
market_regime=symbol_info.get('marketRegime')
|
||||
)
|
||||
except Exception as e:
|
||||
logger.debug(f"记录交易信号失败: {e}")
|
||||
# 记录交易信号到数据库(只有当有明确方向时才记录)
|
||||
signal_direction = trade_signal.get('direction')
|
||||
if signal_direction: # 只有当方向不为空时才记录
|
||||
try:
|
||||
import sys
|
||||
from pathlib import Path
|
||||
project_root = Path(__file__).parent.parent
|
||||
backend_path = project_root / 'backend'
|
||||
if backend_path.exists():
|
||||
sys.path.insert(0, str(backend_path))
|
||||
from database.models import TradingSignal
|
||||
TradingSignal.create(
|
||||
symbol=symbol,
|
||||
signal_direction=signal_direction,
|
||||
signal_strength=trade_signal.get('strength', 0),
|
||||
signal_reason=trade_signal.get('reason', ''),
|
||||
rsi=symbol_info.get('rsi'),
|
||||
macd_histogram=symbol_info.get('macd', {}).get('histogram') if symbol_info.get('macd') else None,
|
||||
market_regime=symbol_info.get('marketRegime')
|
||||
)
|
||||
except Exception as e:
|
||||
logger.debug(f"记录交易信号失败: {e}")
|
||||
|
||||
if not trade_signal['should_trade']:
|
||||
logger.info(
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user