YQL getting stock quotes country wise - yql

I have been searching for this for last few days. I have achieved fetching the basic things through YQL, like their stocks, prices and all.
Like this :
Select Name,Symbol,LastTradePriceOnly,LastTradeDate, LastTradeTime, Change, ChangeInPercentage, PreviousClose, Open, Bid, Ask, DaysRange, YearRange, Volume , Average, MarketCapitalization, PERatio, EPSEstimateCurrentYear, TralingAnnualDividendYield from yahoo.finance.quotes where symbol = 'aapl'
But i do not know how to get stock quotes country wise. First of all i did not get a YQL to get the countries related to stocks.
For example :
Select Name,Symbol from yahoo.finance.quotes where Country = "India".
Thanks for your time.

Using YQL in this manner is basically looking up the results for a given stock symbol which you provide. (Behind the scenes, this YQL table is querying a data source that Yahoo Finance uses.) It's not a general purpose database where you could do queries such as getting a list of symbols or markets for a given country.
YQL does work for some international market stocks, but again you need to already know the symbol. For example:
select * from yahoo.finance.quotes where symbol="arm.l"
select * from yahoo.finance.quotes where symbol="kfa.bo"

I'm looking for the same sort of thing, I would have thought you would need to use market name instead of the country name. i.e NASDAQ, FTSE or the BSE.

Yahoo APIs don't appear to work for int'l bourses. Try this:
select * from yahoo.finance.quotes where symbol="ril.bo"
The query works and returns no data. This is a sample what I got:
"Name": "RIL.BO",
"Notes": null,
"Open": null,
"PreviousClose": null,
"PricePaid": null,
"ChangeinPercent": null,
"PriceSales": null,
"PriceBook": null,
"ExDividendDate": null,
"PERatio": null,
"DividendPayDate": null,
"PERatioRealtime": null,
"PEGRatio": null,
"PriceEPSEstimateCurrentYear": null,
"PriceEPSEstimateNextYear": null,
"Symbol": "RIL.BO",
YQL gives a clue that it is not set up for int'l exchanges. Buried in JSON is the message:
"ErrorIndicationreturnedforsymbolchangedinvalid": "No such ticker symbol. <a href=/l>Try Symbol Lookup</a> (Look up: <a href=/l?s=RIL.BO>RIL.BO</a>)",
Note that the symbols I have used are valid and from Yahoo!'s own lookup.
Everything works just fine for US bourses. Try substituting GOOG or YHOO for RIL.BO. Works like a charm.

There is a list of important Stock Exchange codes for World wise region- http://finance.yahoo.com/intlindices?e=asia and I have explained the URL and Query logic here- http://prasanta-paul.blogspot.kr/2013/01/accessing-yahoo-finance-api.html
Hope it helps!

Related

How to do grouping in elasticsearch with searchkick rails

I have articles data indexed to elastic as follows.
{
"id": 1011,
"title": "abcd",
"author": "author1"
"status": "published"
}
Now I wanted to get all the article id grouped by status.
Result should someway look like this
{
"published": [1011, 1012, ....],
"draft": [2011],
"deleted": [3011]
}
NB: I tried normal aggs (Article.search('*',aggs: [:status], load: false).aggs) , it just giving me the count of each items in, I want ids in each item instead
#Crazy Cat
You can transform you query in this way:
sort(Inc/Dec order) your response from ES over field "status".
Only Ask ES query to return only ID Field and status.
Now the usage of sorting would be it would sort your response to like this: [1st N results of "deleted" status, then N+1 to M results to "draft" and then M+1 to K results to "published"].
Now the advantages of this technique:
You will get flagged ids field of every document over which you can apply operations in you application.
Your query would be light weight as compared to Aggs query.
This way you would also get the metdata of every document ike docId of that document.
Now the Disadvantages:
You would always have to give a high upper bound of your page size, but You can also play around with count coming in the metadata.
Might take a bit more of network size as it returns redundant status in every document.
I Hope this redesign of your query might be helpful to you.

How to filter for a object wiith a "value" and "name" in QBO api?

