Stock Market Tiles?


#1

1) Give a description of the problem
I’m building a dashboard using piston examples others have posted. I already have tiles for weather, battery levels, etc. but I’d like to also include a couple of tiles that display near-real-time stock market performance. Does anyone have any suggestions as to where/how I can access an API that might provide that info? Has anyone done this already?

2) What is the expected behavior?
There would be two tiles on my dashboard that display current levels for the DJIA and S&P 500 indices.

3) What is happening/not happening?
Nothing is happening because I don’t know quite where to start.


#2

After spending most of the day working on this I managed to find an API that provides stock market info and send a request to it. It looks like I’m getting a valid response but I have been unable to figure out how to access the individual elements in the response. I looked at any example pistons I could find and have tried multiple permutations but haven’t been successful. I searched the WebCoRE wiki for JSON and get “There were no results matching the query.”

Does anyone know how I go about grabbing individual data elements from the data that’s being returned? I’ve researched the format of a json response but what I’m getting back doesn’t seem to match the format that’s described in what I’ve read.

Any help is appreciated.

The piston that makes the call:

Here’s the log (what I see in a browser is below this):

11/3/2017, 6:54:24 PM +288ms
+0ms ╔Received event [Home].time = 1509756865289 with a delay of -1001ms
+139ms ║RunTime Analysis CS > 18ms > PS > 66ms > PE > 51ms > CE
+158ms ║Runtime (37373 bytes) successfully initialized in 66ms (v0.2.0f9.20171007) (156ms)
+161ms ║╔Execution stage started
+177ms ║║Cancelling statement #2’s schedules…
+198ms ║║Sending external web request to: www.alphavantage.co/query?function=TIME_SERIES_DAILY_ADJUSTED&symbol=DJI&apikey=xxxxxxxxxxxxxxx
+626ms ║║Executed virtual command httpRequest (431ms)
+651ms ║║Meta Data:[5. Time Zone:US/Eastern, 2. Symbol:Dow Jones Industrial Average Index, 1. Information:Daily Time Series with Splits and Dividend Events, 3. Last Refreshed:2017-11-03, 4. Output Size:Compact], Time Series (Daily):2017-09-05:[3. low:21709.6309, 4. close:21753.3105, 5. adjusted close:21753.3105, 2. high:21921.0898, 6. volume:332840000, 1. open:21912.3691, 8. split coefficient:1.0000, 7. dividend amount:0.0000], 2017-09-06:[3. low:21794.0703, 4. close:21807.6406, 5. adjusted close:21807.6406, 2. high:21849.2402, 6. volume:318760000, 1. open:21815.7598, 8. split coefficient:1.0000, 7. dividend amount:0.0000], 2017-09-07:[3. low:21745.7109, 4. close:21784.7793, 5. adjusted close:21784.7793, 2. high:21850.0098, 6. volume:333810000, 1. open:21820.3809, 8. split coefficient:1.0000, 7. dividend amount:0.0000], 2017-09-08:[3. low:21731.1191, 4. close:21797.7891, 5. adjusted close:21797.7891, 2. high:21846.6309, 6. volume:289400000, 1. open:21764.4297, 8. split coefficient:1.0000, 7. dividend amount:0.0000],…[TRUNCATED]
+652ms ║║Executed virtual command log (9ms)
+656ms ║╚Execution stage complete. (498ms)
+658ms ║Setting up scheduled job for Fri, Nov 3 2017 @ 6:55:25 PM MDT (in 60.344s)
+872ms ╚Event processed successfully (872ms)

What I see in a browser:

