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