Trying to get IB to accept a multi-leg combo options order: no luck so far

Discussion in 'App Development' started by badIRAbad, Sep 21, 2019.

  1. badIRAbad

    badIRAbad

    I've got a project to automate some trades that are all multi-leg options trades: short strangles, iron condors, double calendars, etc.

    I have both the Python and the C++ versions of the Interactive Brokers' TWS API running and working for sending single options orders.

    I first tried the Python version trying to get combination order going: no luck at all. Just "you are not connected" error code 504 ... when the log file shows I was connected up to that point. Clearly some rogue parameter I have but I didn't see what.

    I gave up on the Python version and tried the C++ sample code; it runs a test suite and even has an old one of the multileg orders in its sample set that I just had to uncomment to get to run.

    Of course, this didn't work since the options dates were from 2016 and I got a reasonable sort of error in the logs:

    Code: 200, Msg: No security definition has been found for the request

    I tried substituting a new options chain for this old one:

    #ifdef BAD
    Contract ContractSamples::OptionComboContract(){
    //! [bagoptcontract]
    std::cerr << "Option Combo!---------------------------------" << std::endl ;
    Contract contract;
    contract.symbol = "AAPL";
    contract.secType = "BAG";
    contract.currency = "USD";
    contract.exchange = "BOX";

    ComboLegSPtr leg1(new ComboLeg);
    leg1->conId = 353810203;
    //leg1->localSymbol = "C AAPL Oct 18 215"
    leg1->action = "BUY";
    leg1->ratio = 1;
    leg1->exchange = "BOX";

    ComboLegSPtr leg2(new ComboLeg);
    leg2->conId =353810186;
    //leg2->localSymbol = "C AAPL Oct 18 220"
    leg2->action = "SELL";
    leg2->ratio = 1;
    leg2->exchange = "BOX";

    contract.comboLegs.reset(new Contract::ComboLegList());
    contract.comboLegs->push_back(leg1);
    contract.comboLegs->push_back(leg2);
    //! [bagoptcontract]
    return contract;
    }

    #else

    Contract ContractSamples::OptionComboContract(){
    //! [bagoptcontract]
    Contract contract;
    contract.symbol = "DBK";
    contract.secType = "BAG";
    contract.currency = "EUR";
    contract.exchange = "DTB";

    ComboLegSPtr leg1(new ComboLeg);
    leg1->conId = 197397509;
    leg1->action = "BUY";
    leg1->ratio = 1;
    leg1->exchange = "DTB";

    ComboLegSPtr leg2(new ComboLeg);
    leg2->conId = 197397584;
    leg2->action = "SELL";
    leg2->ratio = 1;
    leg2->exchange = "DTB";

    contract.comboLegs.reset(new Contract::ComboLegList());
    contract.comboLegs->push_back(leg1);
    contract.comboLegs->push_back(leg2);
    //! [bagoptcontract]
    return contract;
    }
    #endif


    ... and I get no useful error message for this one at all.

    Anybody got this working (in Python or C++ or Java)? I am stuck ...

    Any suggestions would be greatly appreciated!
     
  2. badIRAbad

    badIRAbad