Lean.Brokerages.InteractiveBrokers
Lean.Brokerages.InteractiveBrokers copied to clipboard
Handle Ambiguous Contract Description
Expected Behavior
If we get the "ambiguous contract description" error, we try to choose the correct contract.
Actual Behavior
LEAN exist.
2025-01-08T17:16:52.0276524Z TRACE:: EventBasedDataQueueHandlerSubscriptionManager.Subscribe(): SPY 250108C00591000 2025-01-08T17:16:52.0285534Z TRACE:: InteractiveBrokersBrokerage.Subscribe(): Subscribe Request: SPY 250108C00591000 2025-01-08T17:16:52.0319947Z TRACE:: InteractiveBrokersBrokerage.GetContractDetails(): SPY 250108C00591000 (OPT SPY USD Smart) 2025-01-08T17:16:52.8429421Z TRACE:: InteractiveBrokersBrokerage.GetContractDetails(): clientOnContractDetails event: OPT SPY USD SMART 20250108 591 C SPY 2025-01-08T17:16:52.8435285Z TRACE:: InteractiveBrokersBrokerage.GetContractDetails(): contracts found: 2 2025-01-08T17:16:52.8468728Z TRACE:: InteractiveBrokersBrokerage.Subscribe(): Subscribe Processed: SPY 250108C00591000 (OPT SPY USD Smart 20250108 591 C) # 5. SubscribedSymbols.Count: 1 2025-01-08T17:16:52.8484828Z TRACE:: DataManager.AddSubscription(): Added SPY 250108C00591000,#0,SPY,Minute,QuoteBar,Quote,Raw,OpenInterest. Start: 1/8/2025 5:16:52 PM. End: 12/31/2050 5:00:00 AM 2025-01-08T17:16:52.8541028Z TRACE:: DataManager.AddSubscription(): Added SPY 250108C00591000,#0,SPY,Minute,TradeBar,Trade,Raw,OpenInterest. Start: 1/8/2025 5:16:52 PM. End: 12/31/2050 5:00:00 AM 2025-01-08T17:16:52.8555233Z TRACE:: DataManager.AddSubscription(): Added SPY 250108C00591000,#0,SPY,Minute,OpenInterest,OpenInterest,Raw,OpenInterest,Internal. Start: 1/8/2025 5:00:00 AM. End: 12/31/2050 5:00:00 AM 2025-01-08T17:16:53.2809796Z TRACE:: EventBasedDataQueueHandlerSubscriptionManager.Subscribe(): SPY 2025-01-08T17:16:53.2814848Z TRACE:: InteractiveBrokersBrokerage.Subscribe(): Subscribe Request: SPY 2025-01-08T17:16:53.2823305Z TRACE:: InteractiveBrokersBrokerage.GetContractDetails(): SPY (STK SPY USD Smart) 2025-01-08T17:16:53.3568480Z TRACE:: InteractiveBrokersBrokerage.HandleError(): RequestId: 5 ErrorCode: 200 - The contract description specified for SPY is ambiguous.. Origin: [Id=5] Subscribe: SPY 250108C00591000 (OPT SPY USD Smart 20250108 591 C) 2025-01-08T17:16:53.3605450Z ERROR:: Brokerage.OnMessage(): Error - Code: 200 - The contract description specified for SPY is ambiguous.. Origin: [Id=5] Subscribe: SPY 250108C00591000 (OPT SPY USD Smart 20250108 591 C)
Potential Solution
N/A. Perhaps we can do something when we find more than one. 2025-01-08T17:16:52.8435285Z TRACE:: InteractiveBrokersBrokerage.GetContractDetails(): contracts found: 2
Reproducing the Problem
# region imports
from AlgorithmImports import *
# endregion
class AmbiguousContractDescription(QCAlgorithm):
def initialize(self):
self.set_start_date(2025,1,8)
self.add_option_contract(
Symbol.create_option(
Symbol.create("SPY", SecurityType.EQUITY, Market.USA), Market.USA,
OptionStyle.AMERICAN, OptionRight.CALL, 591, self.start_date
)
)
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