Is there an easy way to show stock price?

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:
    getQuote API | Barchart OnDemand

  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