Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Try to Reconcile State #136

Open
4 tasks done
AlexCatarino opened this issue Dec 17, 2024 · 0 comments
Open
4 tasks done

Try to Reconcile State #136

AlexCatarino opened this issue Dec 17, 2024 · 0 comments
Labels
enhancement New feature or request

Comments

@AlexCatarino
Copy link
Member

Expected Behavior

The algorithm state matches the IB portfolio,

Actual Behavior

We have observed the following case:

No positions at 5:21Z:

2024-11-26T05:21:37.3783447Z TRACE:: InteractiveBrokersBrokerage.HandlePortfolioUpdates(): Contract: FUT MNQ USD , ConId: 654503320, Position: 0, MarketPrice: 20873.5, MarketValue: 0, AverageCost: 0, UnrealisedPnl: 0, RealisedPnl: 0, AccountName: U8888888

Sell 1 unit at 14:30:00Z

2024-11-27T14:30:00.6864126Z TRACE:: BrokerageTransactionHandler.Process(): 11/27/2024 14:30:00 UTC: Submit Order: (51) - OrderId: 51 (BrokerId: ) New Market order for -1 units of MNQ YOGVNNAOI1OH Status: Unprocessed

Rejected by IB at 14:30:01Z

2024-11-27T14:30:01.0118024Z TRACE:: LiveTradingResultHandler.OrderEvent(): Time: 11/27/2024 14:30:01 OrderID: 51 EventID: 2 Symbol: MNQ20Z24 Status: Invalid Quantity: -1 Message: 201 - Order rejected - reason:The Available Funds in your Commodities segment are insufficient to cover the change in the margin requirements in your Commodities segment should this order execute. In order to obtain the desired position, your Commodities Net Liquidation Value [2673.60 USD] must exceed the new total initial Margin of [4348.07 USD].. Origin: [Id=52] IBPlaceOrder: MNQ20Z24 (FUT MNQ USD CME 20241220 0 ) BrokerId: 52

By then, IB tell us there is an open short position.

2024-11-27T14:30:01.5744480Z TRACE:: InteractiveBrokersBrokerage.HandlePortfolioUpdates(): Contract: FUT MNQ USD , ConId: 654503320, Position: -1, MarketPrice: 20936.9003906, MarketValue: -41873.8, AverageCost: 41873.88, UnrealisedPnl: 0, RealisedPnl: 0.08, AccountName: U8888888

At 16:45, we place an order to open a long position:

2024-11-27T16:45:00.2486565Z TRACE:: LiveTradingResultHandler.OrderEvent(): Time: 11/27/2024 16:45:00 OrderID: 53 EventID: 2 Symbol: MNQ20Z24 Status: Filled Quantity: 1 FillQuantity: 1 FillPrice: $20725.75 OrderFee: 0.62 USD Message: Interactive Brokers Order Fill Event BrokerId: 54

which closes the position:

2024-11-27T16:45:01.2083719Z TRACE:: InteractiveBrokersBrokerage.HandlePortfolioUpdates(): Contract: FUT MNQ USD , ConId: 654503320, Position: 0, MarketPrice: 20726.25, MarketValue: 0, AverageCost: 0, UnrealisedPnl: 421.76, RealisedPnl: 0, AccountName: U8888888

We should see the mismatch that occurred at 2024-11-27T14:30:01.5744480Z.

Potential Solution

Check HandlePortfolioUpdates for inconsistencies. Exit the algorithm.

Reproducing the Problem

Underterminitic. Bug on IB side.

Checklist

  • I have completely filled out this template
  • I have confirmed that this issue exists on the current master branch
  • I have confirmed that this is not a duplicate issue by searching issues
  • I have provided detailed steps to reproduce the issue
@AlexCatarino AlexCatarino added the enhancement New feature or request label Dec 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant