nautilus_trader icon indicating copy to clipboard operation
nautilus_trader copied to clipboard

Sell order denied due to CUM_NOTIONAL_EXCEEDS_FREE_BALANCE when there is enough balance

Open rubenmarias opened this issue 9 months ago • 3 comments

Bug Report

Expected Behavior

Sell order is submitted without being blocked by the risk engine

Actual Behavior

Risk engine denies an order due to CUM_NOTIONAL_EXCEEDS_FREE_BALANCE even though there is enough balance.

Steps to Reproduce the Problem

  1. Starting balance: 1000000 FDUSD, 0 BTC
  2. Subscribe to provided quote ticks and run provided strategy

Specifications

rubenmarias avatar May 05 '24 19:05 rubenmarias

Hi @rubenmarias

I've been able to reproduce the order denial, I used ETHUSDT as a placeholder instrument here but the starting conditions and maths should be the same I think.

After some buy and sell cycles the first occurrence is here:

2024-04-26T02:02:37.539078627Z [DEBUG] BACKTESTER-001.RiskEngine: Total: Money('0.17814000', ETH)
2024-04-26T02:02:37.539078627Z [DEBUG] BACKTESTER-001.RiskEngine: Locked: Money('0.00000000', ETH)
2024-04-26T02:02:37.539078627Z [DEBUG] BACKTESTER-001.RiskEngine: Free: Money('0.17814000', ETH)
2024-04-26T02:02:37.539078627Z [DEBUG] BACKTESTER-001.RiskEngine: Cumulative notional SELL: Money('0.20000000', ETH)
2024-04-26T02:02:37.539078627Z [WARN] BACKTESTER-001.RiskEngine: SubmitOrder for O-20240426-0202-001-000-625 DENIED: CUM_NOTIONAL_EXCEEDS_FREE_BALANCE: free=0.17814000 ETH, cum_notional=0.20000000 ETH

This looks like an order to sell 0.2 ETHUSDT when the available ETH balance is 0.17814000, does this match the observation you see at this timestamp?

cjdsellers avatar May 06 '24 07:05 cjdsellers

Yes @cjdsellers, a couple things that I didn't mention:

  • when checking the portfolio the current position is enough for the sell
  • by looking at the sequence of buys and sells, the inventory is enough for the sell

thanks

rubenmarias avatar May 06 '24 16:05 rubenmarias

Indeed, I see at that timestamp both the strategy inventory and portfolio.net_position both agree at LONG 0.20702.

cjdsellers avatar May 07 '24 08:05 cjdsellers

Now fixed from ae9677a559c4be36fbeaf017a7ad92e23a82de63.

cjdsellers avatar May 18 '24 00:05 cjdsellers