{
“Meta Data”: {
“1. Information”: “Daily Time Series with Splits and Dividend Events”,
“2. Symbol”: “Dow Jones Industrial Average Index”,
“3. Last Refreshed”: “2017-11-03”,
“4. Output Size”: “Compact”,
“5. Time Zone”: “US/Eastern”
},
“Time Series (Daily)”: {
“2017-11-03”: {
“1. open”: “23549.5898”,
“2. high”: “23557.0605”,
“3. low”: “23481.5703”,
“4. close”: “23539.1895”,
“5. adjusted close”: “23539.1895”,
“6. volume”: “312254782”,
“7. dividend amount”: “0.0000”,
“8. split coefficient”: “1.0000”
},
“2017-11-02”: {
“1. open”: “23463.2402”,
“2. high”: “23531.3809”,
“3. low”: “23350.9805”,
“4. close”: “23516.2598”,
“5. adjusted close”: “23516.2598”,
“6. volume”: “348040000”,
“7. dividend amount”: “0.0000”,
“8. split coefficient”: “1.0000”
},
“2017-11-01”: {
“1. open”: “23442.9004”,
“2. high”: “23517.7109”,
“3. low”: “23388.9102”,
“4. close”: “23435.0098”,

  • Truncated -

#3

Try using parse json action. Then you should be able to access it by $json variable.

Are you wanting specific things from the return or to run through everything?

For example if you are just wanting the most recent values for open/high/low/close
$json.Time Series (Daily)[0].open
Although the spaces might not be there but you should pick up on what it is doing.

Or

Do you want to access all the information that is returned across all the days?


#4

I’d like to run the piston every hour and get the most recent high. Last night I realized I was getting an error when parsing the response. I used an online parser to parse the response being returned to WebCoRE and get this message:

If I use a browser to execute the query and copy and paste the results to the parser, it parses without an error.

Here’s the updated piston and the new log. It’s the red version as I’m using a publicly available demo key.

1ms ╔Received event [Home].time = 1509814975695 with a delay of -1425ms
+135ms ║RunTime Analysis CS > 20ms > PS > 60ms > PE > 55ms > CE
+146ms ║Runtime (48569 bytes) successfully initialized in 60ms (v0.2.0f9.20171007) (144ms)
+148ms ║╔Execution stage started
+163ms ║║Cancelling statement #2’s schedules…
+174ms ║║Sending external web request to: www.alphavantage.co/query?function=TIME_SERIES_INTRADAY&symbol=MSFT&interval=1min&apikey=demo
+680ms ║║Executed virtual command httpRequest (507ms)
+684ms ║║Error parsing JSON data [:]
+685ms ║║Executed virtual command parseJson (2ms)
+692ms ║║[:]
+692ms ║║Executed virtual command log (1ms)
+701ms ║║Executed virtual command setVariable (4ms)
+704ms ║╚Execution stage complete. (557ms)
+705ms ║Setting up scheduled job for Sat, Nov 4 2017 @ 11:03:55 AM MDT (in 60.72s)
+813ms ╚Event processed successfully (812ms)

I also tried this but get an error:


#5

looks like its already parsed in $response. have you tried accessing $response… instead of parsing then accessing $json?


#6

I have been working on the same problem after seeing this post yesterday. I too am stuck. Although i am trying to use what is in $response as you suggest. The biggest problem i seem to be having is the API returns spaces in the labels for a field. So when i try to use the field label in a value or expression i get an error. If someone could help me with the syntax of:

to set a variable equal to say the Symbol value in the following $ response I think i would be able to figure this out.

Meta Data:[5. Time Zone:US/Eastern, 2. Symbol:Dow Jones Industrial Average Index, 1. Information:Daily Time Series with Splits and Dividend Events, 3. Last Refreshed:2017-11-03, 4. Output Size:Compact], Time Series (Daily):2017-09-05:[3. low:21709.6309, 4. close:21753.3105, 5. adjusted close:21753.3105, 2. high:21921.0898, 6. volume:332840000, 1. open:21912.3691, 8. split coefficient:1.0000, 7. dividend amount:0.0000], 2017-09-06:[3. low:21794.0703, 4. close:21807.6406, 5. adjusted close:21807.6406, 2. high:21849.2402, 6. volume:318760000, 1. open:21815.7598, 8. split coefficient:1.0000, 7. dividend amount:0.0000], 2017-09-07:[3. low:21745.7109, 4. close:21784.7793, 5. adjusted close:21784.7793, 2. high:21850.0098, 6. volume:333810000, 1. open:21820.3809, 8. split coefficient:1.0000, 7. dividend amount:0.0000], 2017-09-08:[3. low:21731.1191, 4. close:21797.7891, 5. adjusted close:21797.7891, 2. high:21846.6309, 6. volume:289400000, 1. open:21764.4297, 8. split coefficient:1.0000, 7. dividend amount:0.0000],…[TRUNCATED]


#7

I found an alternate source of data but with the DST issues I cannot continue testing for a while.


split this topic #8

A post was split to a new topic: Stock tiles piston


#9

moved the post below this to the piston example category: