Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

TWS Interactive Brokers API - How to fix "No security definition has been found for the request"?

Using the Java API (and I guess this goes for any other TWS Interactive Brokers client API) I get an error "No security definition has been found for the request" The FAQ and other resources were resoundingly unhelpful.

    Contract contract = new Contract();

    int id = incId;           

    System.out.println("Oder Id " + id );

    // use UTC seconds as transaction id

    // This is the problem you need to have a blank contractId
    contract.m_conId = 12345;
    contract.m_symbol = signal.symbol;
    contract.m_secType = "STK";
    contract.m_expiry = "";
    contract.m_strike = 0;
    contract.m_exchange = "SMART";
    contract.m_primaryExch = "ISLAND";
    contract.m_currency = "USD";

    //etc

    Order order = new Order();

    // set order fields
    order.m_account = "XXXXXX";
    order.m_orderId = id;
    //etc

    GetInstance().wrapper.m_client.placeOrder(id, contract, order);
like image 982
FlavorScape Avatar asked Dec 12 '13 19:12

FlavorScape


4 Answers

The key here is that the contractId field should be left blank. Submitting with a contractId causes a security error.

like image 109
FlavorScape Avatar answered Oct 13 '22 01:10

FlavorScape


It was solved for me by setting the exchange to "SMART".

My use case was getting all the contracts I am currently holding and sending a MOC order. I got the contract using the reqPositions method, but the Contracts in those return values still gave this error.

Setting exchange to SMART on these contracts solved the issue for me.

like image 41
Mate Hegedus Avatar answered Oct 12 '22 23:10

Mate Hegedus


In some cases the exchange needs to be left blank. I had some luck using this lookup:

https://pennies.interactivebrokers.com/cstools/contract_info/v3.9/index.php

For instance, for CL:

con.connect()

contract = Contract()
contract.m_symbol = "CL"
contract.m_exchange = ""
contract.m_currency = "USD"
contract.m_secType = "FUT"

con.reqContractDetails(1, contract)

time.sleep(2)

con.disconnect()
like image 23
Gregism Avatar answered Oct 12 '22 23:10

Gregism


Other possible reasons for this error may include:

-The ConId should be set to 0.

-The TradingClass should be left blank.

-Issues with the LocalSymbol or GlobalSymbol.

-Other Contract variables were incorrectly set.

-The specific contract requested doesn't currently exist on the market.

like image 30
GGnore Avatar answered Oct 13 '22 01:10

GGnore