In order to download quotes from yahoo finance it is enough to do so on Python. And how to do the same on Java?
from pandas_datareader import data a = 'AAPL' aapl = data.DataReader(a, 'yahoo', '1990-01-01') aapl.to_csv('C:/aapl_data.csv') In order to download quotes from yahoo finance it is enough to do so on Python. And how to do the same on Java?
from pandas_datareader import data a = 'AAPL' aapl = data.DataReader(a, 'yahoo', '1990-01-01') aapl.to_csv('C:/aapl_data.csv') A complete java solution with good examples. The code will be almost as small as in python.
If you search the source, you can understand how to work with Yahoo api, or read the following instructions
http://meumobi.imtqy.com/stocks%20apis/2016/03/13/get-realtime-stock-quotes-yahoo-finance-api.html
The low-level version will look something like this:
package javatest; import java.io.File; import java.io.FileOutputStream; import java.net.URL; import java.nio.channels.Channels; import java.nio.channels.ReadableByteChannel; import java.util.Calendar; public class JavaTest { public static void urlToFile(URL url, File file) throws Exception { ReadableByteChannel rbc = Channels.newChannel(url.openStream()); FileOutputStream fos = new FileOutputStream(file); fos.getChannel().transferFrom(rbc, 0, Long.MAX_VALUE); } public static void main(String[] args) throws Exception { Calendar from = Calendar.getInstance(); from.clear(); Calendar to = Calendar.getInstance(); to.clear(); from.set(2016, 2, 15); to.set(2016, 2, 28); urlToFile( new URL(String.format( "http://ichart.finance.yahoo.com/table.csv?s=AAPL&a=%s&b=%s&c=%s&d=%s&e=%s&f=%s&g=d&ignore=.csv", from.get(Calendar.MONTH), from.get(Calendar.DAY_OF_MONTH), from.get(Calendar.YEAR), to.get(Calendar.MONTH), to.get(Calendar.DAY_OF_MONTH), to.get(Calendar.YEAR) )), new File("file.csv") ); } } Source: https://ru.stackoverflow.com/questions/633504/
All Articles