access fundamental data from matlab with the Trading Toolbox
2 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
I wanted to know if it was possible to access fundamental data Interactive Brokers from matlabTrading Toolbox - MATLAB ? (https://interactivebrokers.github.io/tws-api/fundamentals.html)
0 Kommentare
Antworten (1)
Annie Leonhart
am 4 Jan. 2020
Bearbeitet: Annie Leonhart
am 4 Jan. 2020
Yes, it's possible... but, data is returned in XML... it'll take a lot of work to cleanup the XML file... a LOT. The code below will create a struct with the XML data. Good luck cleaning that up.
%% Connect to IBTWS or GATEWAY
ib = ibtws('',4001,0);
%% Create Contract
contract = ib.Handle.createContract;
contract.symbol = 'AAPL';
contract.secType = 'STK';
contract.exchange = 'SMART';
contract.primaryExchange = 'SMART';
contract.currency = 'USD';
%% register event
ib.Handle.registerevent({'fundamentalData',@(varargin)fundHandler(varargin{:},ib)});
%% Request Data
tickerid = randperm(10000,1);
ib.Handle.reqFundamentalData(tickerid,contract,'ReportsFinSummary'); pause(0.2);
ib.Handle.cancelFundamentalData(tickerid);
%% Unregister the event(s)
listeners = ib.Handle.eventlisteners;
i = strcmp(listeners(:,1),'fundamentalData');
ib.Handle.unregisterevent([{listeners{i,1}}' {listeners{i,2}}']);
% Event handler
function fundHandler(varargin)
switch varargin{end-1}
case 'fundamentalData'
fundamentaldata = varargin{5}.data
% Store the XML data in a temp *.xml file
filename = ['fundamentaldata.xml'];
fid = fopen(filename,'Wt');
fwrite(fid,fundamentaldata);
fclose(fid);
% Read the file into an XML model object
data = xml2struct(filename);
% Assign the data to a variable
assignin('base','fundamentaldata',data)
end
end
Output:
0 Kommentare
Siehe auch
Kategorien
Mehr zu Trading Technologies finden Sie in Help Center und File Exchange
Produkte
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!