softwarespartan / IB4m

Interactive Brokers API for Matlab
GNU General Public License v2.0
62 stars 21 forks source link

ContractFactory.GenericStockContract does not return proper variables #81

Closed Burrguy closed 4 years ago

Burrguy commented 4 years ago

I am running OptionsComputationsIB4m.m

% configure buffers for contract details, market data, and options computations
[detailsBuf ,detailslh] = TWS.initBufferForEvent(TWS.Events.CONTRACTDETAILS  );
[   dataBuf ,   datalh] = TWS.initBufferForEvent(TWS.Events.MARKETDATA       ,10000);
[    optBuf ,    optlh] = TWS.initBufferForEvent(TWS.Events.OPTIONCOMPUTATION,10000);

% initialize session with TWS
session = TWS.Session.getInstance();

% connect to TWS
session.eClientSocket.eConnect('127.0.0.1',7496,0);

% create generic contract contract object
contract = com.tws.ContractFactory.GenericStockContract('IBM');

% change security type to "option"
contract.m_primaryExch = []; contract.m_secType='OPT';

The code fails on the last line, with this error: No public field m_primaryExch exists for class com.ib.client.Contract.

Error in OptionsComputationsIB4m (line 21) contract.m_primaryExch = []; contract.m_secType='OPT';

Because the GenericStockContract does not contain either variable listed above the code fails

This is what contract does contain: val =

conid 0 symbol IBM strike 0.0 exchange SMART currency USD primaryExch ISLAND

I suppose this could be because the wrong API version is installed, I have matlab R2018b installed, build 978,1g if TWS and the latest API.

Also ver -java: Operating System: Microsoft Windows 7 Professional Version 6.1 (Build 7601: Service Pack 1) Java Version: Java 1.8.0_152-b16 with Oracle Corporation Java HotSpot(TM) 64-Bit Server VM mixed mode

softwarespartan commented 4 years ago

Thanks for reaching out @Burrguy

This example is still using the old API syntax. Apologies for any confusion. I thought I updated all of them for new +9.73 API but guess I missed this one. The only change here is how the contract is defined.

contract = com.ib.client.Contract();
contract.symbol('IBM')
contract.primaryExch([]);
contract.currency('USD');
contract.secType('OPT');

Let me know if you find other issues.

softwarespartan commented 4 years ago

@Burrguy closing this but feel free to reopen if not resolved