9

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);
Dragos Durlut
  • 8,018
  • 10
  • 47
  • 62
FlavorScape
  • 13,301
  • 12
  • 75
  • 117

7 Answers7

4

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

FlavorScape
  • 13,301
  • 12
  • 75
  • 117
  • Have you tried this with data for futures? I am getting this error eventhough I gave secType as "FUT" – Avinash Jul 11 '14 at 09:44
  • I can't tell what's wrong unless you show what parameters you're submitting. There's a minimum criteria for futures. https://www.interactivebrokers.com/en/software/api/apiguide/java/how_to_determine_a_futures_contract.htm – FlavorScape Jul 14 '14 at 22:09
  • Contract contract = new Contract(); contract.m_symbol = "C"; contract.m_secType = "FUT"; contract.m_exchange = "CFE"; contract.m_currency = "USD"; contract.m_expiry = "201412"; m_client.reqMktData(12,contract,"",FALSE) – Avinash Jul 16 '14 at 06:45
  • Ok this is messing up the formatting. I think I will ask another question? Or is it clear? – Avinash Jul 16 '14 at 06:47
  • Shouldn't your order be more than an empty string? – FlavorScape Jul 16 '14 at 15:38
  • Contract contract = new Contract(); contract.m_symbol = "USD"; contract.m_secType = "CASH"; contract.m_exchange = "IDEALPRO"; contract.m_currency = "JPY"; this worked in my case – nikolai.serdiuk Oct 19 '14 at 10:28
2

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.

Mate Hegedus
  • 2,887
  • 1
  • 19
  • 30
1

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()
Gregism
  • 392
  • 5
  • 11
1

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.

GGnore
  • 31
  • 3
0

I have had the same issue, but it was because I was not filling the values of SecIdType and SecId.

Here is an example of the order and request that worked:

IBApi.Order order = new IBApi.Order()
{
    Account = OrderCreationConfig.IndividualAccount
    , ClientId = OrderCreationConfig.OrderSlaveClientId //1
    , Action = orderNodeEntity.OrderAction //"BUY"
    , TotalQuantity = orderNodeEntity.NrOfStocks
    , OrderType = OrderCreationConfig.OrderTypeLMT //"LMT"
    , Tif = OrderCreationConfig.OrderTifGTC //"GTC"
    , OcaType = OrderCreationConfig.OcaTypeId //3
    , LmtPrice = price
    , AuxPrice = 0
    , TrailStopPrice = double.MaxValue
    , VolatilityType = 0
    , DeltaNeutralOrderType = "None"
};

IBApi.Contract contract = new IBApi.Contract()
{
      Symbol = orderNodeEntity.Symbol
     , SecType = OrderCreationConfig.ContractSecTypeSTK //"STK"
     , Strike = 0
     , Right = OrderCreationConfig.ContractRightQuestionMark //"?"
     , Exchange = OrderCreationConfig.ContractExchangeIsland //"ISLAND"
     , Currency = OrderCreationConfig.ContractCurrencyUSD //"USD"
     , LocalSymbol = orderNodeEntity.Symbol
     , TradingClass = null        
     , SecIdType = OrderCreationConfig.ContractSecIdTypeISIN //"ISIN"
     , SecId = this.GetISINCode(orderNodeEntity.Symbol) //"US0378331005" 
};
Dragos Durlut
  • 8,018
  • 10
  • 47
  • 62
0

Also make sure to pick the correct lastTradeDateOrContractMonth for your contract. I got the same error when trying to sell an option at a maturity date that was not legit...

Alexander
  • 1,422
  • 11
  • 15
0

Instead of SMART use ISLAND into exchange.

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 = "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);
lonewolf
  • 392
  • 3
  • 10