softwarespartan / IB4m

Interactive Brokers API for Matlab
GNU General Public License v2.0
62 stars 21 forks source link

Fundamental data #109

Open beppe969 opened 3 years ago

beppe969 commented 3 years ago

Hello

can someone post a script showing how to retrieve fundamental data (like price/earnings, etc.) for a contract?

Thanks! Giuseppe

Despair2000 commented 3 years ago

This is rather simple.

`[buf, lh] = TWS.initBufferForEvent(TWS.Events.FUNDAMENTALDATA);

reqFundamentalData(session.eClientSocket,reqID,contract,reportType,[]) pause(3)

data = collection2cell(buf);`

reportType can be one of the following: 'ReportsFinSummary' - Financial summary 'ReportsOwnership' - Company's ownership (Can be large in size) 'ReportSnapshot' - Company's financial overview 'ReportsFinStatements' - Financial Statements 'RESC' - Analyst Estimates
'CalendarReport' - Company's calendar

A little bit annoying that the data comes in XML-format though.

beppe969 commented 3 years ago

Great, thanks, I'll try this!

Despair2000 commented 3 years ago

Keep in mind that some items (like the calendar report) need special subscriptions.

beppe969 commented 3 years ago

Pardon my inexperience, but at some point I get data =

1×1 cell array

{1×1 com.tws.Handler$FundamentalDataEvent}

but then I have no idea on how to actually access the data from this cell array...

Despair2000 commented 3 years ago

The API always returns java-objects. You can have a look at what you got with fields(data{1}) in other situations you will need methods(data{1}) because the data is often returned in form of methods. If you issue the first you will find that the java-object has two fields, date and data. The data field has the data you requested. So if you issue data{1}.data you will see the XML-data the API has sent you.

beppe969 commented 3 years ago

got it thanks! I'll try to decode the xml-data to see how to retrieve the numbers I'm interested in. Thank you!