1
This commit is contained in:
parent
7de9705be0
commit
8fbbe3cbc1
@ -731,9 +731,10 @@ class CryptoAgent:
|
|||||||
paper_decision = self.execute_signal_with_rules(
|
paper_decision = self.execute_signal_with_rules(
|
||||||
trading_signal, 'PaperTrading', paper_account, paper_positions, paper_pending
|
trading_signal, 'PaperTrading', paper_account, paper_positions, paper_pending
|
||||||
)
|
)
|
||||||
await self._send_trading_decision_notification(
|
# 不发送决策通知(因为是基于硬编码规则的执行,不是 LLM 决策)
|
||||||
paper_decision, market_signal, current_price, prefix="[模拟盘]"
|
# await self._send_trading_decision_notification(
|
||||||
)
|
# paper_decision, market_signal, current_price, prefix="[模拟盘]"
|
||||||
|
# )
|
||||||
else:
|
else:
|
||||||
paper_decision = {"action": "IGNORE", "reason": "未启用"}
|
paper_decision = {"action": "IGNORE", "reason": "未启用"}
|
||||||
logger.info(f"⏸️ 模拟盘交易未启用")
|
logger.info(f"⏸️ 模拟盘交易未启用")
|
||||||
@ -745,9 +746,10 @@ class CryptoAgent:
|
|||||||
hl_decision = self.execute_signal_with_rules(
|
hl_decision = self.execute_signal_with_rules(
|
||||||
trading_signal, 'Hyperliquid', hl_account, hl_positions, hl_pending
|
trading_signal, 'Hyperliquid', hl_account, hl_positions, hl_pending
|
||||||
)
|
)
|
||||||
await self._send_trading_decision_notification(
|
# 不发送决策通知(因为是基于硬编码规则的执行,不是 LLM 决策)
|
||||||
hl_decision, market_signal, current_price, prefix="[Hyperliquid]"
|
# await self._send_trading_decision_notification(
|
||||||
)
|
# hl_decision, market_signal, current_price, prefix="[Hyperliquid]"
|
||||||
|
# )
|
||||||
else:
|
else:
|
||||||
hl_decision = {"action": "IGNORE", "reason": "未启用"}
|
hl_decision = {"action": "IGNORE", "reason": "未启用"}
|
||||||
logger.info(f"⏸️ Hyperliquid 实盘交易未启用")
|
logger.info(f"⏸️ Hyperliquid 实盘交易未启用")
|
||||||
@ -759,9 +761,10 @@ class CryptoAgent:
|
|||||||
bg_decision = self.execute_signal_with_rules(
|
bg_decision = self.execute_signal_with_rules(
|
||||||
trading_signal, 'Bitget', bg_account, bg_positions, bg_pending
|
trading_signal, 'Bitget', bg_account, bg_positions, bg_pending
|
||||||
)
|
)
|
||||||
await self._send_trading_decision_notification(
|
# 不发送决策通知(因为是基于硬编码规则的执行,不是 LLM 决策)
|
||||||
bg_decision, market_signal, current_price, prefix="[Bitget]"
|
# await self._send_trading_decision_notification(
|
||||||
)
|
# bg_decision, market_signal, current_price, prefix="[Bitget]"
|
||||||
|
# )
|
||||||
else:
|
else:
|
||||||
bg_decision = {"action": "IGNORE", "reason": "未启用"}
|
bg_decision = {"action": "IGNORE", "reason": "未启用"}
|
||||||
logger.info(f"⏸️ Bitget 实盘交易未启用")
|
logger.info(f"⏸️ Bitget 实盘交易未启用")
|
||||||
|
|||||||
@ -34,27 +34,21 @@ class PaperTradingExecutor(BaseExecutor):
|
|||||||
# 调整保证金(模拟盘无手续费)
|
# 调整保证金(模拟盘无手续费)
|
||||||
adjusted_margin = margin
|
adjusted_margin = margin
|
||||||
|
|
||||||
# 执行下单
|
# 构建信号字典
|
||||||
if order_type == 'market':
|
signal = {
|
||||||
result = self.paper_trading.create_order_from_signal(
|
'symbol': symbol,
|
||||||
symbol=symbol,
|
'action': action,
|
||||||
action=action,
|
'entry_type': order_type,
|
||||||
entry_type='market',
|
'entry_price': entry_price if order_type == 'limit' else current_price,
|
||||||
position_value=adjusted_margin * self.paper_trading.leverage,
|
'stop_loss': stop_loss,
|
||||||
entry_price=current_price, # 市价单使用当前价格
|
'take_profit': take_profit,
|
||||||
stop_loss=stop_loss,
|
}
|
||||||
take_profit=take_profit
|
|
||||||
)
|
# 执行下单(统一调用方式)
|
||||||
else:
|
result = self.paper_trading.create_order_from_signal(
|
||||||
result = self.paper_trading.create_order_from_signal(
|
signal=signal,
|
||||||
symbol=symbol,
|
current_price=current_price
|
||||||
action=action,
|
)
|
||||||
entry_type='limit',
|
|
||||||
position_value=adjusted_margin * self.paper_trading.leverage,
|
|
||||||
entry_price=entry_price,
|
|
||||||
stop_loss=stop_loss,
|
|
||||||
take_profit=take_profit
|
|
||||||
)
|
|
||||||
|
|
||||||
if result.get('success'):
|
if result.get('success'):
|
||||||
order = result.get('order')
|
order = result.get('order')
|
||||||
|
|||||||
127
check_bitget_status.py
Normal file
127
check_bitget_status.py
Normal file
@ -0,0 +1,127 @@
|
|||||||
|
#!/usr/bin/env python3
|
||||||
|
"""
|
||||||
|
Bitget 交易状态诊断脚本(简化版)
|
||||||
|
仅检查配置文件,不导入服务模块
|
||||||
|
"""
|
||||||
|
import sys
|
||||||
|
import os
|
||||||
|
from pathlib import Path
|
||||||
|
|
||||||
|
# 添加后端路径
|
||||||
|
backend_path = Path(__file__).parent / 'backend'
|
||||||
|
sys.path.insert(0, str(backend_path))
|
||||||
|
|
||||||
|
def check_env_file():
|
||||||
|
"""检查 .env 文件"""
|
||||||
|
env_path = Path(__file__).parent / '.env'
|
||||||
|
|
||||||
|
print("=" * 60)
|
||||||
|
print("🔍 Bitget 交易配置检查")
|
||||||
|
print("=" * 60)
|
||||||
|
|
||||||
|
if not env_path.exists():
|
||||||
|
print("\n❌ .env 文件不存在")
|
||||||
|
return
|
||||||
|
|
||||||
|
print(f"\n📄 检查 .env 文件: {env_path}")
|
||||||
|
|
||||||
|
with open(env_path, 'r', encoding='utf-8') as f:
|
||||||
|
lines = f.readlines()
|
||||||
|
|
||||||
|
# 查找 Bitget 相关配置
|
||||||
|
bitget_configs = []
|
||||||
|
for i, line in enumerate(lines, 1):
|
||||||
|
line = line.strip()
|
||||||
|
if line.startswith('BITGET_') or 'bitget' in line.lower():
|
||||||
|
# 隐藏敏感信息
|
||||||
|
if 'KEY' in line or 'SECRET' in line or 'PASSPHRASE' in line:
|
||||||
|
key, value = line.split('=', 1) if '=' in line else (line, '')
|
||||||
|
bitget_configs.append((i, f"{key}=***"))
|
||||||
|
else:
|
||||||
|
bitget_configs.append((i, line))
|
||||||
|
|
||||||
|
if bitget_configs:
|
||||||
|
print("\n✅ 找到 Bitget 配置:")
|
||||||
|
for line_num, config in bitget_configs:
|
||||||
|
print(f" 行 {line_num}: {config}")
|
||||||
|
else:
|
||||||
|
print("\n⚠️ 未找到任何 Bitget 相关配置")
|
||||||
|
|
||||||
|
# 检查关键配置项
|
||||||
|
print("\n📋 关键配置项检查:")
|
||||||
|
|
||||||
|
env_dict = {}
|
||||||
|
for line in lines:
|
||||||
|
line = line.strip()
|
||||||
|
if '=' in line and not line.startswith('#'):
|
||||||
|
key, value = line.split('=', 1)
|
||||||
|
env_dict[key.strip()] = value.strip()
|
||||||
|
|
||||||
|
# 1. BITGET_TRADING_ENABLED
|
||||||
|
enabled = env_dict.get('BITGET_TRADING_ENABLED', 'false').lower()
|
||||||
|
print(f" • BITGET_TRADING_ENABLED: {enabled}")
|
||||||
|
if enabled == 'true':
|
||||||
|
print(" ⚠️ Bitget 实盘交易: **已启用**")
|
||||||
|
else:
|
||||||
|
print(" ✅ Bitget 实盘交易: 未启用")
|
||||||
|
|
||||||
|
# 2. API Keys
|
||||||
|
api_key = env_dict.get('BITGET_API_KEY', '')
|
||||||
|
api_secret = env_dict.get('BITGET_API_SECRET', '')
|
||||||
|
passphrase = env_dict.get('BITGET_PASSPHRASE', '')
|
||||||
|
|
||||||
|
print(f" • BITGET_API_KEY: {'✅ 已配置' if api_key else '❌ 未配置'}")
|
||||||
|
print(f" • BITGET_API_SECRET: {'✅ 已配置' if api_secret else '❌ 未配置'}")
|
||||||
|
print(f" • BITGET_PASSPHRASE: {'✅ 已配置' if passphrase else '❌ 未配置'}")
|
||||||
|
|
||||||
|
# 3. 其他配置
|
||||||
|
max_leverage = env_dict.get('BITGET_MAX_TOTAL_LEVERAGE', '未设置')
|
||||||
|
max_position = env_dict.get('BITGET_MAX_SINGLE_POSITION', '未设置')
|
||||||
|
print(f" • BITGET_MAX_TOTAL_LEVERAGE: {max_leverage}")
|
||||||
|
print(f" • BITGET_MAX_SINGLE_POSITION: {max_position}")
|
||||||
|
|
||||||
|
# 4. 检查 config.py 默认值
|
||||||
|
print("\n📖 检查 config.py 默认值:")
|
||||||
|
config_path = backend_path / 'app' / 'config.py'
|
||||||
|
|
||||||
|
if config_path.exists():
|
||||||
|
with open(config_path, 'r', encoding='utf-8') as f:
|
||||||
|
config_content = f.read()
|
||||||
|
|
||||||
|
# 查找 bitget_trading_enabled 默认值
|
||||||
|
import re
|
||||||
|
match = re.search(r'bitget_trading_enabled[:\s=]+(?:bool\s*=\s*)?([^\n]+)', config_content)
|
||||||
|
if match:
|
||||||
|
default_value = match.group(1).strip()
|
||||||
|
print(f" • 默认值: {default_value}")
|
||||||
|
|
||||||
|
# 结论
|
||||||
|
print("\n" + "=" * 60)
|
||||||
|
print("📝 诊断结论:")
|
||||||
|
print("=" * 60)
|
||||||
|
|
||||||
|
if enabled == 'true':
|
||||||
|
print("\n⚠️ Bitget 实盘交易功能已启用!")
|
||||||
|
print("\n如果您不想使用实盘交易,请:")
|
||||||
|
print(" 1. 编辑 .env 文件")
|
||||||
|
print(" 2. 设置 BITGET_TRADING_ENABLED=false")
|
||||||
|
print(" 3. 重启后端服务")
|
||||||
|
else:
|
||||||
|
print("\n✅ Bitget 实盘交易功能未启用")
|
||||||
|
print("\n如果您收到了交易通知,可能原因:")
|
||||||
|
print(" 1. 配置被运行时修改")
|
||||||
|
print(" 2. 有旧进程仍在运行")
|
||||||
|
print(" 3. 通知配置错误")
|
||||||
|
print("\n建议:")
|
||||||
|
print(" • 检查后端日志: tail -f backend/logs/app.log")
|
||||||
|
print(" • 重启后端服务: 重启 uvicorn 进程")
|
||||||
|
|
||||||
|
print("=" * 60)
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
try:
|
||||||
|
check_env_file()
|
||||||
|
except Exception as e:
|
||||||
|
print(f"\n❌ 诊断失败: {e}")
|
||||||
|
import traceback
|
||||||
|
traceback.print_exc()
|
||||||
Loading…
Reference in New Issue
Block a user