Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
Zhou-JiaJun committed Jun 22, 2022
1 parent c946511 commit 187e96f
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 12 deletions.
39 changes: 29 additions & 10 deletions rqalpha/mod/rqalpha_mod_sys_simulation/matcher.py
Expand Up @@ -309,8 +309,11 @@ def match(self, account, order, open_auction): # type: (Account, Order, bool) -
if instrument.during_call_auction(self._env.calendar_dt):
# 集合竞价时段内撮合无视 matching_type 的设置,直接使用 last 进行撮合
deal_price = _cur_tick.last
# 集合竞价默认开启成交量限制,用来保证在集合竞价中只有一笔成交
_volume_limit_flag = True
else:
deal_price = self._deal_price_decider(order_book_id, order.side)
_volume_limit_flag = self._volume_limit

# 确认价格是否有效
if not is_valid_price(deal_price):
Expand Down Expand Up @@ -374,7 +377,7 @@ def match(self, account, order, open_auction): # type: (Account, Order, bool) -
return

# 是否开启成交量限制
if self._volume_limit:
if _volume_limit_flag:
# 获取上一个tick
_last_tick = self._get_last_tick(order_book_id)

Expand All @@ -392,7 +395,8 @@ def match(self, account, order, open_auction): # type: (Account, Order, bool) -
volume_limit = (volume_limit // instrument.round_lot) * instrument.round_lot

if volume_limit <= 0:
if order.type == ORDER_TYPE.MARKET:
# 集合竞价无法撤单
if order.type == ORDER_TYPE.MARKET and not instrument.during_call_auction(self._env.calendar_dt):
reason = _(u"Order Cancelled: market order {order_book_id} volume {order_volume}"
u" due to volume limit").format(
order_book_id=order.order_book_id,
Expand All @@ -402,7 +406,10 @@ def match(self, account, order, open_auction): # type: (Account, Order, bool) -
return

# 实际成交数量
fill = min(order.unfilled_quantity, volume_limit)
if self._volume_limit:
fill = min(order.unfilled_quantity, volume_limit)
else:
fill = order.unfilled_quantity
else:
# 下单数量就是成交数量
fill = order.unfilled_quantity
Expand Down Expand Up @@ -499,6 +506,9 @@ def match(self, account, order, open_auction):
if instrument.during_call_auction(self._env.trading_dt):
# 集合竞价期间一律使用last
matching_price = self._cur_tick[order_book_id].last
_volume_limit_flag = True
else:
_volume_limit_flag = self._volume_limit

if matching_price != matching_price:
return
Expand All @@ -512,7 +522,7 @@ def match(self, account, order, open_auction):
return

# 成交量限制
if self._volume_limit:
if _volume_limit_flag:
# 获取tick
_last_tick = self._get_last_tick(order_book_id)
_cur_tick = self._cur_tick[order_book_id]
Expand All @@ -530,15 +540,24 @@ def match(self, account, order, open_auction):
# 对成交量根据 1手 : n股 的比例进行限制
volume_limit = (volume_limit // instrument.round_lot) * instrument.round_lot

# 没成交量
if volume_limit == 0:
if volume_limit <= 0:
# 集合竞价无法撤单
if order.type == ORDER_TYPE.MARKET and not instrument.during_call_auction(self._env.calendar_dt):
reason = _(u"Order Cancelled: market order {order_book_id} volume {order_volume}"
u" due to volume limit").format(
order_book_id=order.order_book_id,
order_volume=order.quantity
)
order.mark_cancelled(reason)
return

if instrument.during_call_auction(self._env.trading_dt):
# 集合竞价期间不看档位
fill = min(order.unfilled_quantity, volume_limit)
if self._volume_limit:
if instrument.during_call_auction(self._env.trading_dt):
fill = min(order.unfilled_quantity, volume_limit)
else:
fill = min(order.unfilled_quantity, amount, volume_limit)
else:
fill = min(order.unfilled_quantity, amount, volume_limit)
fill = min(order.unfilled_quantity, amount)
else:
fill = min(order.unfilled_quantity, amount)

Expand Down
3 changes: 1 addition & 2 deletions rqalpha/model/instrument.py
Expand Up @@ -395,14 +395,13 @@ def during_call_auction(self, dt):
# 9:30 前或 14:57 之后为集合竞价
return _minute < 9 * 60 + 30 or _minute >= 14 * 60 + 57
elif self.type == INSTRUMENT_TYPE.FUTURE:
# TODO:期货收盘集合竞价时间
# 期货开盘时间
start_time = self.trading_hours[0].start

# -1 是因为获取到的时间都是开盘后1分钟,如 09:31
start_minute = start_time.hour * 60 + start_time.minute - 1

# 开盘集合竞价时间段为开盘前5分钟
# 开盘集合竞价时间段为开盘前5分钟,期货无收盘集合竞价
return start_minute - 5 <= _minute < start_minute
else:
# 其他品种由子类实现
Expand Down

0 comments on commit 187e96f

Please sign in to comment.