API to retrieve combo/spreads not options

Discussion in 'Interactive Brokers' started by gtan78, Feb 13, 2025.

  1. gtan78

    gtan78

    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.
     
  2. 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.
     
  3. gtan78

    gtan78

    Just trying to retrieve available list of contracts via API , but it doesn't show the combos available. Just the regular outright contracts
     
  4. What is the exact query you are after?

    I don't use ib_insync. So I can try your query with my own library.
     
  5. gtan78

    gtan78

    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
     
  6. Last edited: Feb 17, 2025
  7. gtan78

    gtan78

    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}")
     
  8. spy likes this.
  9. gtan78

    gtan78

    Thanks vm!
     
  10. spy

    spy

    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
     
    #10     Feb 17, 2025