This should be pretty easy to solve for you guys.
I would like to display a crypto coin price on my remote - refreshing every 30mins or so.
API call is: “https://api.coingecko.com/api/v3/simple/price?ids=nemesis-dao&vs_currencies=usd”
Return value in json is: {“nemesis-dao”:{“usd”:190.34}}
Just need a label showing: “190.34”
How?
THX!
Attached is a plugin showing how to display the value of “nemesis-dao” from CoinGecko.
CoinGecko.hrp (123.1 KB)
CoinGecko.plugin (1.1 KB)
CoinGeckoTile.xaml (1.1 KB)
plugin.Name = "CoinGecko";
plugin.OnChangeRequest = onChangeRequest;
plugin.OnConnect = onConnect;
plugin.OnDisconnect = onDisconnect;
plugin.OnPoll = onPoll;
plugin.OnSynchronizeDevices = onSynchronizeDevices;
plugin.PollingInterval = 1800000;
plugin.DefaultSettings = {};
var http = new HTTPClient();
function onChangeRequest(device, attribute, value) {
}
function onConnect() {
}
function onDisconnect() {
}
function onPoll() {
for (var deviceId in plugin.Devices) {
var device = plugin.Devices[deviceId];
var response = http.get("https://api.coingecko.com/api/v3/simple/price?ids=" + deviceId + "&vs_currencies=usd");
var json = response.data;
device.usd = json[deviceId]["usd"];
}
}
function onSynchronizeDevices() {
var coinGeckoDevice = new Device();
coinGeckoDevice.Id = "nemesis-dao";
coinGeckoDevice.DisplayName = "Nemesis DAO";
coinGeckoDevice.Capabilities = [];
coinGeckoDevice.Attributes = ["usd"];
coinGeckoDevice.TileTemplate = "CoinGeckoTile.xaml";
plugin.Devices[coinGeckoDevice.Id] = coinGeckoDevice;
}
WOW! That was fast!
It works!
Thanks so much!
Got another one of those…
Entering this:
https://api.coingecko.com/api/v3/simple/price?ids=ethereum&vs_currencies=usd&include_24hr_change=true
gets this:
{
"ethereum": {
"usd": 1712.08,
"usd_24h_change": -3.2755194542350505
}
}
What I would like to get out of this is a simple button/image change.
If "usd_24h_change" is a negative number --> show ethereum_red.png
If "usd_24h_change" is a positive number --> show ethereum_green.png
Doable? THX