Lean.Brokerages.InteractiveBrokers
Lean.Brokerages.InteractiveBrokers copied to clipboard
NormalizePriceToBrokerage Improvements
Expected Behavior
Receive a message when the NormalizePriceToBrokerage method changes the price.
Actual Behavior
We are not notified about the change.
Potential Solution
Implement the same logic from Lean.
Reproducing the Problem
User algorithm placed the following trades:
Buy Leg: SPXW 240401P05150000, Strike: 5150.0, Bid: 0.0, Ask: 0.05, Last Price: 0.05 Sell Leg: SPXW 240401P05200000, Strike: 5200.0, Bid: 0.1, Ask: 0.2, Last Price: 0.1 Quantity: 1 Limit Price: -0.12 Time: 20240401 14:11:00.672 UTC
Reproduceable by the following algorithm:
class CrawlingFluorescentYellowGorilla(QCAlgorithm):
def Initialize(self):
self.SetStartDate(2024,3,28)
self.SetCash(100000)
index = self.AddIndex("SPX").Symbol
self.legs = [
Leg.Create(Symbol.CreateOption(index, "SPXW", Market.USA, OptionStyle.European, OptionRight.Put, 5150, datetime(2024,4,1)), 1),
Leg.Create(Symbol.CreateOption(index, "SPXW", Market.USA, OptionStyle.European, OptionRight.Put, 5200, datetime(2024,4,1)), -1)
]
[self.AddIndexOptionContract(leg.Symbol) for leg in self.legs]
def callback():
self.tickets = self.ComboLimitOrder(self.legs, 1, -0.12)
self.Schedule.On(self.DateRules.On(2024,4,1), self.TimeRules.At(14,11, TimeZones.Utc), callback)
However, the order arrived with limit price of -0.1, so there was a rounding from -0.12 to -0.1.
The rounding was not made by LEAN as we observe when we run a backtest with this code, so the NormalizePriceToBrokerage method rounded it down.
This method uses the GetMinTick method to look for the minimum price variation in the Contract. This information comes from Interactive Brokers. We should log both when NormalizePriceToBrokerage, and GetMinTick value.
If the minimum value is 0.05 for SPXW under $3, their API has a bug.
Checklist
- [x] I have completely filled out this template
- [x] I have confirmed that this issue exists on the current
masterbranch - [x] I have confirmed that this is not a duplicate issue by searching issues
- [x] I have provided detailed steps to reproduce the issue
For combo orders, we could assume the minimum tick is 0.01.