配置项#
TradePy的默认配置文件是 ~/.tradepy/config.yaml
,基本格式如下。如果是回测模式,则只需提供 common
配置项
common:
# 详见CommonConf字段说明
trading:
# 详见TradingConf字段说明
schedules:
# 详见SchedulesConf字段说明
- pydantic model tradepy.core.conf.TradePyConf#
- field common: CommonConf [Required]#
- field trading: TradingConf | None = None#
实盘/模拟盘交易配置
- field schedules: SchedulesConf | None = None#
定时任务配置
- field notifications: NotificationConf | None = None#
微信通知配置,用于推送异常状态,未完成
- static get_default_config_file_path() Path #
- classmethod load_from_config_file() TradePyConf #
- save_to_config_file(path: str | Path | None = None)#
- pydantic model tradepy.core.conf.CommonConf#
- field mode: Literal['backtest', 'paper-trading', 'live-trading'] [Required]#
运行模式, 回测/模拟盘/实盘
- field database_dir: Path [Optional]#
本地数据存放目录
- field trade_lot_vol: int = 100#
每手交易量
- field blacklist_path: Path | None = None#
股票黑名单文件路径,
- field redis: RedisConf | None = None#
Redis 配置
- field redis_connection_pool: ConnectionPool | None = None#
- get_redis_client() Redis #
- pydantic model tradepy.core.conf.TradingConf#
- field broker: BrokerConf [Required]#
交易端服务连接配置
- field xtquant: XtQuantConf | None = None#
XtQuant配置 (策略端不需要)
- field strategy: StrategyConf [Optional]#
策略配置
- field periodic_tasks: PeriodicTasksConf [Optional]#
定时任启动时间务配置
- field timeouts: TimeoutsConf [Optional]#
超时时间配置
- field indicators_window_size: int = 60#
计算指标需要至少多少根K线
- field pending_order_expiry: float = 0#
未成交委托单过期时间, 单位秒, 0 表示不过期
- field cache_retention: int = 7#
缓存数据保留天数
- field markets: tuple[Literal['上证主板', '深证主板', '创业板', '北交所', '科创板', 'CDR', '新三板'], ...] = ('上证主板', '深证主板', '创业板')#
只交易这些主板的股票
- pydantic model tradepy.core.conf.SchedulesConf#
- field update_datasets: str = '0 20 * * *'#
更新本地数据, 默认每天20:00
- field warm_database: str = '0 9 * * *'#
预热数据库, 默认每天09:00
- field flush_broker_cache: str = '5 15 * * *'#
导出当日交易记录, 默认每天15:05
- field vacuum: str = '0 23 * * *'#
清理过期数据, 默认每天23:00
- static parse_cron(cron: str)#
- pydantic model tradepy.core.conf.BrokerConf#
- field host: str [Required]#
交易端服务地址
- field port: int [Required]#
交易端服务端口
- pydantic model tradepy.core.conf.XtQuantConf#
- field account_id: str [Required]#
您的券商账户ID
- field qmt_data_path: str [Required]#
QMT的Userdata_mini目录地址
- field price_type: str = 'FIXED_PRICE'#
- pydantic model tradepy.core.conf.PeriodicTasksConf#
- field tick_fetch_interval: int = 5#
行情更新间隔, 单位秒
- field assets_sync_interval: int = 3#
资产与持仓更新间隔, 单位秒
- field cancel_expired_orders_interval: int = 5#
过期未成交委托单清理间隔, 单位秒
- pydantic model tradepy.core.conf.TimeoutsConf#
- field download_quote: int = 3#
下载行情超时时间, 单位秒
- field download_ask_bid: int = 2#
下载买卖盘超时时间, 单位秒
- field compute_open_indicators: int = 240#
盘前计算当日指标超时时间, 单位秒, 最长4分钟
- field compute_close_indicators: int = 240#
尾盘计算平仓指标超时时间, 单位秒, 最长4分钟
- field handle_cont_trade: int = 2#
处理每个行情推送的超时时间, 包含了策略给出买卖信号和下单, 单位秒
- pydantic model tradepy.core.conf.StrategyConf#
- field strategy_class: Any = None#
策略类的module导入路径, 比如”my_strategy.SampleStrategy”。也可是策略类本身,但是在Jupyter Notebook中不能直接传入策略类
- field stop_loss: float = 0#
静态止损百分比, 如果不需要静态止盈止损, 可设置为一个任意大数
- field take_profit: float = 0#
静态止盈百分比
- field take_profit_slip: SlippageConf [Optional]#
止盈滑点
- field stop_loss_slip: SlippageConf [Optional]#
止损滑点
- field max_position_size: float = 1#
最大持仓百分比, 1 表示允许满仓单股
- field max_position_opens: int = 10000#
每日最大开仓数量, 如果触发买入信号的标的数量大于此值, 则按照买入信号的权重值顺序买入,权重一致则随机选择
- field min_trade_amount: int = 0#
每次开仓的最小买入金额, 0 表示不限制
- field custom_params: dict[str, Any] [Optional]#
自定义参数, 策略类内可在self上直接访问
- classmethod from_dict(data: dict[str, Any])#
- update(**kv_pairs)#
- load_strategy() StrategyBase #
- load_strategy_class() Type[StrategyBase] #
- pydantic model tradepy.core.conf.SlippageConf#
- field method: Literal['max_pct', 'max_jump', 'weibull'] [Required]#
滑点计算方法, max_pct=最大随机百分比, max_jump=最大随机跳点
- field params: Any [Required]#
滑点计算方法的参数, 如: method=max_jump, params=2, 即为最大可随机出两跳价位的滑点
- pydantic model tradepy.core.conf.BacktestConf#
- field cash_amount: float [Required]#
回测初始资金
- field broker_commission_rate: float = 0.05#
佣金费率%, 万五是0.05
- field min_broker_commission_fee: float = 5#
佣金最低收取金额
- field stamp_duty_rate: float = 0.1#
印花税率%, 千分之一是0.1
- field use_minute_k: bool = False#
是否使用分钟级K线进行回测
- field strategy: StrategyConf [Required]#
- field sl_tf_order: Literal['stop loss first', 'take profit first', 'random'] = 'stop loss first'#
止盈止损单的触发顺序, random 表示随机选择