TWS Interactive Brokers API-如何解决“未为请求找到安全定义”?

Fla*_*ape 5 java api tws interactive-brokers

使用Java API(我猜想这适用于任何其他TWS Interactive Brokers客户端API),出现错误“未为请求找到安全定义”。FAQ和其他资源毫无帮助。

    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);
Run Code Online (Sandbox Code Playgroud)

Fla*_*ape 4

这里的关键是contractId字段应该留空。使用 ContractId 提交会导致安全错误。