Problem with TWO different wget statements in KWGT:
A) $wg(gv(fullurl), json, .['Time Series (Daily)'].['2018-04-03'].[0])$
B) $wg(gv(fullurl), json, .['Meta Data'].[0])$
fullurl=https://www.alphavantage.co/query?function=TIME_SERIES_DAILY&symbol=MSFT&apikey=[MYAPIKEY]
If I execute $wg(gv(fullurl), json, .['Meta Data'])$ (without the [0]) I get the following:
{1. Information=Daily Prices (open, high, low, close) and Volumes, 2. Symbol=MSFT, etc...
This data should be AN ARRAY of data, but appears to be a string instead
Statement B above COMPLETELY fails (no output). My best guess is that the parenthesis in the json key are causing the issue, but I am not entirely sure.
Am I missing something?
Actual results (truncated here) in a browser or via curl are:
{
"Meta Data": {
"1. Information": "Daily Prices (open, high, low, close) and Volumes",
"2. Symbol": "MSFT",
},
"Time Series (Daily)": {
"2018-04-03": {
"1. open": "89.5750",
"2. high": "90.0400",
},
Use bracket notation or dot notation. Not both.
$wg(gv(fullurl), json, ['Time Series (Daily)']['2018-04-03'][0])$
or
$wg(gv(fullurl), json, ".Time Series (Daily).2018-04-03[0]")$
Bracket notation would most likely work better in this scenario due to the spaces in your JSON element names.
I have been cracking my head over this. The json has changed slightly since the original post was made but the challenge remains. The current JSON looks something like this.
{
"Meta Data": {
"1. Information": "Daily Prices (open, high, low, close) and Volumes",
"2. Symbol": "MSFT",
"3. Last Refreshed": "2018-08-10",
"4. Output Size": "Compact",
"5. Time Zone": "US/Eastern"
},
"Time Series (Daily)": {
"2018-08-10": {
"1. open": "109.4200",
"2. high": "109.6900",
"3. low": "108.3800",
"4. close": "109.0000",
"5. volume": "18119408"
},
"2018-08-09": {
"1. open": "109.7100",
"2. high": "110.1600",
"3. low": "109.6000",
"4. close": "109.6700",
"5. volume": "13677211"
},
"2018-08-08": {
"1. open": "109.3300",
"2. high": "109.7500",
"3. low": "108.7599",
"4. close": "109.4900",
"5. volume": "15487502"
}
}
}
I need to get the value from "4. close" from the second node in "Time Series (Daily). On tuesday till saturday I can achieve this with .['Time Series (Daily)']['$df(yyyy-MM-DD, r1d)$']['4. close'] . This however wont work on sunday and monday because the stock markets are not open on the previous days of these two days.
So I somehow need a way to select the second node but I dont seem to be able to achieve this. Using stuff like .['Time Series (Daily)'][1]['4. close'] is not working. Strangely I can get the value from "4. close" of the first node using this: .['Time Series (Daily)'][*]['4. close'] .
Any solution to this?
replace your df() function with if(df(f)<3, df(yyyy-MM-dd, "r"+(df(f)+1)+"d"), df(yyyy-MM-dd, r1d))
Thanx Joshua, looks like the right direction. Trying to get my head around it. It's not working correctly yet. If I use it today (on a Sunday) it still gives me the date of yesterday (Saturday) while it s should give me the date of Friday.
I'm on the road right now but I'll see if I can tweak it further.
For reference, I fixed it with the following formula.
$if(df(f)=1, df(yyyy-MM-dd, r3d), df(f)=6, df(yyyy-MM-dd, r2d), df(f)=7, df(yyyy-MM-dd, r3d), df(f)>1&df(f)<6, df(yyyy-MM-dd), 1rd)$