Is there any way to get historical stock prices from the yahoo api in the json format? I'd like to use REST because it's more lightweight.
To follow up on user586050's answer with a specific example...
You can use the YQL yahoo.finance.historical data table for this request, and have the results come back in JSON format.
For example try this query (the link will take you to the YQL console where you can play with it):
select * from yahoo.finance.historicaldata where symbol = "YHOO" and startDate = "2009-09-11" and endDate = "2009-09-15"
Sample results in JSON format:
{
"query": {
"count": 3,
"created": "2011-12-31T19:44:20Z",
"lang": "en-US",
"results": {
"quote": [
{
"date": "2009-09-15",
"Date": "2009-09-15",
"Open": "16.01",
"High": "16.49",
"Low": "15.87",
"Close": "16.41",
"Volume": "64668200",
"Adj_Close": "16.41"
},
{
"date": "2009-09-14",
"Date": "2009-09-14",
"Open": "15.45",
"High": "15.58",
"Low": "15.28",
"Close": "15.57",
"Volume": "19451200",
"Adj_Close": "15.57"
},
{
"date": "2009-09-11",
"Date": "2009-09-11",
"Open": "15.53",
"High": "15.68",
"Low": "15.41",
"Close": "15.59",
"Volume": "26860700",
"Adj_Close": "15.59"
}
]
}
}
}
You can use YQL to fetch data. look at here the code in C#.
Or if you want current stock look at https://github.com/samkiller/stoxxbees
You can have stock data in both xml or json.
get json format you can use YQL to send request and get response, if you want to get history data in spreadsheet, you can use http://ichart.finance.yahoo.com/table.csv?s=company symbol e.g open http://ichart.finance.yahoo.com/table.csv?s=MD in your browser
Related
We are using Airbyte to sync MongoDB data into Snowflake. For some reason, our JSON lists are synched as what appear to be Java Objects.
I am trying to get the data into a JSON format, so I can work with the properties.
Example of Java object row in our cost column:
"[Document{{currency=USD, value=815.00}}, Document{{currency=EUR, value=671.00}}, Document{{currency=GBP, value=579.00}}, Document{{currency=DKK, value=4992.00}}, Document{{currency=SEK, value=6760.00}}]"
I want to convert the row into the following format
[{
"currency": "USD",
"value": 815.00
}, {
"currency": "EUR",
"value": 671.00
}, {
"currency": "GBP",
"value": 579.00
}, {
"currency": "DKK",
"value": 4992.00
}, {
"currency": "SEK",
"value": 6760.00
}]
How can I accomplish that in Snowflake?
You can use regex but it's not the most elegant way:
set term='[Document{{currency=USD, value=815.00}}, Document{{currency=EUR, value=671.00}}, Document{{currency=GBP, value=579.00}}, Document{{currency=DKK, value=4992.00}}, Document{{currency=SEK, value=6760.00}}]';
select regexp_replace(regexp_replace(regexp_replace($term, 'Document',''), '}}', '}'), '{{', '{');
I get:
[{currency=USD, value=815.00}, {currency=EUR, value=671.00}, {currency=GBP, value=579.00}, {currency=DKK, value=4992.00}, {currency=SEK, value=6760.00}]
This can be further extended to replace currency with "currency".
I'm trying to use some results exported in JSON of a script called "Mixed Content Scan" (it's a script in order to search on a website if there is some mixed HTTP/HTTPS content and if all your pages are ok in HTTPS).
I'm a beginner with JSON, I read and watched a lot of tutorials in order to understand how to structure JSON data but I'm stumbling on something.
Here is a sample of my data (first 3 lines) :
{"message":"Scanning https://mywebsite.com/","context":[],"level":250,"level_name":"NOTICE","channel":"MCS","datetime":{"date":"2018-10-05 23:48:50.268196","timezone_type":3,"timezone":"America/New_York"},"extra":[]}
{"message":"00000 - https://mywebsite.com/","context":[],"level":400,"level_name":"ERROR","channel":"MCS","datetime":{"date":"2018-10-05 23:48:50.760948","timezone_type":3,"timezone":"America/New_York"},"extra":[]}
{"message":"http://mywebsite.com/wp-content/uploads/2015/03/image.jpg","context":[],"level":300,"level_name":"WARNING","channel":"MCS","datetime":{"date":"2018-10-05 23:48:50.761082","timezone_type":3,"timezone":"America/New_York"},"extra":[]}
I know I need to wrap my data around some {} or [] (tried both), but I think I'm missing something, for example, every JSON data validator websites are telling me that I have an error between 2 lines when I add a "," when I try to have multiple results into it.
How can I upgrade this raw data in order for a JSON validator to validate it?
Thanks!
How's this
[{
"message": "Scanning https://mywebsite.com/",
"context": [],
"level": 250,
"level_name": "NOTICE",
"channel": "MCS",
"datetime": {
"date": "2018-10-05 23:48:50.268196",
"timezone_type": 3,
"timezone": "America/New_York"
},
"extra": []
}, {
"message": "00000 - https://mywebsite.com/",
"context": [],
"level": 400,
"level_name": "ERROR",
"channel": "MCS",
"datetime": {
"date": "2018-10-05 23:48:50.760948",
"timezone_type": 3,
"timezone": "America/New_York"
},
"extra": []
}, {
"message": "http://mywebsite.com/wp-content/uploads/2015/03/image.jpg",
"context": [],
"level": 300,
"level_name": "WARNING",
"channel": "MCS",
"datetime": {
"date": "2018-10-05 23:48:50.761082",
"timezone_type": 3,
"timezone": "America/New_York"
},
"extra": []
}]
Entries in an array need to be separated by commas.
How can I fetch the json into web api and get the specific data?
For example, this is my web api "https://api.coinmarketcap.com/v2/ticker/1/" and the output is like this:
{
"data": {
"id": 1,
"name": "Bitcoin",
"symbol": "BTC",
"website_slug": "bitcoin",
"rank": 1,
"circulating_supply": 17145625.0,
"total_supply": 17145625.0,
"max_supply": 21000000.0,
"quotes": {
"USD": {
"price": 6196.07,
"volume_24h": 3623440000.0,
"market_cap": 106235492694.0,
"percent_change_1h": -0.08,
"percent_change_24h": -2.9,
"percent_change_7d": -6.64
}
},
"last_updated": 1531423345
},
"metadata": {
"timestamp": 1531423031,
"error": null
}
}
I want a code how I can open the "web api link", "get the json into web api", "get the data in json".
I'm not really sure what language you are using. It would be helpful to provide that information in the tags or the question itself
If you are using python 3.7
import json
from urllib.request import urlopen
myjson = JSON.loads(urlopen("https://api.coinmarketcap.com/v2/ticker/1/"))
Here you will get the json deserialized into native python nested arrays and dictionaries (dictionaries in your case).
From this you can access elements from the json just like you would any element from a normal python dictionary. For example if I wanted to access the id
myjson["data"]["id"]
Hope this helped! Best of luck... please reply what language you are using and any frameworks so the community can help you in the best way.
How do I access only certain parts of JSON response? Is this even possible?
I get the whole response to show up on my EJS template as:
{ "result": { "price": { "last": 2086.004, "high": 2228.857, "low": 1980, "change": { "percentage": -0.048247334, "absolute": -105.74609 } }, "volume": 11616.328 }, "allowance": { "cost": 4279664, "remaining": 3766767537 } }
With:
var rows =<%-JSON.stringify(data)%>
document.getElementById("1").innerHTML = rows;
But how would I access, let’s say result.price.last?
I've tried all kind of approaches, but none seem to work.
As #Andrew Li proposed, rows.result.price.last, I could swear I tried it at least twice, Oh well, it works now.
Disclaimer: this is my first time attempting to write in Javascript; I don't know what I am doing.
I tried looking for example of this, but everything I found has the JSON object included in Javascript. Trying to return just the price_usd from this JSON
https://api.coinmarketcap.com/v1/ticker/bitcoin/
[
{
"id": "bitcoin",
"name": "Bitcoin",
"symbol": "BTC",
"rank": "1",
"price_usd": "972.935",
"price_btc": "1.0",
"24h_volume_usd": "501202000.0",
"market_cap_usd": "15650425175.0",
"available_supply": "16085787.0",
"total_supply": "16085787.0",
"percent_change_1h": "-2.35",
"percent_change_24h": "-17.36",
"percent_change_7d": "2.55",
"last_updated": "1483690766"
}
]
My current code in the linked function box is :
return {payload:msg.payload.price_usd};
msg.payload returns undefined. Tried with both http request set to return as parsed JSON object and as UTF-8 string.
The response is surrounded by [ ]. This indicates it's an array. So you need to reference into that array to get to the data.
msg.payload[0].price_usd