Futures calendar spreads on TWS excel API

Discussion in 'Automated Trading' started by TraDaToR, Dec 29, 2009.

  1. TraDaToR



    I already asked this question about one year ago, but nobody answered.

    How can you retrieve datas and submit orders on calendar spreads using TWS DDE API?

    I understand how to get combination quotes by giving an id to each contract of the spread and defining a combination using contract ids, but I don't think it will give the actual calendar spread contract datas, but a combination of outrights instead.

    Does someone trade calendar spreads through TWS API?

    Thanks a lot for your help.
  2. I do. Not calendar spreads per se, but inter market spreads (say long ES, short NQ) (which is kicking my arse pretty bad right now, but that's another story). My spreadsheet simply fires off market orders when spreads reach where I need them to be. I can order long march short june for same futures if I wanted to using the same spreadsheet. So yes, it can be done with some modification of the spreadsheet IB provides.

    I do not have a problem making the excel sheet available, but it literally is put together using duct tape - only I know how to work it. If I ever clean it up, I can make it available, but not as is.
  3. TraDaToR


    Thanks Darth Sidious, but I want to trade the actual calendar spread contract and not a combo of different expiries. I want to place limit orders in the calendar spread book.
  4. OK. Tell me what specific order you would place and how using TWS, and I will try to look up if that can be done using Excel DDE to TWS
  5. TraDaToR



    For example, Corn calendar spread - MAR 10 + MAY 10 has a 9 3/4 - 10 spread currently with 1204 bid and 5710 offered.

    I would like to submit a limit buy order @ 9. You can submit this spread contract through spread trader or creating a ZC + comb + ECBOT + calendar spread ticker
  6. I did the getting quote part. You should be able to extend it to placing order too. This is the standard excel file IB supplies as part of the API download.

    Take a look at http://institutions.interactivebrokers.com/php/apiguide/interoperability/dde_excel/dde_combo.htm for very good info.

    Test this on a paper trading account first, make sure TWS is configered to allow DDE etc. - you know the drill.

    Open the excel file I have attached. Ignore any errors for now. It will also look for, and offer to start CHANGEME.EXE. Decline.

    In the Tickers tab, do a search & replace: replace all CHANGEME with your TWS user id (NOT your account number). So if you normally login with user id bbernanke99, you will replace CHANGEME with bbernanke99. Cell B5, and all formula's in row 34 & 35 will be affected. SAVE & close the excel file.

    Open up the file again. You should be getting quotes in row 34 for regular ES, and in row 35 for your spread.

    Study what you have in K35, and you should be able to rig something to place the order too. (methinks, but can't be sure without trying)

    PS: You can also get the contract id's by right clicking on the legs in TWS and "Contract Info > Details"
    eusdaiki likes this.
  7. TraDaToR


    Damn , Darth Sidious you are a godsent. Thank you very much for your help.

    I thought the id was one you had to create for every contract, not the conid that is in the contract details. It's easier than I thought.

    I cannot open your spreadsheet right now as I have an other one running on the API . I hope teh quotes refer to the spread contract and not combo of legs. If ask and bid size are 1000's , it's the spread contract. If they are 10's, it's a generic combo.

    Thanks a lot agian for your help.
  8. thansk for the page Darth, Im interested in creating my own spreads similar to what you are doing. Any tips on the coding required to fire off the 2 orders?