It seems like its the api won't permit a query filter of the form:
select * from purchaseorder where APAccountRef.value='33'
In the case of purchase orders it seems to mean that I need to bring down every purchase order to my server and scan for the account I need which is highly suboptimal. Is there some other syntax for querying against the many attributes which have been encoded like
"APAccountRef": {
"value": "33",
"name": "Accounts Payable (A/P)"
}
with just a name and value attribute?
If you refer to the documentation:
https://developer.intuit.com/docs/api/accounting/purchaseorder
It gives you a list of all fields, and a list of fields that are filterable. Your query is using a field that does not exist as part of Purchase Orders:
AccountRef.value='39'
The correct field is:
APAccountRef:
required
ReferenceType, filterable
Specifies to which AP account the bill is credited.
So your query should be:
SELECT * FROM purchaseorder WHERE APAccountRef = '39'
Try this in python-
"select * from purchaseorder where APAccountRef in ('33')"

Search four fields in YQL geo.places

We are currently using YQL to query geo data for towns and counties in the UK. At the moment, we can use the following query to find all towns named Boston:
select * from geo.places where text="boston" and placeTypeName="Town"
Demo
The issue is, that we would like to specify the county and country to generate more specific results. I have tried the following query, but it returns 0 results:
select * from geo.places where (text="boston" and placeTypeName="Town") and (text="lincolnshire" and placeTypeName="County")
Demo
How can I query 3 field types to return the results I need? Essentially, we would like to query the following fields:
text and placeTypeName="Town"
text and placeTypeName="County"
text and placeTypeName="Country"
This may be an option maybe:
https://developer.yahoo.com/blogs/ydnsevenblog/solving-location-based-services-needs-yahoo-other-technology-7952.html
As it mentions:
Turning text into a location
You can also turn a text (name) into a location using the following code:
yqlgeo.get('paris,fr',function(o){
alert(o.place.name+' ('+
o.place.centroid.latitude+','+
o.place.centroid.longitude+
')');
})
This wrapper call uses our Placemaker Service under the hood and automatically disambiguates for you. This means that Paris is Paris, France, and not Paris Hilton; London is London, England, and not Jack London.

Convert/Cast string to integer via YQL?

In SQL, you can use cast or convert to convert a string to an integer so you can compare numerical values, i.e.
SELECT * FROM table1 WHERE CAST(col1 AS int) < 100
Is it possible to do the same thing in YQL?
The following doesn't work:
SELECT * FROM json WHERE url='url_goes_here' AND CAST(col1 AS int) < 100
It gives me 0 results. I should be getting more.
In both queries, col1 is a string.
YQL is not exactly SQL per say. It is a "SQL like" language. It does not query a database instead in the background makes REST calls to the backends.
Since I don't know what table you are querying, from what I understood from the question, what you are saying can be achieved. Read the yql doc here. Sample query select * from local.search where query="sushi" and location="san francisco, ca" and Rating.TotalRatings < "12"
I know its strange that we are comparing against a string value but it does work. You can test this on the YQL console here (just copy paste the query in the text box). Let me know if you have any questions/concerns. I will try to answer it to best of my knowledge.

Merged Google Fusion Tables - Select Query with WHERE clause on Merge Key Error

I have merged two Fusion Tables together on the key "PID". Now I would like to do a SELECT query WHERE PID = "value'. The error comes back that no column with the name PID exists in the table. A query for another column gives this result:
"kind": "fusiontables#sqlresponse",
"columns": [
"\ufeffPID",
"Address",
"City",
"Zoning"
],
"rows": [
[
"001-374-079",
"# LOT 15 MYSTERY BEACH RD",
"No_City_Value",
"R-1"
],
It appears that the column name has been changed from "PID" to "\ufeffPID", which no matter how many attempts to get the syntax to read a GET Url, I keep getting an error.
Is there any limitation with querying on the key of a merged table? Since I cannot seem to get the name correct for the column a work around would be to use the Column ID but that does not seem to be an option either. Here is the URL:
https://www.googleapis.com/fusiontables/v1/query?sql=SELECT 'PID','Address','City','Zoning' FROM 1JanYNl3T45kFFxqAmGS0BRgkopj4AS207qnLVQI WHERE '\ufeffPID' = 001-493-078&key=myKey
Cheers
I have no explanation for \ufeff in there; that's the Unicode character 'ZERO WIDTH NO-BREAK SPACE', so it's conceivable that it's actually there in the column name because it would be invisible in the UI. So, first off I would recommend changing the name in the base tables and see if that works.
Column IDs for merge tables have a different form than for base tables. An easy way to get them is to add the filters of interest to one of your tabs (any type will do) and then do Tools > Publish. The top text ("Send a link in email or IM") has a query URL that has what you need. Run it through a URL decoder such as http://meyerweb.com/eric/tools/dencoder/ and you'll see the column ID for PID is col0>>0.
Rod

Resources