diff --git a/RELEASES.md b/RELEASES.md index 27a1ead4d3ee..b12e7f51d898 100644 --- a/RELEASES.md +++ b/RELEASES.md @@ -31,6 +31,7 @@ Released on TBD (UTC). - Fixed `RiskEngine` cumulative notional calculations for margin accounts (was incorrectly using base currency when selling) - Fixed selling `Equity` instruments with `CASH` account and `NETTING` OMS incorrectly rejecting (should be able to reduce position) - Fixed Databento bars decoding (was incorrectly applying display factor) +- Fixed `AccountMarginExceeded` error condition (margin must actually be exceeded now, and can be zero) --- diff --git a/nautilus_trader/accounting/accounts/margin.pyx b/nautilus_trader/accounting/accounts/margin.pyx index 5e980b6dd528..c8db6e8baf38 100644 --- a/nautilus_trader/accounting/accounts/margin.pyx +++ b/nautilus_trader/accounting/accounts/margin.pyx @@ -466,7 +466,7 @@ cdef class MarginAccount(Account): cdef double total_free = current_balance.total.as_f64_c() - total_margin - if total_free <= 0.0: + if total_free < 0.0: raise AccountMarginExceeded( balance=current_balance.total.as_decimal(), margin=Money(total_margin, currency).as_decimal(), diff --git a/nautilus_trader/accounting/manager.pyx b/nautilus_trader/accounting/manager.pyx index 79433cf4a630..2016282f0851 100644 --- a/nautilus_trader/accounting/manager.pyx +++ b/nautilus_trader/accounting/manager.pyx @@ -559,12 +559,12 @@ cdef class AccountsManager: new_free = balance.free.as_f64_c() + pnl.as_f64_c() total = Money(new_total, pnl.currency) free = Money(new_free, pnl.currency) - if new_total < 0: + if new_total < 0.0: raise AccountBalanceNegative( balance=total.as_decimal(), currency=pnl.currency, ) - if new_free <= 0: + if new_free < 0.0: raise AccountMarginExceeded( balance=total.as_decimal(), margin=balance.locked.as_decimal(),