access fundamental data from matlab with the Trading Toolbox
조회 수: 1 (최근 30일)
이전 댓글 표시
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
답변 (1개)
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:
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Instrument Control Toolbox Supported Hardware에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!