Error with " Request Interactive Brokers Historical Data" example

I am receiving an error when I follow the help example Request Interactive Brokers Historical Data.
ib = ibtws('',7496) %
ibContract = ib.Handle.createContract;
ibContract.symbol = 'IBM';
ibContract.secType = 'STK';
ibContract.exchange = 'SMART';
ibContract.primaryExchange = 'NYSE';
ibContract.currency = 'USD';
getdata(ib,ibContract)
startdate = floor(now) - 5;
enddate = floor(now);
d = history(ib,ibContract,startdate,enddate)
the output:
ans =
struct with fields:
LAST_PRICE: 145.19
LAST_SIZE: 1.00
VOLUME: 23572.00
BID_PRICE: 145.19
BID_SIZE: 5.00
ASK_PRICE: 145.20
ASK_SIZE: 3.00
d =
'No historical data query found for ticker id:975'
However the API error logs:
11:25:22:998 <- 20-975-0-IBM-STK--0---SMART-NYSE-USD---0-20180728 00:00:00-1 day-6 D-0-TRADES-1-0--
11:25:23:143 -> --17-975-20180722 00:00:00-20180728 00:00:00-6-20180720-149.11-149.50-146.10-146.25-56435-147.146-31676-20180723-146.26-146.70-145.01-145.85-31681-145.653-17672-20180724-145.73-147.04-145.73-146.05-33764-146.483-18819-20180725-145.80-146.91-145.50-145.80-30822-146.152-19893-20180726-146.74-149.27-146.34-147.48-42520-147.469-23727-20180727-146.93-147.36-144.66-145.19-19673-145.926-13840-
11:25:23:147 <- 25-1-975-
11:25:23:148 -> ---=4-2-975-366-No historical data query found for ticker id:975-
11:25:23:148 <- 25-1-975-
11:25:23:148 -> ---=4-2-975-366-No historical data query found for ticker id:975-
using 2018a with API 9.73.07
It doesn't matter the dates(1 day 10 days ago) or securities I try is still get the same error. Also Timeseries does not work a well, the API logs shows the data but the no historical data error.

답변 (3개)

John Pries
John Pries 2018년 10월 25일

0 개 추천

Anyone solve this issue. I've got it too. It seems like 'historicalDataEnd' event is happening before 'historicalData' and closing event listeners and clearing persistent variables ...
Scott Meier
Scott Meier 2018년 11월 9일
I believe the second line of code shown below is missing from the timeseries.m file. I'm using 2018b. I copied this line from the 2017a version.
case 'historicalDataEnd'
assignin('base','ibBuiltInIntraDayData',ibBuiltInIntraDayData);
% Clear persistent variables and event listeners
clear ibBuiltInIntraDayDataCounter ibBuiltInIntraDayData

댓글 수: 5

Hi Scott,
Nice, the timeseries.m file can work now by adding the 2nd line of code you mentioned.
history.m also do not work, do you have any suggestions on where can be changed to make it work ?
Thanks !
Hi Terry, I did not have any issues with the history.m file. I used it as is.
Hi Scott,
i added a simillar line to the history.m file, it works now (maybe it works without this line as well) .
case 'historicalDataEnd'
assignin('base','ibBuiltInHistoricalData',ibBuiltInHistoricalData);
%Historical data end event
% Clear persistent variables and event listeners
clear ibBuiltInHistoricalDataCounter ibBuiltInHistoricalData
Sadly i noticed a new problem with IB connection, sometimes when i request data (using either getdata history or timeseries ), the code stuck in the while loop:
while c.DataRequest
drawnow
end
i suspect it happend due to using " ib = ibtws('',7496)" , i may have connect + disconnect from TWS too often ?? the only solution to make data request work again, is to quit Matlab, and re-launch Matlab
have you experienced the same problem before ?
Thanks
Terry
Yes, I experienced this often in the beginning, possibly from making too many history requests in a short time. If you use the IB Gateway instead of TWS, you can view the API messages and this can give a clue as to what's happening. It may be possible in TWS, but I'm not sure how to do that.
Hi Scott,
you can view the TWS log book, in TWS, go to Classic TWS view, then account->Diagnostics -> view TWS log book,
then you can export today's log book, in the file, there are details of messages, although i cant' understand very much.
the problem i have now, is still data request freeze, when i reconnect and reconnect from TWS, this doesnt happend with API 971, later version of API, stuck all the time................... this is such a big headache to me
best regards
Terry

댓글을 달려면 로그인하십시오.

Yair Altman
Yair Altman 2019년 1월 4일
편집: Yair Altman 2019년 1월 4일
Here's how you can fetch IB's historical data using the IB-Matlab connector:
>> data = IBMatlab('action','history', 'symbol','IBM', 'DurationValue',5, 'BarSize','1 hour')
data =
struct with fields:
dateNum: [1×78 double]
dateTime: {1×78 cell}
open: [1×78 double]
high: [1×78 double]
low: [1×78 double]
close: [1×78 double]
volume: [1×78 double]
count: [1×78 double]
WAP: [1×78 double]
hasGaps: [1×78 logical]
>> data.dateTime'
ans =
78×1 cell array
{'20181227 11:00:00'}
{'20181227 12:00:00'}
{'20181227 13:00:00'}
{'20181227 14:00:00'}
{'20181227 15:00:00'}
{'20181227 16:00:00'}
...
For additional details, see https://undocumentedmatlab.com/ib-matlab

댓글 수: 1

It is sad that you pay for a toolbox with the expectations that it will work and the only real solution that matlab has is to spen $300 a year with a third party vendor.

댓글을 달려면 로그인하십시오.

카테고리

도움말 센터File Exchange에서 Data Type Conversion에 대해 자세히 알아보기

제품

릴리스

R2018a

질문:

2018년 7월 27일

댓글:

2019년 1월 13일

Community Treasure Hunt

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

Start Hunting!

Translated by