access fundamental data from matlab with the Trading Toolbox
1 vue (au cours des 30 derniers jours)
Afficher commentaires plus anciens
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 commentaires
Réponses (1)
Annie Leonhart
le 4 Jan 2020
Modifié(e) : Annie Leonhart
le 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 commentaires
Voir également
Catégories
En savoir plus sur Instrument Control Toolbox Supported Hardware dans Help Center et File Exchange
Produits
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!