Skip to content

Commit

Permalink
撮合过程中若缺失数据则跳过此次撮合
Browse files Browse the repository at this point in the history
  • Loading branch information
Zhou-JiaJun committed Oct 31, 2023
1 parent 69b5448 commit 5747782
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 11 deletions.
9 changes: 6 additions & 3 deletions rqalpha/mod/rqalpha_mod_sys_simulation/matcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,9 +124,12 @@ def match(self, account, order, open_auction):
elif isinstance(order.style, ALGO_ORDER_STYLES):
reason = _(u"Order Cancelled: {order_book_id} bar no volume").format(order_book_id=order.order_book_id)
else:
reason = _(u"Order Cancelled: current bar [{order_book_id}] miss market data.").format(
order_book_id=order.order_book_id)
order.mark_rejected(reason)
# 撮合的时候无行情数据也不需要撤单,等到有行情再撮合
reason = None
# reason = _(u"Order Cancelled: current bar [{order_book_id}] miss market data.").format(
# order_book_id=order.order_book_id)
if reason:
order.mark_rejected(reason)
return

price_board = self._env.price_board
Expand Down
14 changes: 6 additions & 8 deletions rqalpha/mod/rqalpha_mod_sys_simulation/simulation_broker.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ def submit_order(self, order):
order.active()
self._env.event_bus.publish_event(Event(EVENT.ORDER_CREATION_PASS, account=account, order=order))
if self._match_immediately:
self._match(self._env.calendar_dt)
self._match()

def cancel_order(self, order):
account = self._env.get_account(order.order_book_id)
Expand Down Expand Up @@ -158,19 +158,17 @@ def pre_settlement(self, __):
def on_bar(self, event):
for matcher in self._matchers.values():
matcher.update(event)
self._match(event.calendar_dt)
self._match()

def on_tick(self, event):
tick = event.tick
self._get_matcher(tick.order_book_id).update(event)
self._match(event.calendar_dt, tick.order_book_id)
self._match(tick.order_book_id)

def _match(self, dt, order_book_id=None):
def _match(self, order_book_id=None):
# 撮合未完成的订单,若指定标的时只撮合指定的标的的订单
order_filter = lambda a_and_o: (not a_and_o[1].is_final()) and (True if order_book_id is None else a_and_o[1].order_book_id == order_book_id)
# + 需要在交易时段内
open_order_filter = lambda a_and_o: order_filter(a_and_o) and self._env.data_proxy.instrument(a_and_o[1].order_book_id).during_continuous_auction(dt.time())
for account, order in filter(open_order_filter, self._open_orders):
order_filter = lambda a_and_o: not (a_and_o[1].is_final() or (order_book_id and a_and_o[1].order_book_id != order_book_id))
for account, order in filter(order_filter, self._open_orders):
self._get_matcher(order.order_book_id).match(account, order, open_auction=False)
for account, order in filter(order_filter, self._open_auction_orders):
self._get_matcher(order.order_book_id).match(account, order, open_auction=True)
Expand Down

0 comments on commit 5747782

Please sign in to comment.