nautechsystems / nautilus_trader

A high-performance algorithmic trading platform and event-driven backtester
https://nautilustrader.io
GNU Lesser General Public License v3.0
2.02k stars 462 forks source link

`free` amount was negative #1770

Closed a4399518s closed 3 months ago

a4399518s commented 3 months ago

Bug Report

File "nautilus_trader/portfolio/portfolio.pyx", line 161, in nautilus_trader.portfolio.portfolio.Portfolio.initialize_orders File "nautilus_trader/portfolio/portfolio.pyx", line 204, in nautilus_trader.portfolio.portfolio.Portfolio.initialize_orders File "nautilus_trader/accounting/manager.pyx", line 168, in nautilus_trader.accounting.manager.AccountsManager.update_orders File "nautilus_trader/accounting/manager.pyx", line 244, in nautilus_trader.accounting.manager.AccountsManager._update_balance_locked File "nautilus_trader/accounting/accounts/cash.pyx", line 126, in nautilus_trader.accounting.accounts.cash.CashAccount.update_balance_locked File "nautilus_trader/accounting/accounts/cash.pyx", line 165, in nautilus_trader.accounting.accounts.cash.CashAccount._recalculate_balance File "nautilus_trader/model/objects.pyx", line 1593, in nautilus_trader.model.objects.AccountBalance.init File "nautilus_trader/core/correctness.pyx", line 58, in nautilus_trader.core.correctness.Condition.true ValueError: free amount was negative

Expected Behavior

Add here...

Actual Behavior

Add here...

Steps to Reproduce the Problem

  1. Save 10 USDT and 100 FIL in your account.
  2. 100 fils per order, no guarantee of success.
  3. Transportation agency code.

code: File: /root/project/nautilus_trader/nautilus_trader/accounting/accounts/cash.pyx Line 100: Use the update_balance_locked method. Locked at 100 USDT. (Affected by the unit) Line 149: When using the _recalculate_balance method to adjust the balance, use USDT surplus of 10 - chain constant amount of 100 to get a negative number. The program is abnormally exited.

Specifications

cjdsellers commented 3 months ago

Hi @a4399518s

There's not quite enough information here to look into this. If this was during a backtest and the free balance went negative then the exit is expected. If a cash account has been configured and there's some cross-asset interaction then it's potentially unsupported.

I can look into this further if you're able to provide a code snippet.