stock-ai-agent/check_bitget_status.py
2026-03-28 23:47:49 +08:00

128 lines
4.3 KiB
Python

#!/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()