Not possible to request bid/ask of an option spread using IB API

Discussion in 'Automated Trading' started by yosuji198, Mar 20, 2020.

  1. yosuji198

    yosuji198

    Hi Community,

    I am coding a trading algo and trying to find a way to pull the bid/ask for a an equity option call spread - in Python using ib_insync.

    Code Below:
    whatsmyprice = ib.reqTickByTickData(spread_contract, "BidAsk", 0, True)
    print(whatsmyprice)

    Result:

    Error 321, reqId 88: Error validating request:-'bZ' : cause - 'BAG' security type is not supported in ReqTickByTick(97) request, contract: Contract(secType='BAG', symbol='AAPL', exchange='SMART', currency='USD', comboLegs=[ComboLeg(conId=403136034, ratio=1, action='BUY', exchange='SMART', openClose=0, shortSaleSlot=0, designatedLocation='', exemptCode=-1), ComboLeg(conId=403136060, ratio=1, action='SELL', exchange='SMART', openClose=0, shortSaleSlot=0, designatedLocation='', exemptCode=-1)])

    However, the TWS system is able to display the bid/ask and midpoint of option spreads in TWS. How can I pull bid, ask and midpoint using ib_insync API or IB API?
    upload_2020-3-20_14-21-16.png

    Thanks Community!!
     
  2. xandman

    xandman

    We see the use of BAG for SecType. Perhaps, you should be using "OPT" for stock options.
     
    TooEffingOld likes this.
  3. yosuji198

    yosuji198

    My coder figured it out. The problem was the ib.reqTickByTickData

    Solution:
    data = ib.reqTickers(spread_contract)
    print('ask_price: ', data[0].ask)
    print('bid_price: ', data[0].bid)
     
    xandman likes this.