Having trouble with Futures Contracts in IB TWS API

Discussion in 'Automated Trading' started by IAS_LLC, Oct 18, 2013.

  1. IAS_LLC

    IAS_LLC

    Hello,

    I am in the process of developing my automated trading platform (unix c++) that will interface with the IB TWS API (I'm very early in the process). Right now I am working with a demo account to work out all of the bugs in my software out. I have been able to succefully get quotes and place trades for stocks and options, but am having trouble with futures and currencies.

    I get the following error when I perform m_pClient->reqContractDetails(2000,MyContract)

    "Error id=2000, errorCode=200, msg=No security definition has been found for the request"


    MyContract is defined as follows for the futures contract:

    MyContract.symbol = "6EZ3"; // CME Euro-USD fture
    MyContract.secType = "FUT";
    MyContract.expiry = "201312"; // I have also tried 20131216, which is what tws lists
    MyContract.strike = 0.0; // This shouldn't matter...
    MyContract.right = ""; // Not defining this.... shouldnt matter
    MyContract.multiplier = "125000";
    MyContract.exchange = "GLOBEX";
    MyContract.currency = "USD";


    And MyContract is defined as follows for the FOREX contract.

    MyContract.symbol = "EUR.USD"; // FOREX EUR/USD
    MyContract.secType = "CASH";
    MyContract.expiry = ""; // I have also tried 20131216, which is what tws lists
    MyContract.strike = 0.0; // This shouldn't matter...
    MyContract.right = ""; // Not defining this.... shouldnt matter
    MyContract.multiplier = "";
    MyContract.exchange = "IDEALPRO";
    MyContract.currency = "USD";


    What am I doing wrong? Any help would be greatly appreciated!!

    Thanks,
    Brad
     
  2. IAS_LLC

    IAS_LLC

    I figured out the problem.

    For the Futures contract, the symbol is just "EUR". And for the the FOREX, it is also "EUR"

    Its unfortunate that the the symbols listed in TWS don't match the way the must be defined for the API. I found the contract search feature on IBs website much more helpful.

    I do find it troubling that I can define a E-Micro EUR/USD contract in two different ways.... I can say <"EUR","FUT",12500> or <"M6E","FUT",12500> .... scary. Looks like I better be EXTREMELY careful when defining contracts.

    Thanks,
    Brad
     
  3. It's been awhile since I've messed with the IB API, but I remember these type of problems can be frustrating.

    Have you tried on both paper and demo account? Could be differences, but probably not.

    What if you open a position on the demo account for the security you are looking for and then request the portfolio positions? You can then examine the various fields to see what TWS has populated for the contract details when the portfolio events return.
     
  4. IB has two sets of symbols for lots of things. I forget why but it causes major headaches if you use the wrong symbol.
     
  5. slumdog

    slumdog

    In java i set the localSymbol='6EZ3' field in the Contract object and leave the symbol field blank.

    And i set the expiry to "".

    I dont know if this is best practice, but 6EZ3 is pretty unambiguous.
    My code has been like that for years and still works.

    There is an option to see the local symbol columns in the main TWS grid, some local symbols have spaces i think 'YM DEC 13' has 3 spaces between the YM and the DEC or something.
     
    None Business likes this.
  6. Just glancing briefly at your code, one issue I see is you symbol definition.

    So for example: EDZ3 (Dec 13 Eurodollar futures)

    Local symbol is EDZ3 and Symbol is ED.

    Within TWS check the contract details, that should help.
     
  7. IAS_LLC

    IAS_LLC

    Yeah, I realized that. Thanks for the help everyone. Your comments are all very helpful!
     
  8. If you want you can also use the local symbol notation to retrieve an instrument.

    (But I think IB got it right, this way is more intuitive and usable)

    This is a file with examples of symbols I use for my application:
    http://www.datatime.eu/public/gbot/GBOT_Tickers.txt
    (see near the bottom)

    (I even allow the use of contractID alone, which in some occasions can be pretty useful.)
     
  9. Thanks for this.