This BAG order works with Equity options. Why not with Index Options

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

  1. Hi Community,

    My coder wrote a code to execute a simple call spread for AAPL (call spread described below). It works for other equity options. Why doesn't it work for Index options like NDX and SPX? Why can't I just change 'AAPL' to 'NDX'?

    spread1_contract = Contract()
    spread1_contract.symbol = "AAPL"
    spread1_contract.secType = "BAG"
    spread1_contract.currency = "USD" = "SMART"
    option1 = Option('AAPL', '20200409', 260, 'C', 'SMART', tradingClass='AAPL')
    option2 = Option('AAPL', '20200409', 265, 'C', 'SMART', tradingClass='AAPL')
    contracts = [option1, option2]
    leg1 = ComboLeg()
    leg1.conId = option1.conId
    leg1.ratio = 1
    leg1.action = "BUY" = "SMART"
    leg2 = ComboLeg()
    leg2.conId = option2.conId
    leg2.ratio = 1
    leg2.action = "SELL" = "SMART"
    spread1_contract.comboLegs = []

    ib_call1_order = Order()
    ib_call1_order.orderType = 'SNAP PRIM'
    ib_call1_order.action = 'BUY'
    ib_call1_order.totalQuantity = 3

    trade = ib.placeOrder(spread1_contract, ib_call1_order)
  2. NDX also trades weekly as NDXP and SPX trades weekly as SPXW. That adds to the confusion since I trade weekly - I would need one code for the weekly expiry SPXW and another code if next week is a monthly to trade SPX
  3. Figured it out. There's a mixing of NDX and NDXP in the coding :sneaky:
    Also, looks like with the below code you can't pull data for an expiry farther out than the next monthly expiry. So for example if the next expiry for the monthly NDX is 13th April, then you CAN'T pull data for weekly NDXP for any expiry after that - for some reason.

    spread1_contract = Contract()
    spread1_contract.symbol = "NDX"
    spread1_contract.secType = "BAG"
    spread1_contract.currency = "USD" = "SMART"
    option1 = Option('NDX', '20200409', call1_strike1, call1_type1, 'SMART', tradingClass='NDXP')
    option2 = Option('NDX', '20200409', call1_strike2, call1_type2, 'SMART', tradingClass='NDXP')
    contracts = [option1, option2]