Error with " Request Interactive Brokers Historical Data" example
Ältere Kommentare anzeigen
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.
Antworten (3)
John Pries
am 25 Okt. 2018
0 Stimmen
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 ...
1 Kommentar
françois robert
am 29 Okt. 2018
I have the same issue, did you find a solution ?
Scott Meier
am 9 Nov. 2018
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 Kommentare
terry dylan
am 10 Jan. 2019
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 !
Scott Meier
am 10 Jan. 2019
Hi Terry, I did not have any issues with the history.m file. I used it as is.
terry dylan
am 10 Jan. 2019
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
Scott Meier
am 11 Jan. 2019
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.
terry dylan
am 13 Jan. 2019
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
am 4 Jan. 2019
Bearbeitet: Yair Altman
am 4 Jan. 2019
>> 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'}
...
1 Kommentar
Mike A
am 10 Jan. 2019
Kategorien
Mehr zu Data Type Conversion finden Sie in Hilfe-Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!