1

I'm quite new YQL and i've found the query to retrieve a single quote from a stock

select * from yahoo.finance.quote symbol = "YHOO"

and another query to get this same information but on date range

select * from yahoo.finance.historicaldata symbol = "YHOO" and startDate = "2016-09-01" and endDate = "2016-09-22"

What i could not figure out was: how could we retrieve quotes from a full day of trading?

I'm currently using the Yahoo finance app and notice they provide a good graphic about the price variation, so i presume there is a way to achieve it.

I also tried to read yql tables repository but on both table that i am using there is no (at least explicit) clue of how to pass hour range.

Ramon Moraes
  • 477
  • 7
  • 23

2 Answers2

3

You can retrieve the complete quotes of a day by querying the Yahoo Finance API endpoint directly (not via YQL) and receiving a list in JSON format.

The end point is http://chartapi.finance.yahoo.com/instrument/1.0/$symbol/chartdata;type=$type;range=$range/json/, where:

  • $symbol is the stock ticker symbol, e.g. AAPL for Apple or BAS.DE for BASF traded at Xetra
  • $type is the type of the query, you can query for quote, sma, close, volume
  • $range is the desired latest days with 1d, 5d, 10d, 15d

An example query would be http://chartapi.finance.yahoo.com/instrument/1.0/aapl/chartdata;type=quote;range=1d/json/ which gives you all quotes from AAPL from the last day.

As far as I know, you can only query for the quotes up to the last 15 days. I have not yet found a way to query for some other day further in the past.

Just my self-centric hint: check out my PHP package YahooFinanceQuery on Github, which uses an implementation of the above query and handles the returning JSON to filter the results.

dirk
  • 494
  • 1
  • 3
  • 17
  • I tried to query the 5D and notice that the query is actually cumulative. So there is no way to get by exactly date, right? – Ramon Moraes Sep 26 '16 at 14:00
  • Sorry, nope. Not possibe as far as I know. Only the daily quotes of the last 15 days. – dirk Sep 27 '16 at 18:33
  • The sample query for Apple stock doesn't work. Chrome reports no server found for chartapi.finance.yahoo.com – Jan Rou Sep 16 '17 at 12:02
  • Yes, that is correct. Yahoo changed their API endpoints in early 2017. – dirk Sep 17 '17 at 13:14
  • 1
    I found another API endpoint, which seems to allow to download daily quotes - `https://query1.finance.yahoo.com/v8/finance/chart/DBK.DE?range=1d&includePrePost=false&interval=2m&corsDomain=de.finance.yahoo.com&.tsrc=finance`. It just gives OHLCV information, but the intervals and granularity are changeable. Just start playing with the parameters. – dirk Sep 20 '17 at 10:10
3

As an update/extension to my previous answer I found a new API endpoint to download daily quotes. Yahoo changed their API endpoints in early 2017.

The new endpoint is: https://query1.finance.yahoo.com/v8/finance/chart/{$symbol}?range={$range}&interval={$interval}, where:

  • $symbol is the stock ticker symbol, e.g. AAPL for Apple
  • $range is the desired range of the query, allowed parameters are [1d, 5d, 1mo, 3mo, 6mo, 1y, 2y, 5y, 10y, ytd, max]
  • $interval is the desired interval of the quote, e.g. every 5 minutes, allowed parameters are [1m, 2m, 5m, 15m, 30m, 60m, 90m, 1h, 1d, 5d, 1wk, 1mo, 3mo]

An example would be: https://query1.finance.yahoo.com/v8/finance/chart/AAPL?range=10d&interval=1m where you receive OHLCV quotes for the AAPL stock from the last 10 trading days with a 1 minute interval. All in a nicely JSON format.

Not all $range parameters will return results with the specified $interval, but will return the nearest possible combination. For example, the "max" range will return all quotes with a "1mo" interval.

dirk
  • 494
  • 1
  • 3
  • 17