issue retrieving data from interactive brokers

6 views (last 30 days)
i'm using matlab 2021b with the most recent IB TWS, the example code provided by mathworks seems to run fine (no errors are produced), but no data is retrieved from IB.
%% connect to IB TWS
clear all; close all; clc
ib = ibtws('',7497);
%% Create the IContract Object
ibContract = ib.Handle.createContract;
ibContract.symbol = 'MSFT';
ibContract.secType = 'STK';
ibContract.exchange = 'SMART';
ibContract.primaryExchange = 'NASDAQ';
ibContract.currency = 'USD';
d = getdata(ib,ibContract)
%% request last 20 days of data
bizDayConvention = 13; % i.e. BUS/252
currentdate = today;
startDate = daysadd(currentdate,-20,bizDayConvention);
endDate = daysadd(currentdate,-1,bizDayConvention);
%%
histTradeData = history(ib,ibContract,startDate,endDate);
the same problem occurs when trying to retrieve live market data and create orders.
On a seperate note if someone from mathworks sees this, the documentation regarding Interactive Brokers needs updating/more detail adding as there is no documentation provided by IB for MATLAB.

Answers (1)

Shivam Lahoti
Shivam Lahoti on 3 Nov 2023
Hi Philip Curran,
As per my understanding, you want to use the ibtws” function. As stated in the question, you are able to extend the connection to IB TWS but facing difficulty while retrieving the data.
Please try the steps mentioned in the answer attached below and observe if it solves your problem. Though it does not throw an error for your connection step, following the mentioned steps might help in retrieving the data, as the answer discusses about using this functionality in releases after r2021a.
Have a look at the references attached below as they discuss the similar issue.
I hope this helps.
Regards,
Shivam Lahoti.

Categories

Find more on Financial Toolbox in Help Center and File Exchange

Products


Release

R2021b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!