Skip to content

Commit

Permalink
Merge 3162069 into 2f079a2
Browse files Browse the repository at this point in the history
  • Loading branch information
Zhou-JiaJun committed May 25, 2022
2 parents 2f079a2 + 3162069 commit 19d5228
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 4 deletions.
14 changes: 10 additions & 4 deletions docs/source/api/base_api.rst
Original file line number Diff line number Diff line change
Expand Up @@ -535,16 +535,16 @@ time_rule - 定时间运行
注意:

* market_open与market_close都跟随中国A股交易时间进行设置,即09:31~15:00。
* physical_time用于设置物理时间,与market_open和market_close的相对时间不同。
* physical_time更多用于交易时间不确定的品种,如商品期货。
* 使用time_rule定时运行只会在分钟级别回测和实时模拟交易中有定义的效果,在日回测中只会默认依然在该天运行,并不能在固定的时间运行。
* 在分钟回测中如未指定time_rule,则默认在开盘后一分钟运行,即09:31分。
* 如果两个schedule,分别使用market_open 与market_close规则,但规则触发时间在同一时刻,则market_open的handle一定在market_close的handle前执行。
* 目前暂不支持开盘交易(即 09:30分交易) ,所以time_rule(minute=0) 和time_rule(hour=0) 将不会触发任何事件。
* market_open(minute=120)将在11:30执行, market_open(minute=121)在13:01执行,中午休市的区间会被忽略。
* 目前暂不支持开盘交易(即 09:30分交易)。
* time_rule='before_trading'表示在开市交易前运行scheduler函数。该函数运行时间将在before_trading函数运行完毕之后handle_bar运行之前。

`time_rule`: 定时具体几点几分运行某个函数。time_rule='before_trading' 表示开始交易前运行;market_open(hour=x, minute=y)表示A股市场开市后x小时y分钟运行,market_close(hour=x, minute=y)表示A股市场收市前x小时y分钟运行。如果不设置time_rule默认的值是中国A股市场开市后一分钟运行。

market_open, market_close参数如下
market_open, market_close, physical_time参数如下

========================= ========================= ==============================================================================
参数 类型 注释
Expand Down Expand Up @@ -583,6 +583,12 @@ time_rule - 定时间运行
scheduler.run_daily(function, time_rule='before_trading')
* 每天十点运行

.. code-block:: python3
:linenos:
scheduler.run_daily(function, time_rule=physical_time(hour=10, minute=0))
.. _api-base-types:

Expand Down
54 changes: 54 additions & 0 deletions tests/api_tests/mod/sys_scheduler/test_future_scheduler.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
# -*- coding: utf-8 -*-
# 版权所有 2019 深圳米筐科技有限公司(下称“米筐科技”)
#
# 除非遵守当前许可,否则不得使用本软件。
#
# * 非商业用途(非商业用途指个人出于非商业目的使用本软件,或者高校、研究所等非营利机构出于教育、科研等目的使用本软件):
# 遵守 Apache License 2.0(下称“Apache 2.0 许可”),
# 您可以在以下位置获得 Apache 2.0 许可的副本:http://www.apache.org/licenses/LICENSE-2.0。
# 除非法律有要求或以书面形式达成协议,否则本软件分发时需保持当前许可“原样”不变,且不得附加任何条件。
#
# * 商业用途(商业用途指个人出于任何商业目的使用本软件,或者法人或其他组织出于任何目的使用本软件):
# 未经米筐科技授权,任何个人不得出于任何商业目的使用本软件(包括但不限于向第三方提供、销售、出租、出借、转让本软件、
# 本软件的衍生产品、引用或借鉴了本软件功能或源代码的产品或服务),任何法人或其他组织不得出于任何目的使用本软件,
# 否则米筐科技有权追究相应的知识产权侵权责任。
# 在此前提下,对本软件的使用同样需要遵守 Apache 2.0 许可,Apache 2.0 许可与本许可冲突之处,以本许可为准。
# 详细的授权流程,请联系 public@ricequant.com 获取。


__config__ = {
"base": {
"start_date": "2015-01-01",
"end_date": "2015-12-31",
"frequency": "1d",
"accounts": {
"future": 1000000,
}
},
"extra": {
"log_level": "error",
},
}


def test_run_daily():
"""
测试 physical_time 的使用
"""
from rqalpha.mod.rqalpha_mod_sys_scheduler.scheduler import physical_time

def _day(context, bar_dict):
context.counter += 1

def init(context):
context.counter = 0
scheduler.run_daily(_day, time_rule=physical_time(hour=21, minute=31))
scheduler.run_daily(_day, time_rule=physical_time(hour=9, minute=31))
context.days = 0

def handle_bar(context, bar_dict):
context.days += 1
assert context.counter == context.days * 2

return locals()

0 comments on commit 19d5228

Please sign in to comment.