Is there an easy way to show stock price?

Hi! Is there an easy way to show the latest stock price on my dashboard? Specifically, I am hoping to see the latest corn and soybean prices

Do you have access to an RSS feed or JSON feed that has stock prices?

If so, there’s options with either the RSS Feed tile or the Media Tile.

Bear with me as this is a bit of a Rube Goldberg setup, but I tried it out and if I understand what you’re looking for, I believe it accomplishes what you are looking for…

It looks like barchart.com has commodities data available via an API for free and we can combine that with shields.io (similar to this post) to generate an image for a Media Tile.

How to Setup a Custom Commodities Price Tile for Corn

Summary

Sign up for a barchart.com API Key. Replace the XXXX in the following URL with your API Key and use it as a Media Tile (set to refresh periodically).

Corn

https://img.shields.io/badge/dynamic/json.svg?label=%20&colorA=333&colorB=616161&query=$.results..lastPrice&style=flat-square&uri=https%3A%2F%2Fmarketdata.websol.barchart.com%2FgetQuote.json%3Fapikey%3DXXXX%26symbols%3DZC*1

Soybean

https://img.shields.io/badge/dynamic/json.svg?label=%20&colorA=333&colorB=616161&query=$.results..lastPrice&style=flat-square&uri=https%3A%2F%2Fmarketdata.websol.barchart.com%2FgetQuote.json%3Fapikey%3DXXXX%26symbols%3DZS*0

Detailed Steps

Click to view details
  1. Sign up for API access to barchart.com at this link:
    https://www.barchart.com/ondemand/api/getQuote/free

  2. Once you receive your API key, make note of it as we’ll use it in the following steps

  3. As a first step, you can try replacing the XXXX in the following link with your API Key and opening the link in your browser.

    https://marketdata.websol.barchart.com/getQuote.json?apikey=XXXX&symbols=ZC*1
    

    You should see a (encoded) response with the commodity data:

    {"status": {"code":200,"message":"Success."},
     "results":[{
       "symbol":"ZCZ19","exchange":"CBOT","name":"Corn","dayCode":"A",
       "serverTimestamp":"2019-10-11T00:00:00-05:00","mode":"d",
       "lastPrice":397.75,"tradeTimestamp":"2019-10-11T00:00:00-05:00",
       "netChange":17.5,"percentChange":4.6,"unitCode":"-1",
       "open":380.75,"high":398.75,"low":380.5,"close":397.75,"flag":"s","volume":253205
     }]
    }
    
  4. Once you have that, we’ll create an image that pulls out just the price using shields.io. Replace the XXXX in the following URL with your barchart.com API key:

    https://img.shields.io/badge/dynamic/json.svg?label=%20&colorA=333&colorB=616161&query=$.results..lastPrice&style=flat-square&uri=https%3A%2F%2Fmarketdata.websol.barchart.com%2FgetQuote.json%3Fapikey%3DXXXX%26symbols%3DZC*1
    

    Note that the query parameter in the URL is being used to pick which attribute from the previous response we want to display. This could be changed from lastPrice to netChange or any of the other attributes for example.

    When opened in your browser, it should show a small grey box with the “Last Price” of the Corn commodity:

  5. We can now take this URL and use it in a SharpTools Media Tile. Open your SharpTools Resources page and tap Media.

  6. Tap Create Media - enter a name (eg. Corn Price) and enter the long shields.io URL from above.
    Note: You’ll likely want this to refresh periodically, so be sure to check the ‘Autorefresh’ box and enter a refresh interval (eg. 30 minutes)

  7. Now we can add the media tile to our dashboard. Open your desired dashboard for editing and tap the + icon in the bottom-right corner of the dashboard. Expand the Media section and select your Corn Price media resource you just created.

    Note: Once the media item is added to your dashboard, you may want to adjust the tile to your liking. For example, I’ve adjusted my ‘Media Scaling’ to ‘Contain’, have adjusted the color of my tile to match the media item (the default grey), and added a label.

1 Like

Yes that is exactly what I am looking for. I will probably play with it a bit to see if I can get it to show just 3.97. The last 2 digits aren’t very important.

Thanks!

2 Likes

I got my free API key today and created a media tile using the URL and my key. I am getting an “invalid query parameter: URL” error as my media tile. Did I miss a step or does it take a while for the API key to work? Thanks!

Can you send me a PM with the URL you are trying (including the API Key)?

Edit: My apologies. I introduced a typo in the URL when I redacted my API key. I’ve updated the post above with the correct URLs.

1 Like

It is working now. Thanks again!

2 Likes

Thanks for this post, I’m able to pull up everything but Bitcoin prices. Can you show me how I could do this to get Bitcoin latest price?

ah I see, you have to use the symbol that is in the URL, not the one on the page

ZM*0 = ZMH20

I got it thanks

2 Likes

my code didn’t work, can anyone post the correct code on barchart that would allow me to show BTC prices?

From what I can tell, Cryptocurrencies aren’t part of barchart’s free API plan.

BTC Futures from Barchart

If you want to stick with barchart and their free plan, it looks like the following would work for BTC Futures:

https://img.shields.io/badge/dynamic/json.svg?label=%20&colorA=333&colorB=616161&query=$.results..lastPrice&style=flat-square&uri=https%3A%2F%2Fmarketdata.websol.barchart.com%2FgetQuote.json%3Fapikey%3DXXXX%26symbols%3DBT*0

That being said, a quick search for Bitcoin Price API returned a number of results. For example, the following URL could be used in a Media Tile to show recent BTC-USD price using Coindesk as a source:

https://img.shields.io/badge/dynamic/json.svg?label=%20&colorA=333&colorB=616161&query=$.bpi.USD.rate&style=flat-square&uri=https%3A%2F%2Fapi.coindesk.com%2Fv1%2Fbpi%2Fcurrentprice.json
1 Like

Thanks Josh that works, is there a way to remove everything right of the decimal?

Not that I’m aware of using the tools in this particular thread. You could try to find another API that provides the BTC price already rounded.

(I would guess that most APIs will return the decimal precision considering the most common use case for wanting to know BTC price via API)

Hi @LOUIE_S - regarding your question about how to show an exchange rate, specifically USD to PHP (Philippine Peso), here’s an URL that should work for you in a Media Tile:

http://img.shields.io/badge/dynamic/json.svg?label=%E2%82%B1&colorA=333&colorB=616161&query=$.rates.PHP&style=flat-square&uri=https%3A%2F%2Fapi.exchangeratesapi.io%2Flatest%3Fbase%3DUSD%26symbols%3DPHP

image

Notes (tap to expand)

This uses the API at exchangeratesapi.io:

https://api.exchangeratesapi.io/latest?base=USD&symbols=PHP

Which returns data in the format:

{"rates":{"PHP":50.59},"base":"USD","date":"2020-05-21"}

So our shields.io query is:

$.rates.PHP

Which results in the final Media Tile URL of:

http://img.shields.io/badge/dynamic/json.svg?label=%E2%82%B1&colorA=333&colorB=616161&query=$.rates.PHP&style=flat-square&uri=https%3A%2F%2Fapi.exchangeratesapi.io%2Flatest%3Fbase%3DUSD%26symbols%3DPHP

Josh. You are awesome. Thanks a lot. This will help a great deal.

1 Like