Skip to content

Commit

Permalink
修复分钟频率open_auction拿有夜盘品种的价格有误
Browse files Browse the repository at this point in the history
  • Loading branch information
Zhou-JiaJun committed Sep 7, 2023
1 parent 7cceee9 commit 447ad16
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 2 deletions.
4 changes: 2 additions & 2 deletions rqalpha/mod/rqalpha_mod_sys_simulation/matcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,14 +78,14 @@ def _vwap_decider(self, order_book_id, _):
return 0

def _open_auction_deal_price_decider(self, order_book_id, _):
return self._env.data_proxy.get_open_auction_bar(order_book_id, self._env.calendar_dt).open
return self._env.data_proxy.get_open_auction_bar(order_book_id, self._env.trading_dt).open

SUPPORT_POSITION_EFFECTS = (POSITION_EFFECT.OPEN, POSITION_EFFECT.CLOSE, POSITION_EFFECT.CLOSE_TODAY)
SUPPORT_SIDES = (SIDE.BUY, SIDE.SELL)

def _get_bar_volume(self, order, open_auction=False):
if open_auction:
volume = self._env.data_proxy.get_open_auction_bar(order.order_book_id, self._env.calendar_dt).volume
volume = self._env.data_proxy.get_open_auction_bar(order.order_book_id, self._env.trading_dt).volume
else:
if isinstance(order.style, ALGO_ORDER_STYLES):
_, volume = self._env.data_proxy.get_algo_bar(order.order_book_id, order.style, self._env.calendar_dt)
Expand Down
43 changes: 43 additions & 0 deletions tests/api_tests/mod/sys_simulation/test_simulation_event_source.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,3 +59,46 @@ def handle_bar(context, bar_dict):
assert context.open_auction_prices == (bar.open, bar.limit_up, bar.limit_down, bar.prev_close)

return locals()


def test_open_auction_1m():
""" 测试分钟回测下的open_auction """

try:
import rqalpha_plus
except ImportError:
print("非本地不执行分钟频率测试")
return {}

__config__ = {
"base": {
"start_date": "2023-03-17",
"end_date": "2023-03-17",
"frequency": "1m",
"accounts": {
"stock": 100000,
"future": 1000000,
}
},
"mod": {
"ricequant_data": {
"enabled": True,
}
}
}

def init(context):
subscribe("AU2306")
subscribe("000001.XSHE")

def open_auction(context, bar_dict):
buy_open("AU2306", 1)
order_shares("000001.XSHE", 100)

def handle_bar(context, bar_dict):
pos = get_position("AU2306")
assert pos.avg_price == 432.58, "期货分钟频率open_auction价格有误"
pos = get_position("000001.XSHE")
assert pos.avg_price == 12.99, "股票分钟频率open_auction价格有误"

return locals()

0 comments on commit 447ad16

Please sign in to comment.