QuantConnect / Lean.Brokerages.InteractiveBrokers

InteractiveBrokers Brokerage Plugin
Apache License 2.0
27 stars 17 forks source link

GetContractDetails Delay Order Execution #48

Open AlexCatarino opened 1 year ago

AlexCatarino commented 1 year ago

Expected Behavior

When the algorithm places an order, the contract details should have been cached before.

Actual Behavior

The contract details are fetched before we place the orders. If we subscribe to Interactive Brokers' data, fetch and cache this information on subscribe. On the other hand, if we use an alternative feed, e.g. QuantConnect's, the contract details are requested to IB before the orders are placed.

Potential Solution

Perhaps we could fetch them during the heartbeats.

Reproducing the Problem

Deploy live algorithm with QuantConnect data and place one order to open a position and another to close it. The roundtrip time of the first will be longer. See in the syslog that GetContractDetails is called before the first order.

Checklist

AlexCatarino commented 1 year ago

An algorithm placed limit orders to force getting contract details to cache them and the speed increased. 20 orders that fetched contract details took 3.5 seconds against 1.5 seconds of 20 orders that didn't fetch it.