Created
March 6, 2023 00:04
-
-
Save ms3056/3712f80b92337c32fbbb7cb4e00eb47f to your computer and use it in GitHub Desktop.
Obsidian Crypto Snippet
This file contains 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
function roundToTwo(num) { | |
return +(Math.round(num + "e+2") + "e-2"); | |
} | |
async function start(symbol) { | |
const headers = { 'X-Api-Key': 'YOUR_API_KEY' }; | |
// const symbol = 'ETHUSD'; | |
const url = `https://api.api-ninjas.com/v1/cryptoprice?symbol=${symbol}`; | |
const quoteData = await requestUrl({ url: url, headers }); | |
console.log(quoteData); | |
if (quoteData.status >= 400 && request.throw) { | |
console.log(quoteData); | |
return `*Something went wrong!*`; | |
} | |
const data = quoteData.json; | |
let sym; | |
let price; | |
sym = data.symbol; | |
price = roundToTwo(parseFloat(data.price)); | |
return `${sym} — **\$${price}**`; | |
} | |
module.exports = start; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Requirements
Usage
<% tp.user.crypto("symbol") %>
where symbol is the crypto you are interested in such as ETHUSD