Getting block data from YQL - yql

I read up on YQL. However i'm at a loss on how to get blocks of data.
I can get individual stock data fine but how do you get collated data like the FTSE 100 shares, without having to find the symbol for each 100 shares and pulling that data in individually?
Ideally i would have the hundred shares with each of their bits of data.
Thanks in advance,
Ewan

looks like you are right that only one stock can be queried at a time. since the api is restful, you can easily use a for loop in bash and curl all the stocks.

Whenever we query YQL table we need to give the SYMBOLS (tickers) as inputs. However there is a limit to the number of symbols you can enter in one go.
I created an Excel sheet where I read a list of symbols from a sheet and then query with YQL and dump the data in another sheet.
Let's assume you want to pull out historical prices with the following specifications:
Symbol/Ticker : symbol
StartDate
EndDate
The corresponding weblink to extract this info would be (in VBA syntax)
"http://query.yahooapis.com/v1/public/yql?q=select%20*%20from%20yahoo.finance.historicaldata%20where%20symbol%20in%20%28%27 " & symbol & "%27%29%20and%20startDate%20=%20%27" & startDate & "%27%20and%20endDate%20=%20%27" & endDate & "%27&diagnostics=true&env=store://datatables.org/alltableswithkeys"
You can find the Excel sheet present at my blog.

Related

Google Sheets: API To Get Crypto Prices and History?

As GOOGLEFINANCE() seems very limited in the cryptocurrencies it supports, are there any (free?) APIs that I can use to get data from?
Although I use GF() for ETH and BTC, I'm specifically looking for Price and Historical Closing Prices on ADA (Cardano).
I've searched the forum for suggestions, there aren't many and most are old. Binance's API seemed OK, but it gives prices in USDT instead of USD.
If anyone is interested, I found an API that offers a free key, although limited in the number of daily calls you can make: CoinAPI.
It seems very powerful, with quotes available in most currencies. So far, I've managed to get a current price:
Formulas shown in brown.
(1) shows the raw data returned, a two rows delimited by semi-colons.
(2) wraps a QUERY() around IMPORTDATA(), using offset 1 plus param 0, to not return the header row, then wraps all that in SPLIT() to separate the delimited text into columns.
(3) wraps (2) with INDEX() so I can get just the Price in the 4th col.
As this value will not automatically update like GOOGLEFINANCE(), I think I'll need to set a Trigger to do that.
I've also retrieved historical data, but I've yet to figure out how to split multiple rows of delimited text from the IMPORTDATA() function.
[Edit] See the solution to splitting multiple rows by #player0 at https://stackoverflow.com/a/69055990/190925.

How do I pull the first instance of an open orders expected receive date into a different Google sheet, comparing parts lists

I'm working on an inventory system in Google Sheets and I need to pull data from one sheet into another sheet within the same work book.
I have two lists of parts, one is an indented BOM, that shows quantity of parts. The other is a Purchasing/Receiving log for inventory.
I need to compare the BOM with the Purchasing sheet to find the first instance of an order for that part, then check if it is still open or not, then pull the expected delivery date into the matching row in the BOM sheet assuming that order is still open.
These are the two formula I have that are the closest.
=IF(ISBLANK(A2),"",(SUMIF('PURCHASING/RECEIVING LOG'!D:D,B:B,'PURCHASING/RECEIVING LOG'!L:L)))
This one SUMS the date value, resulting in way off dates when converted back into a date format, but it correctly lines up all dates from PURCHASING RECEIVING, that match part name in BOM
=IF(B:B='PURCHASING/RECEIVING LOG'!D:D,IF('PURCHASING/RECEIVING LOG'!C:C="OPEN",'PURCHASING/RECEIVING LOG'!L:L,"WRONG"),"WRONG2")
This one correctly checks if the purchase order is open or not, but it only pulls the date if the rows match, instead of matching up the data for both columns. So if 'BOM'!B2 = 'PURCHASING RECEIVING'!D2. I need to check if any row in 'PURCHASING RECEIVING'!D:D = 'BOM'!B2, then B3 then B4 etc. Then pull the relevant information from 'PURCHASING RECEIVING'!L:L
Neither of them pull only the first instance of a matching open order.
There are duplicate parts in both the BOM and the Purchasing sheet, since multiple machines use the same parts, and we have multiple open orders for the same parts at any given time.
Any help or if someone could point me in the right direction would be greatly appreciated.
Please let me know if there are any questions.
Thank you.
EDIT: Added sample sheet
https://docs.google.com/spreadsheets/d/1fsrl4h__GbtHeHUCBs0PS25HR8MhWEplQ2bY-qcdWlw/edit?usp=sharing
You can use a QUERY on the second sheet to pull the required date, for example in cell G3, you would use:
=QUERY('PURCHASING RECEIVING'!$B$2:$E,"select min(E) where B = 'OPEN' and C ='"&E3&"' label min(E) ''")
And then drag down to the rest of the rows.
Sample Output:
Reference:
QUERY function
Query Language Reference

Extract html table row to google sheet

