Hi, Re futures, not options Does anyone know if it is possible to retrieve 'native' spreads , those that have an orderbook on the exchange, not the smart combo type orders legged by the broker. I haven't had luck with ib_insync code using python.
To my knowledge, for options you don't even have access to the complex order book from TWS or any other front-tend of IB, so probably also not from the API. (There is a "complex orders and trade scanner" in TWS, but is seems to be dysfunctional. I'm not sure why IB releases dysfunctional features to their customers.) I think the futures complex order books are available via subscription, at least the top of book.
Just trying to retrieve available list of contracts via API , but it doesn't show the combos available. Just the regular outright contracts
What is the exact query you are after? I don't use ib_insync. So I can try your query with my own library.
Hi contract_details = ib.reqContractDetails(contract) # Output all available expiration dates for details in contract_details: print(f"Symbol: {details.contract.symbol}, {details.contract.lastTradeDateOrContractMonth}" Only shows contracts but not combo spreads
Are you trying to replicate what is on this page? https://www.interactivebrokers.com/campus/trading-lessons/creating-futures-spreads-in-tws/
Yes, trying to replicate a Futures spread. But not trying to use the "SMART" system to create a custom spread. There should be regular spreads traded on the exchange symbols = ['MCH.HK'] exchange = 'HKFE' # Function to retrieve spreads for a given symbol def get_spreads(symbol): print(f"\nFetching spreads for {symbol}...") # Define the base contract (e.g., futures contract) contract = Contract() contract.symbol = symbol contract.secType = 'FUT' # Futures contract.exchange = exchange contract.currency = 'HKD' # Adjust currency if needed # Search for contracts matching the symbol and exchange matching_contracts = ib.reqContractDetails(contract) if not matching_contracts: print(f"No contracts found for {symbol} on {exchange}.") return # Print available contracts print(f"Available contracts for {symbol}:") for i, contract_detail in enumerate(matching_contracts): print(f"{i + 1}. {contract_detail.contract.localSymbol} - {contract_detail.contract.lastTradeDateOrContractMonth}")
ok, as far as I understand you are fine with the definitions of the contracts as they are because the contract itself is not going to give you the combos that you could build. Once you have two contracts, you can build a futures spread order as on this page: https://interactivebrokers.github.io/tws-api/spread_contracts.html A detailed explanation on this page as well: https://www.interactivebrokers.com/campus/trading-lessons/python-complex-orders/
This plus, I assume you have the proper data/trading permissions (duh). If you can find them in TWS then you should be able to find them via API. But, yeah... at a minimum it seems like you're not filling in enough detail to make reqContractDetails happy. I.E: no combolegs and "it is required to know the conId of the contract in question" (1) Good luck