From c39268b3da404718f9f02492099cc08a342e2c19 Mon Sep 17 00:00:00 2001 From: "lin.dongzhao" <542698096@qq.com> Date: Fri, 19 Apr 2024 17:26:04 +0800 Subject: [PATCH] =?UTF-8?q?tick=20=E6=92=AE=E5=90=88=E4=BF=AE=E5=A4=8D=20c?= =?UTF-8?q?ash=20=E4=B8=BA=E8=B4=9F=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../mod/rqalpha_mod_sys_simulation/matcher.py | 28 +++++++++++++------ 1 file changed, 19 insertions(+), 9 deletions(-) diff --git a/rqalpha/mod/rqalpha_mod_sys_simulation/matcher.py b/rqalpha/mod/rqalpha_mod_sys_simulation/matcher.py index 572a876b6..4406d1c13 100644 --- a/rqalpha/mod/rqalpha_mod_sys_simulation/matcher.py +++ b/rqalpha/mod/rqalpha_mod_sys_simulation/matcher.py @@ -145,9 +145,8 @@ def match(self, account, order, open_auction): cost_money += self._env.get_order_transaction_cost(validate_order) if cost_money > account.cash + order.init_frozen_cash: reason = _(u"Order Cancelled: not enough money to buy {order_book_id}, needs {cost_money:.2f}, cash {cash:.2f}").format( - order_book_id=order_book_id, - cost_money = cost_money, - cash = account.cash + order.init_frozen_cash) + order_book_id=order_book_id, cost_money=cost_money, cash = account.cash + order.init_frozen_cash + ) order.mark_rejected(reason) return @@ -358,6 +357,23 @@ def match(self, account, order, open_auction): # type: (Account, Order, bool) - order_book_id=order.order_book_id) order.mark_rejected(reason) return + + # 对价格进行滑点处理 + if instrument.during_call_auction(self._env.calendar_dt): + price = deal_price + else: + price = self._slippage_decider.get_trade_price(order, deal_price) + if order.side == SIDE.BUY and self._slippage_decider.decider.rate != 0: + validate_order = copy(order) + validate_order.set_frozen_price(price) + cost_money = instrument.calc_cash_occupation(price, order.quantity, order.position_direction, order.trading_datetime.date()) + cost_money += self._env.get_order_transaction_cost(validate_order) + if cost_money > account.cash + order.init_frozen_cash: + reason = _(u"Order Cancelled: not enough money to buy {order_book_id}, needs {cost_money:.2f}, cash {cash:.2f}").format( + order_book_id=order_book_id, cost_money=cost_money, cash=account.cash + order.init_frozen_cash + ) + order.mark_rejected(reason) + return price_board = self._env.price_board if order.type == ORDER_TYPE.LIMIT: @@ -448,12 +464,6 @@ def match(self, account, order, open_auction): # type: (Account, Order, bool) - # 平今的数量 ct_amount = account.calc_close_today_amount(order_book_id, fill, order.position_direction, order.position_effect) - # 对价格进行滑点处理 - if instrument.during_call_auction(self._env.calendar_dt): - price = deal_price - else: - price = self._slippage_decider.get_trade_price(order, deal_price) - # 成交记录 trade = Trade.__from_create__( order_id=order.order_id,