Last active
September 5, 2021 22:28
-
-
Save togosh/0a651c5c68e1649a2292dcaca2e21c58 to your computer and use it in GitHub Desktop.
Nomics API Price of HEX - https://nomics.com/docs/#operation/getCurrenciesTicker
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // 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