Skip to content

Commit

Permalink
tick 撮合修复 cash 为负问题
Browse files Browse the repository at this point in the history
  • Loading branch information
Lin-Dongzhao committed Apr 19, 2024
1 parent 8603427 commit c39268b
Showing 1 changed file with 19 additions and 9 deletions.
28 changes: 19 additions & 9 deletions rqalpha/mod/rqalpha_mod_sys_simulation/matcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit c39268b

Please # to comment.