Skip to content

Commit d35750e

Browse files
committed
Fix check_submitted margin rollback bug
1 parent 39cb953 commit d35750e

3 files changed

Lines changed: 576 additions & 2 deletions

File tree

backtrader/brokers/bbroker.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -681,9 +681,12 @@ def check_submitted(self):
681681
order.data, self.positions[order.data].clone())
682682
# pseudo-execute the order to get the remaining cash after exec
683683
# 假设执行订单之后获取的现金
684-
cash = self._execute(order, cash=cash, position=position)
684+
trial_position = position.clone()
685+
trial_cash = self._execute(order, cash=cash, position=trial_position)
685686
# 如果剩余的现金大于0,调用submit_accept接受订单
686-
if cash >= 0.0:
687+
if trial_cash >= 0.0:
688+
cash = trial_cash
689+
positions[order.data] = trial_position
687690
self.submit_accept(order)
688691
continue
689692
# 如果cash是小于0的话,保证金不足,通知order的状态,调用_ococheck和_bracketize

0 commit comments

Comments
 (0)