Skip to content

Instantly share code, notes, and snippets.

@ms3056
Created March 6, 2023 00:04
Show Gist options
  • Save ms3056/3712f80b92337c32fbbb7cb4e00eb47f to your computer and use it in GitHub Desktop.
Save ms3056/3712f80b92337c32fbbb7cb4e00eb47f to your computer and use it in GitHub Desktop.
Obsidian Crypto Snippet
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;
@ms3056
Copy link
Author

ms3056 commented Mar 6, 2023

Requirements

  • Obsidian
  • Templater Plugin
  • API Key from api-ninjas.com

Usage

<% tp.user.crypto("symbol") %> where symbol is the crypto you are interested in such as ETHUSD

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment