1oscon commited on
Commit
06ff186
·
verified ·
1 Parent(s): 2d9bd9a

Update 模拟实盘.py

Browse files
Files changed (1) hide show
  1. 模拟实盘.py +30 -6
模拟实盘.py CHANGED
@@ -5,6 +5,18 @@ import os
5
  from 插件_引擎.多策略引擎 import 多策略引擎
6
  from 插件_交易.策略_自适应 import 自适应策略
7
 
 
 
 
 
 
 
 
 
 
 
 
 
8
  async def 主程序():
9
  # 1. 加载你的参数文件
10
  参数路径60 = "/storage/emulated/0/exports/回测输出_WebUI_20250925_073205/最优参数_60分.json"
@@ -26,21 +38,33 @@ async def 主程序():
26
  # 2. 创建引擎
27
  引擎 = 多策略引擎()
28
 
29
- # 3. 注册策略(可多个)
 
 
 
30
  if 参数60:
31
- 策略60 = 自适应策略("UXLINK_60分", 参数60)
32
- 引擎.注册策略("UXLINK_60", 策略60, "UXLINK-USDT-SWAP", 60)
 
 
33
 
34
  if 参数120:
35
- 策略120 = 自适应策略("GPS_120分", 参数120)
36
- 引擎.注册策略("GPS_120", 策略120, "GPS-USDT-SWAP", 120)
 
 
37
 
38
  # 4. 启动(订阅并运行)
39
  print("=" * 50)
40
  print("模拟实盘启动...")
41
  print("=" * 50)
42
 
43
- await 引擎.启动(["UXLINK-USDT-SWAP", "GPS-USDT-SWAP"])
 
 
 
 
 
44
 
45
  if __name__ == "__main__":
46
  try:
 
5
  from 插件_引擎.多策略引擎 import 多策略引擎
6
  from 插件_交易.策略_自适应 import 自适应策略
7
 
8
+ def 推断周期(参数: dict, 默认: int) -> int:
9
+ if not isinstance(参数, dict):
10
+ return int(默认)
11
+ 候选键 = ('tf', 'period', '周期', 'bar_min', 'timeframe', 'k', 'k_min')
12
+ for k in 候选键:
13
+ v = 参数.get(k)
14
+ if isinstance(v, (int, float)) and int(v) > 0:
15
+ return int(v)
16
+ if isinstance(v, str) and v.strip().isdigit():
17
+ return int(v.strip())
18
+ return int(默认)
19
+
20
  async def 主程序():
21
  # 1. 加载你的参数文件
22
  参数路径60 = "/storage/emulated/0/exports/回测输出_WebUI_20250925_073205/最优参数_60分.json"
 
38
  # 2. 创建引擎
39
  引擎 = 多策略引擎()
40
 
41
+ # 3. 注册策略(可多个)—— 周期由参数自动推断(无则用默认)
42
+ 合约1 = "UXLINK-USDT-SWAP"
43
+ 合约2 = "GPS-USDT-SWAP"
44
+
45
  if 参数60:
46
+ tf60 = 推断周期(参数60, 60)
47
+ 策略60 = 自适应策略(f"UXLINK_{tf60}分", 参数60)
48
+ 引擎.注册策略("UXLINK_AUTO", 策略60, 合约1, tf60)
49
+ print(f"UXLINK 策略周期:{tf60}(若参数未给出则默认60)")
50
 
51
  if 参数120:
52
+ tf120 = 推断周期(参数120, 120)
53
+ 策略120 = 自适应策略(f"GPS_{tf120}分", 参数120)
54
+ 引擎.注册策略("GPS_AUTO", 策略120, 合约2, tf120)
55
+ print(f"GPS 策略周期:{tf120}(若参数未给出则默认120)")
56
 
57
  # 4. 启动(订阅并运行)
58
  print("=" * 50)
59
  print("模拟实盘启动...")
60
  print("=" * 50)
61
 
62
+ 待订阅 = []
63
+ if 参数60: 待订阅.append(合约1)
64
+ if 参数120: 待订阅.append(合约2)
65
+ if not 待订阅:
66
+ 待订阅 = [合约1, 合约2]
67
+ await 引擎.启动(待订阅)
68
 
69
  if __name__ == "__main__":
70
  try: