Skip to content

Instantly share code, notes, and snippets.

@togosh
Last active September 5, 2021 22:28
Show Gist options
  • Select an option

  • Save togosh/0a651c5c68e1649a2292dcaca2e21c58 to your computer and use it in GitHub Desktop.

Select an option

Save togosh/0a651c5c68e1649a2292dcaca2e21c58 to your computer and use it in GitHub Desktop.
// https://codeakk.medium.com/hex-development-data-a1b1822446fa
// https://togosh.medium.com/hex-developer-guide-3b018a943a55
// https://nomics.com/docs/#operation/getCurrenciesTicker
test();
async function test(){
var price = await getPrice();
console.log("Price: $" + Number(price).toLocaleString(undefined, {minimumFractionDigits:2, maximumFractionDigits:2}));
}
async function getPrice(){
try {
const resp = await fetch("https://api.nomics.com/v1/currencies/ticker?key=" + "XXXXXXXX" + "&ids=HEX");
const data = await resp.json();
if (data && data.length >= 1) {
var hexData = data[0];
if (hexData && hexData.price) {
hexPrice = parseFloat(hexData.price).toFixed(4).toString();
return hexPrice;
}
}
} catch (err) {
console.log("ERROR: " + err + "\n" + err.stack);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment