Crypto Polling (Rule/Tile)

I also have a requirement for a recurring rule trigger where I want to poll an API to get the latest crypto values every x minutes. I can then set dashboard signals to indicate if the value reaches a point where it would be good to sell the crypto etc.

How about creating a Custom Tile that polls the crypto api every x minute? So you can see the value updates in the dashboard without rule involved? (Feel free to pm me if you need some help to get started.)

Meanwhile, if you just need a quick crypto widget, you can also embed the widget as a tile as shown below.

image

1 Like

Thanks I started to build a custom tile for this but am getting a CORS error when I try to get the latest crypto information. I see that for hyperlink tiles you can bypass this using a proxy. Is this available for custom tiles too?

1 Like

Can you post your code somewhere (github) so we can help take a look? (Make sure you don’t expose your own api key anywhere in public.)

You should be able to send the REST api request in the Custom Tile without proxy. Since the CORS error is coming from the destination server (crypto api server), we need more info to better help.

var config = {
      proxy: true,
      headers: {    
        "X-CMC_PRO_API_KEY": apiKey        
      }      
    }    
     axios.get(url, config)

The proxy flag is only available for first-party tiles. In theory, you could use one of the online CORS proxy services - fine for generic API calls, but I would recommend against it for something where you are passing a private API key across.

It might be easier to find an alternative crypto API.

Ok thanks. I see in your realtime version you are using a proxy (https://allorigins.win/) to bypass the CORS issue. I wonder if I can just use a similar approach?

I would not recommend it if you’re including a private API key that has broad account access. Maybe if that API key only provides read-only access to market data in a way that couldn’t cause usage/consumption charges. The documentation from CoinMarketCap, which you appear to be using, strongly discourages using public CORS proxies.

Only because the realtime connection waits until the next price update before it reports the price across the socket. So instead of waiting, I layered in a REST API call to get the initial value and that particular service applies CORS restrictions even to their public endpoints.

Other APIs like the Coindesk one are public and don’t require CORS proxying.

1 Like

Ok all good thanks. I’ll try Coin Desk.

Ended up using https://min-api.cryptocompare.com.
Seems to do what I need and no CORS issues.

2 Likes