QuantConnect / Lean.Brokerages.InteractiveBrokers

InteractiveBrokers Brokerage Plugin
Apache License 2.0
35 stars 22 forks source link

Lean logs have 'UnrealisedPnL' and 'RealisedPnl' backwards #112

Open tmills86 opened 6 months ago

tmills86 commented 6 months ago

Expected Behavior

Lean logs should be showing UnrealisedPnl and RealisedPnl in their respective columns.

Actual Behavior

The logs have these two swapped. An example of the output I'm getting on my server looks like this:

2024-05-08T13:44:01.4882395Z TRACE:: InteractiveBrokersBrokerage.HandlePortfolioUpdates(): Contract: FUT MNQ USD , ConId: 620730945, Position: 0, MarketPrice: 18119.859375, MarketValue: 0, AverageCost: 0, UnrealisedPnl: 87.06, RealisedPnl: 0, AccountName: U########

As you can see, my position is 0, but I'm getting an UnrealisedPnl of 87.06, when this should be in the RealisedPnl column.

Reproducing the Problem

Take any position on interactive brokers and then close it. The UnrealisedPnl and RealisedPnl columns will be swapped.

System Information

Ubuntu 22.04.4 LTS

Checklist

jaredbroad commented 6 months ago

I think this might be a bug in IB: we just log the packet: https://github.com/QuantConnect/Lean.Brokerages.InteractiveBrokers/blob/dd264cf3470942151649005e921c129c68747a34/QuantConnect.InteractiveBrokersBrokerage/InteractiveBrokersBrokerage.cs#L2456C59-L2457C10

Log.Trace($"InteractiveBrokersBrokerage.HandlePortfolioUpdates(): {e}");