access fundamental data from matlab with the Trading Toolbox

3 ビュー (過去 30 日間)
MRossi
MRossi 2020 年 1 月 4 日
編集済み: Annie Leonhart 2020 年 1 月 4 日
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)

回答 (1 件)

Annie Leonhart
Annie Leonhart 2020 年 1 月 4 日
編集済み: Annie Leonhart 2020 年 1 月 4 日
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:

カテゴリ

Help Center および File ExchangeInstrument Control Toolbox Supported Hardware についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by