Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Java API for financial data [closed]

I am working on my Master's project and I am looking for a substantial amount of financial data about a particular company.

Example: let's say "Apple". I want the historic prices, current market price / ratios, quarterly results and the analyst calls.

I saw couple of posts on StackOverflow about YQL. I think I can get current price and various ratios from Yahoo Finance for free. However for other data, there are companies like Thomson Reuters, Bloomberg, etc. but they seem to have a closed system.

Where can I get an API to fetch various data? Is there anything which will help me get that data? I am fine with raw data as well in any format. Whatever I can get. Could you guys please suggest any API?

like image 227
Kunal Avatar asked Feb 04 '11 04:02

Kunal


People also ask

Is Google Finance API discontinued?

Why is Google Finance API not on the list? Google Finance API also discontinued. But don't worry, we have good solutions for you.

Is Yahoo Finance API still available?

The programming interface was clever in solving the bulk data feed in one stock and provided helpful charts to track finance effectively. However, in what appeared to be cost cutting measures by Verizon, Yahoo Finance was discontinued.


1 Answers

I have tackled this problem in the past.

For price history data, I used yahoo's API. When I say API, I mean I was making an HTTP get request for a CSV file of price history data. Unfortunately, that only gets you data for one company at a time, for a time span you specify. So I first made a list of all the ticker symbols, and iterated over that, calling yahoo's API for each. You might be able to find a website that lists ticker symbols too, and just periodically download that list.

Do this too often and too fast, and their website just might block you. I added some code to limit how frequently I made http requests. I also persisted my data so I would not have to get it again. I would always persist the raw/unprocessed form of data, your code could change in ways that make it tough to use anything else. Avro/Thrift might be an exception, since those support schema evolution.

For other kinds of data, you may not have any API that gives you nice CSV files. I had to cope with that problem many times. Here is my advice.

Sometimes a website calls a restful web service behind the scenes, you can discover that by using firebug. Sometimes it will also require certain headers, which you can also discover using firebug.

If you are forced to work with HTML, there are several java libraries that can help you. apache.commons.http is a library you can use to easily make http requests and handle their responses. Google has an http-client jar too, which is probably worth investigating.

The JSoup API is excellent at parsing HTML data, even when it is poorly formatted, and not XHTML. It works with XML too. Instead of traversing or visiting nodes in the jsoup hierarchy, learn XPath and use that to select what you want. The website may periodically change the format of its web page, that should be easy to cope with and fix if you're using JSoup, and tough to cope with otherwise.

If you have to work with JSON, use the Jackson library to parse it.

If you have to work with CSV, use the OpenCSV library to parse and handle it.

Also, always store the data in the raw, and avoid making unnecessary HTTP requests so you don't get blocked. I have been blocked by google finance a couple times, they can do it. Fortunately the block does expire. You might even want to add a random wait period between requests.

like image 99
msknapp Avatar answered Sep 28 '22 16:09

msknapp