Skip to content

Commit

Permalink
Merge f495223 into e92a554
Browse files Browse the repository at this point in the history
  • Loading branch information
Zhou-JiaJun committed Mar 9, 2023
2 parents e92a554 + f495223 commit afd1e03
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 13 deletions.
15 changes: 5 additions & 10 deletions rqalpha/mod/rqalpha_mod_sys_simulation/matcher.py
Expand Up @@ -34,7 +34,7 @@ def match(self, account, order, open_auction):
# type: (Account, Order, bool) -> None
raise NotImplementedError

def update(self):
def update(self, event):
raise NotImplementedError


Expand Down Expand Up @@ -205,7 +205,7 @@ def match(self, account, order, open_auction):
)
order.mark_cancelled(reason)

def update(self):
def update(self, event):
self._turnover.clear()


Expand All @@ -231,7 +231,6 @@ def __init__(self, env, mod_config):
self._cur_tick: Dict[str, TickObject] = dict()

# 订阅一些事件
self._env.event_bus.prepend_listener(EVENT.TICK, self._on_tick)
self._env.event_bus.add_listener(EVENT.BEFORE_TRADING, self._on_before_trading)

def _create_deal_price_decider(self, matching_type):
Expand Down Expand Up @@ -260,12 +259,6 @@ def _on_before_trading(self, event):
self._last_tick.clear()
self._cur_tick.clear()

def _on_tick(self, event):
# 保存上一个时刻的tick
self._last_tick[event.tick.order_book_id] = self._cur_tick.get(event.tick.order_book_id)
# 保存当前时刻的tick
self._cur_tick[event.tick.order_book_id] = event.tick

def _get_today_history_ticks(self, order_book_id, count):
""" 获取当前交易日的历史tick数据 """
cal_dt = self._env.calendar_dt
Expand Down Expand Up @@ -457,7 +450,9 @@ def match(self, account, order, open_auction): # type: (Account, Order, bool) -
)
order.mark_cancelled(reason)

def update(self):
def update(self, event):
self._last_tick[event.tick.order_book_id] = self._cur_tick.get(event.tick.order_book_id)
self._cur_tick[event.tick.order_book_id] = event.tick
self._turnover.clear()


Expand Down
6 changes: 3 additions & 3 deletions rqalpha/mod/rqalpha_mod_sys_simulation/simulation_broker.py
Expand Up @@ -155,14 +155,14 @@ def pre_settlement(self, __):
self._env.event_bus.publish_event(Event(EVENT.ORDER_UNSOLICITED_UPDATE, account=account, order=order))
self._open_exercise_orders.clear()

def on_bar(self, _):
def on_bar(self, event):
for matcher in self._matchers.values():
matcher.update()
matcher.update(event)
self._match()

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

def _match(self, order_book_id=None):
Expand Down

0 comments on commit afd1e03

Please sign in to comment.