2
votes

Since the previous Yahoo Finance download URL is not working anymore, I are now left with something like this:

https://query1.finance.yahoo.com/v7/finance/download/AAPL?period1=1492524105&period2=1495116105&interval=1d&events=history&crumb=tO1hNZoUQeQ

Does anybody know how the period1 (and period2) translate into a date (and viceversa)

Any help appreciated!

Thanks!

4
Downvoting for no reason instead of trying to answer question... way to go people!Molasar
Possible duplicate of Yahoo Finance URL not workingThomasMcLeod

4 Answers

1
votes

It looks like they are just unix time stamps, or the seconds from the Epoch. Here is a website that can covert the information for you: http://www.unixtimestamp.com

2
votes

This is oriented at recreating (kinda) the old functionality. I am running Fedora with Chrome.

(1) Figure out your user agent string for your web browser (I googled something like "what's my user agent string" and quickly found a page that would print it out for the browser you are using). It will be something like "Mozilla/5.0 (X11; Linux x86_64) ..."

(2) Install a package that will export a "cookies.txt" file for Chrome (also googled for something like "Chrome export cookies.txt" and quickly found a chrome extension that would export a cookies.txt for a page you are viewing).

(3) Go to the historical downloads page for a symbol of interest at Yahoo finance. Save the "crumb" in the download link (like you have above) and the cookies.txt for that page.

(4) Now you can use wget to get data. The command will be something like:

wget --load-cookies [THE COOKIES FILE YOU SAVED] -U "[THE USER AGENT STRING YOU FOUND]" -O [DESIRED OUTPUT CSV] https://query1.finance.yahoo.com/v7/finance/download/[THE SYMBOL YOU WANT HISTORICAL DATA FOR]?period1=[UNIX START TIME]\&period2=[UNIX END TIME]\&interval=1d\&events=history\&crumb=[THE CRUMB YOU SAVED]

The period1=... is the UNIX timestamp (seconds since 1970-Jan-1 00:00:00 GMT) of the start date and period2=... is the UNIX timestamp of the end date.

I was able to programmatically download a number of symbols this way. The column ordering of the resulting CSV file had changed from the old ichart API and the number of errors I found in the historical data was noticeably higher than the already quite high error rate in the data.

No guess on how long this will work or if it is stable over a long period of time. YMMV.

1
votes

They are unix timestamps, or seconds since Epoch.

Quote taken from http://www.unixtimestamp.com/

What is the unix time stamp?
The unix time stamp is a way to track time as a running total of seconds. This count starts at the Unix Epoch on January 1st, 1970 at UTC. Therefore, the unix time stamp is merely the number of seconds between a particular date and the Unix Epoch. It should also be pointed out (thanks to the comments from visitors to this site) that this point in time technically does not change no matter where you are located on the globe. This is very useful to computer systems for tracking and sorting dated information in dynamic and distributed applications both online and client side

The following C# code helps to convert between DateTime to Unix Timestamp

//credits to ScottCher
//reference http://stackoverflow.com/questions/249760/how-to-convert-a-unix-timestamp-to-datetime-and-vice-versa
private static DateTime UnixTimestampToDateTime(double unixTimeStamp)
{
    //Unix timestamp Is seconds past epoch
    return new DateTime(1970, 1, 1, 0, 0, 0, 0, DateTimeKind.Utc).AddSeconds(unixTimeStamp).ToLocalTime();
}

//credits to Dmitry Fedorkov
//reference http://stackoverflow.com/questions/249760/how-to-convert-a-unix-timestamp-to-datetime-and-vice-versa
private static double DateTimeToUnixTimestamp(DateTime dateTime)
{
    //Unix timestamp Is seconds past epoch
    return (dateTime.ToUniversalTime() - new DateTime(1970, 1, 1, 0, 0, 0, 0, DateTimeKind.Utc)).TotalSeconds;
}

NOTE: make sure you round it up to zero decimal before substituting into period1 and period2

0
votes

The period1 and period2 are just timestamps (POSIX timestamps). I think you can use any time of the date that you want to use. For example, for 2014-05-20, you can use any time from 00:00:00 to 23:59:59. (Update: Yahoo has just made a change here. You have to use a time that is after market close time, otherwise the data will miss the last day. I think 18:00:00 is working fine.)

I have put together some quick Python3 code to use that new API. Please check out GitHub for source code yahoo_quote_download.