¿best language & platform to automate options trading with ib's api?

Discussion in 'Automated Trading' started by rtw, Jan 6, 2019.

  1. rtw


    good day to everyone.

    i am working on developing a setup to trade options automated with interactive brokers' api and i could use a lot of advice. i have been doing some research into this matter and i now think that c# or python are programming languages that could allow me to create a fully automated algorithmic system to trade options.

    i have used tradestation and ninjatrader to develop and backtest a number of strategies but it is impossible to trade options automated using these platforms. i understand that there are a number of free, open source trading platforms based on both c# and python so i won't have to create a platform from scratch by myself, i would just need to adapt my strategies to either of these programming languages. it is my understanding that ib's api works equally well with c#, python and others, so, i would choose the programming language to work with and the platform to trade with primarily based on which language could best allow me to "dynamically" adjust the contracts to be traded and which platform produced the best results.

    the most important task for my strategies would be to select the options contracts to be traded based on the current price of the underlying stock and the current date. i imagine both c# and python are capable of doing this but it is impossible to accomplish with tradestation or ninjatrader. below is an example of what i have in mind:

    pseudo code for trend following strategies
    - entry -
    when nvda begins uptrend buy 1 nvda call with adaptive strike price and days to expiration at mid market limit
    the nvda call should be selected automatically as (nvda)(expirationdate)c(strikeprice)
    where expiration date can be an input or calculated a number of days (say two weeks) after the current date
    c as this system would try to buy calls on uptrends and puts on downtrends
    strikeprice should be the closest contract available above the price at close when the uptrend began plus an input of a number of points (close + 1, close + 2, etc)
    - exit -
    when nvda ends uptrend sell nvda call at mid market limit
    //in the case of downtrends, the structure would be largely the same but the strike price would be the close minus the number of points

    i imagine that it is possible to have a strategy on c# or python that can intelligently select the instrument to trade from a variety of inputs and data but neither tradestation nor ninjatrader are capable of this. ¿is this correct for c# or python? ¿would any of these programming languages be the most recommendable for tasks like these? ¿and which of the free, open source platforms available (lean, stocksharp, others) would be the most recommendable?

    very well, thanks, regards.
  2. Robert Morse

    Robert Morse Sponsor

    Have you been able to develop an option strategy that is profitable without automation?
  3. rtw


    yes. i use higher time frames and my strategies make 1 or 2 trades per week, i have backtested them extensively and seen the results in real time for months. i want to automate the execution to get myself out of the way and let the strategies run without interference.
  4. Robert Morse

    Robert Morse Sponsor


    I find that those that program love to automate even if manual trading will get better results. Equities and futures are easy to automated because of their market structure. Options are not. Options markets can randomly change in both value and width. How will you determine the price you want to trade at in an automated system without your own option skew? What if at the time you want to exit, markets are wide? If you use the mid-point, that can change even when the stock does not with customer orders. And, what if no MM wants to trade with you at Mid-market? I'm not expecting you to respond, but automated live option trading will not replicate backtesting. 1 to 2 trades a week is not a system that will benefit from automation.

    One more-With an automated system how will you determine what week or month or strike to trade?

    Good luck.

    Last edited: Jan 6, 2019
    janny and Handle123 like this.
  5. rtw




    i do think differently. from my experience, getting fills should not be a problem when trading strategies as slow as mine. and if it became necessary, i could modify the limits to buy at the ask and sell at the bid; the stocks i'm interested in are the most liquid and the entire value of the spread normally is a very manageable 60 usd and usually less.

    regarding the expiration dates, i understand it should be possible to create code that will successfully select the appropriate week it should trade from the current date plus an input with the number of days to expiration one prefers. if this proved impossible or too difficult, i could just input the expiration date by hand every week and all the trades that week could proceed without complication.
  6. Robert Morse

    Robert Morse Sponsor

    It just seems from your description, IMO, automationing the execution is overkill and not increasing your odd of success. I would focus more on the process behind the buy/sell/close signal and automated just that. Then, when you get that buy/sell/close signal, quickly view current markets and make an informed decisions by entering the option order manually.

    When you are only trading a few names, it is easy to leave an order ticket on your desktop ready to change the price and hit send.

    I wish you the best.
    jonahern likes this.
  7. qlai


    For such low frequency strategy, couldn't you simply generate email alerts from your existing platform and have a script which reads email looking for specific command and uses API to send orders? Problem solved!
  8. rtw



    yes. i completely agree with what you write, and actually it is possible to generate custom email alerts from both platforms. the email alerts look like this:

    TradeStation : Chart Analysis Alert for QQQ by -rtw trend following strategy 001 (close, "parameters")
    Info: {"any text message one chooses"}
    Source: -rtw trend following strategy 001 (close,"parameters")
    Occurred: 20-Nov-18 15:15:50
    Price: 158.95

    however, i'm not a programmer and have no idea how i could create a script that traded following email alerts it received. if anyone could point me to some resources where i could find tutorials and examples i think i could build a script as you describe.

  9. qlai


    Start programming a simple script to receive data and sending orders to IB. Once you have to that, add logic to read emails. Or find someone to program it for you.


    I agree with Robert that is an overkill, but a good starting point for someone thinking of taking it further.
  10. What do you call a "platform"? What functions does it have to do for you?
    #10     Jan 7, 2019