Need to download data from Yahoo Finance using Java?
I wrote this utility as part of larger project and realized it could be re-used. Needed a name, so calling it Y-Financier. Posting here in case anyone else can benefit.
You can download the source code at:
https://github.com/adpoe/Y-Financier
All you’ve gotta do:
- Grab the code from GitHub
- Add the Y-Financier Class to your project (copy/paste is fine)
- Create an instance of the Y-Financier class
- Pass your class instance the Ticker Symbol of the stock you’re interested in as the first argument (I.e. — “AAPL” for Apple)
- Pass the name of the file where you’d like to store your data as the second argument
- Call the #downloadFile method from your instance
And you’re done.
Notes:
- This program will always download the most recently available full day’s earnings report. These are usually posted after 8 or 9pm Eastern Time. If you run this program before 8 or 9pm ET, you’ll be downloading yesterday’s report. (Getting real-time stock market data will require a different solution.)
- This program will always overwrite the previously downloaded file. That setting can be changed, but it will need to be done in the source.
- I’m using Ben Noland’s implementation for the #saveURL function, found here.
A concrete example of how to use the class can be found in my Main.java file.
If you’re using Java on a similar project, save your time. Y-Financier will make it money. (hopefully.)