I’m trying to extract a single row from a table
When using the google sheet importhtml function, I get the whole table.
=IMPORTHTML("https://www.marketwatch.com/investing/stock/jwn/options?mod=mw_quote_tab", "table",1)
How can I extract just the row right above the word “ Current price as of “
So e.g. in this case the row will have the data below. (this data will change as the date changes)
quote 1.5 0.53 76 1.36 1.47 142 39 quote 0.88 -1.73 23
I have several urls to go thorough
So e.g if I put the following url then the row position will change.
https://www.marketwatch.com/investing/stock/ge/options
Any idea how to extract that just last row right above the word “ Current price as of “
When I saw the HTML data from the URL of https://www.marketwatch.com/investing/stock/ge/options, I thought that the value you expect might be able to be retrieved using IMPORTXML and a xpath. So in this answer, I would like to propose to use IMPORTXML.
Sample formula:
=IMPORTXML(A1,"//tr[td[1]/#class='acenter inthemoney'][last()]")
In this case, the URL of https://www.marketwatch.com/investing/stock/ge/options is put in the cell "A1".
Result:
Note:
This sample formula can be used for the current URL of https://www.marketwatch.com/investing/stock/ge/options. So when the URL is changed and the HTML structure is changed by updated of the site, the formula might not be able to be used. So please careful this.
Reference:
IMPORTXML
ImportHTML() simply allows you to read an (entire!) HTML table or list into your Google sheet.
If you want to filter or manipulate the imported data, then you'll need to use other Google Sheets functions. These are documented here:
Google Sheets function list
Alternatively, you might want to "import" input one sheet, then select certain data into another, separate sheet:
Get data from other sheets in your spreadsheet
Here are some examples for "filtering" your data:
FILTER function

Find sector by share symbol in google sheets

Is there a way to print out the GICS sector name for a specific share/ETF symbol in google sheets using the GOOGLEFINANCE commands or any other way?
Many thanks
I used this site to find several scraping methods to get data from finviz.
https://decodingmarkets.com/scrape-stock-data-from-finviz/
Extending their logic, I was able to get the company name, and the combined sector/subsector codes
(I originally used the website's scraping techniques to get Dividend data that GoogleFinance formula lacks...)
This formula gets the company name using US ticker symbol in cell C3:
=SUBSTITUTE(INDEX(IMPORTHTML("http://finviz.com/quote.ashx?t="&C3,"table",6),2,1),"*","")
Through trial and error, I found that table 6 has name and sectors. I then referenced the 2nd row and 1st column to get the name.
I found that row 3, column 1 has the sector, subsector and country combined as one value. They use a pipe | delimiter for each break.
Using the split function, I was able to split segment.
=SPLIT(SUBSTITUTE(INDEX(IMPORTHTML("http://finviz.com/quote.ashx?t="&C3,"table",6),3,1),"*",""),"|",true,true)
Its not available from Sheets
Check out the official docs:
https://support.google.com/docs/answer/3093281?hl=en
It has a lot of options but unfortunately, not that one.
If you think it would be useful, then make sure you file a feature request #
https://developers.google.com/issue-tracker
As for any other way
#GSee said it best here: https://stackoverflow.com/a/16525782/10445017

Getting adjusted price information from Yahoo! Finance API for multiple symbols in one call

I would like to get the adjusted price (adjusting for splits and dividends) for a group of stock symbols using Yahoo! Finance. It looks like the historical prices call is limited to one symbol at a time. Could please let me know if there is a way to get multiple symbols in one call?
I would like to get this data so I can do some back testing on that data. Since I may require quite a few symbols (say 500-1000), it will be easier if I can make just a few batch calls to Yahoo!'s servers instead of making one call per symbol everyday.
Another way of getting the adjusted price is to use their daily stock price api and adjust it manually using dividend and splits information (they allow multiple symbols for their daily stock quotes). Unfortunately I cannot find any way to get splits information from the http call (guessing based on 50% or 200% is one option but if you deal with penny stocks, this can be dangerous and cannot figure out uneven splits). Also, the dividend information returned by it is not easy to decode. They seem to be returning the total over 4 quarters and the dividend date doesn't really correspond with the actual dividend date based on the historical price. The various options for the call can be found here: http://www.gummy-stuff.org/Yahoo-data.htm
Any suggestions on getting adjusted price for multiple symbols? Or Am I unnecessarily worrying about making 100s of calls to Yahoo! everyday? Ideally I would like to download all the required data within a couple of hours each day - that would be 10-20 calls per minute. Is that too much? I couldn't find any documentation on the permissible number of requests per second.
I am open to other places where I can get similar data. However, since I am just trying to learn the basics of quant trading and not trade, I would prefer free downloads.
Thanks
-e
This is an old question, but I did find a source where split data is available. Not sure how comprehensive these announcements are though:
http://biz.yahoo.com/c/09/s1.html
In the url, the "09" part is the year (2009), and the "s1" part is the month (s1 = Jan, s2 = Feb., s3 = Mar., etc.)
It isn't a nice clean CSV, but the format of the page is consistent and should be parseable. Just make a query each day for the current month, parse the page, and process any splits that you didn't see the day before.
ETA: And another source (probably less reliable than Yahoo, but can be queried by ticker):
http://getsplithistory.com/
I am not sure which language you are using but I have a sample in C#. I think it will give you the idea at least or may be help some one else
private string BASE_URL = "http://query.yahooapis.com/v1/public/yql?q=" + "select%20*%20from%20yahoo.finance.quotes%20where%20symbol%20in%20({0})" + "&env=store%3A%2F%2Fdatatables.org%2Falltableswithkeys";
Collection<Quote> quotes;
string symbolList = String.Join("%2C", quotes.Select(w => "%22" + w.Symbol + "%22").ToArray());
string url = string.Format(BASE_URL,symbolList);
XDocument doc = XDocument.Load(url);
Parse(quotes,doc);
What we are doing here is appending "," to each array item then passing that symbol list to yahoo. I have successfully fetched prices for 700 symbols in each call. Hitting yahoo servers for each ticker is a pain. I fetch stock prices for all of 6500+ tickers everyday. Earlier it use to take 3 hours now it is less than 2 mins.....sweet
Source link for that code is here - http://www.jarloo.com/get-yahoo-finance-api-data-via-yql/
P.S. Please get a api key to work smoothly. The above url is a public link where tables are timed out most of the time. Once you get an api key then your url will be (minus "public")
http://query.yahooapis.com/v1/yql

Resources