Skip to content

Commit

Permalink
Fixed AccountMarginExceeded error
Browse files Browse the repository at this point in the history
  • Loading branch information
cjdsellers committed Apr 13, 2024
1 parent c7c1a9e commit 5fee0f9
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 3 deletions.
1 change: 1 addition & 0 deletions RELEASES.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)

---

Expand Down
2 changes: 1 addition & 1 deletion nautilus_trader/accounting/accounts/margin.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down
4 changes: 2 additions & 2 deletions nautilus_trader/accounting/manager.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down

0 comments on commit 5fee0f9

Please sign in to comment.