-
Notifications
You must be signed in to change notification settings - Fork 858
Expand file tree
/
Copy pathrun_arbitrage_execution_v3.py
More file actions
executable file
·141 lines (113 loc) · 4.03 KB
/
Copy pathrun_arbitrage_execution_v3.py
File metadata and controls
executable file
·141 lines (113 loc) · 4.03 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
"""
套利执行系统 V3 - 入口文件
功能:
- 完整的套利执行系统(决策、执行、风险控制)
- 自动化开仓/平仓
- 多交易所套利
使用方法:
python3 run_arbitrage_execution_v3.py
可选参数:
--unified-config 统一配置文件路径(套利决策、执行、风险控制)
--monitor-config 监控配置文件路径(交易对、交易所等)
--debug 启用基础Debug模式
--debug-detail 启用详细Debug模式
"""
# 🔥 加载环境变量(必须在其他导入之前)
from dotenv import load_dotenv
from pathlib import Path
env_path = Path(__file__).parent / '.env'
if env_path.exists():
load_dotenv(env_path)
import asyncio
import argparse
from core.services.arbitrage_monitor_v2.core.arbitrage_orchestrator_v3 import ArbitrageOrchestratorV3
from core.services.arbitrage_monitor_v2.config.debug_config import DebugConfig
def parse_args():
"""解析命令行参数"""
parser = argparse.ArgumentParser(description="套利执行系统 V3")
parser.add_argument(
'--unified-config',
type=str,
default='config/arbitrage/arbitrage_unified.yaml',
help='统一配置文件路径(套利决策、执行、风险控制)'
)
parser.add_argument(
'--monitor-config',
type=str,
default='config/arbitrage/monitor_v2.yaml',
help='监控配置文件路径(交易对、交易所等)'
)
parser.add_argument(
'--debug',
action='store_true',
help='启用基础Debug模式'
)
parser.add_argument(
'--debug-detail',
action='store_true',
help='启用详细Debug模式'
)
return parser.parse_args()
async def main():
"""主函数"""
# 解析参数
args = parse_args()
# 创建Debug配置
if args.debug_detail:
debug_config = DebugConfig.create_detailed(set())
print("🐛 详细Debug模式已启用")
elif args.debug:
debug_config = DebugConfig.create_basic()
print("🐛 基础Debug模式已启用")
else:
debug_config = DebugConfig.create_production()
# 配置文件路径
unified_config_path = Path(args.unified_config)
monitor_config_path = Path(args.monitor_config)
# 检查配置文件是否存在
if not unified_config_path.exists():
print(f"⚠️ 统一配置文件不存在: {unified_config_path}")
print("使用默认配置")
unified_config_path = None
if not monitor_config_path.exists():
print(f"⚠️ 监控配置文件不存在: {monitor_config_path}")
print("使用默认配置")
monitor_config_path = None
# 创建调度器
orchestrator = ArbitrageOrchestratorV3(
unified_config_path=unified_config_path,
monitor_config_path=monitor_config_path,
debug_config=debug_config
)
try:
# 启动系统
print("=" * 70)
print("🚀 套利执行系统 V3 启动中...")
print("=" * 70)
print(f"📋 统一配置: {unified_config_path or '默认配置'}")
print(f"📋 监控配置: {monitor_config_path or '默认配置'}")
print()
await orchestrator.start()
print("\n✅ 系统运行中,按 Ctrl+C 停止\n")
print("⚠️ 警告:此系统将执行实际交易,请确保已正确配置风险控制参数!")
print()
# 持续运行
while True:
await asyncio.sleep(1)
except KeyboardInterrupt:
print("\n\n收到停止信号 (Ctrl+C)...")
except Exception as e:
print(f"\n❌ 系统错误: {e}")
import traceback
traceback.print_exc()
finally:
# 停止系统
print("\n🛑 正在停止系统...")
await orchestrator.stop()
print("✅ 系统已停止")
print("\n👋 再见!")
if __name__ == "__main__":
try:
asyncio.run(main())
except KeyboardInterrupt:
pass