Files
big-qmt/py-client/strategy/trend/runtime.py

45 lines
1.5 KiB
Python
Raw Normal View History

2026-08-28 18:52:27 +08:00
"""趋势策略单次运行所需的上下文对象。"""
from __future__ import annotations
2026-08-31 15:33:39 +08:00
from concurrent.futures import ThreadPoolExecutor
2026-08-28 18:52:27 +08:00
from dataclasses import dataclass, field
from config import AccountConfig, GlobalConfig
from sdk import Client
2026-08-28 22:46:04 +08:00
from libs.grid_take_profit import GridTrailingTracker
2026-08-28 18:52:27 +08:00
from .order import OrderBook
from .watch import DipWatch
2026-09-05 13:56:04 +08:00
@dataclass(frozen=True, slots=True)
2026-08-28 18:52:27 +08:00
class Runtime:
"""集中保存趋势策略运行期间共享的依赖和状态。
将这些对象集中到一个 dataclass 开仓持仓管理和单轮调度函数
只需接收一个 ``Runtime``无需重复传递大量参数
Attributes:
client: QMT HTTP 客户端用于查询账户行情和提交委托
global_cfg: 公共配置包含 QMT外部 API 和信号配置
account_cfg: 当前主机的账户及交易策略配置
state: 策略持仓状态的本地持久化存储
orders: 当前活动委托和证券方向锁
open_watch: 新开仓使用的价格反弹观察器
add_watch: 亏损补仓使用的价格反弹观察器
2026-08-28 22:46:04 +08:00
profit_tracker: 跨轮保存的账户持仓最高盈利网格跟踪器
2026-08-28 18:52:27 +08:00
"""
# 外部服务与账户配置。
client: Client
global_cfg: GlobalConfig
account_cfg: AccountConfig
# 策略运行过程中共享的状态组件。
orders: OrderBook
open_watch: DipWatch
add_watch: DipWatch
2026-08-28 22:46:04 +08:00
profit_tracker: GridTrailingTracker
2026-08-31 15:33:39 +08:00
executor: ThreadPoolExecutor