diff --git a/source/plugins/community/crypto/README.md b/source/plugins/community/crypto/README.md new file mode 100644 index 00000000000..948a99c5a29 --- /dev/null +++ b/source/plugins/community/crypto/README.md @@ -0,0 +1,100 @@ + + + + + + + + + + + + + + + + + + + +
← Back to plugins index

🪙 Crypto

+

This plugin generates an SVG image containing crypto metrics from a given address. It uses the CoinGecko API to fetch crypto prices.

+

For more information, check the CoinGecko API documentation.

+
Authors@dajneem23
Supported Features
→ Full specification
+ +
+
    +
  • 👤 Users
  • +
  • 👥 Organizations
  • +
  • 📓 Repositories
  • +
+
🗝️ plugin_crypto
+ + +
+ + +## ➡️ Available Options + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
OptionDescription

plugin_crypto

Enable crypto plugin

Type: boolean
Default: no

plugin_crypto_id

Crypto id (from Coingecko)

Type: string
Default: ""
Example: bitcoin

plugin_crypto_vs_currency

The target currency of market data (usd, eur, jpy, etc.)

Type: string
Default: "usd"
Example: "usd"

plugin_crypto_days

Data up to number of days ago (eg. 1,14,30,max)

Type: string
Default: "1"
Example: 1

plugin_crypto_precision

The number of decimal places to use

Type: number
Default: 2
Example: 2
+ + + + +```yaml +name: Crypto Metrics +uses: lowlighter/metrics@latest +with: + filename: metrics.plugin.crypto.svg + token: NOT_NEEDED + base: "" + plugin_crypto: yes + plugin_crypto_id: bitcoin + plugin_crypto_vs_currency: usd + plugin_crypto_days: 1 + plugin_crypto_precision: 2 +``` + diff --git a/source/plugins/community/crypto/examples.yml b/source/plugins/community/crypto/examples.yml new file mode 100644 index 00000000000..50a861758e0 --- /dev/null +++ b/source/plugins/community/crypto/examples.yml @@ -0,0 +1,13 @@ +- name: Crypto Metrics + uses: lowlighter/metrics@latest + with: + filename: metrics.plugin.crypto.svg + token: NOT_NEEDED + base: "" + plugin_crypto: yes + plugin_crypto_id: bitcoin + plugin_crypto_vs_currency: usd + plugin_crypto_days: 1 + plugin_crypto_precision: 2 + prod: + skip: true diff --git a/source/plugins/community/crypto/index.mjs b/source/plugins/community/crypto/index.mjs new file mode 100644 index 00000000000..9f2f9f80c86 --- /dev/null +++ b/source/plugins/community/crypto/index.mjs @@ -0,0 +1,73 @@ +//Setup +export default async function({login, q, imports, data, account}, {enabled = false, extras = false} = {}) { + //Plugin execution + try { + //Check if plugin is enabled and requirements are met + if ((!q.crypto) || (!imports.metadata.plugins.crypto.enabled(enabled, {extras}))) + return null + + //Load inputs + let {id, days, vs_currency, precision } = imports.metadata.plugins.crypto.inputs({data, account, q}) + if (!id) + throw { error: { message: "Crypto currency id is not set" } } + + console.debug(`metrics/compute/${login}/plugins > crypto > querying api for crypto`) + + const { + data: coin + } = await imports.axios.get(`https://api.coingecko.com/api/v3/coins/${id}`, + { + params: { + market_data:true + } + }) + + if (!coin) { + throw {error: {message: "Crypto currency not found"}} + } + + const { + data: { prices }, + } = await imports.axios.get(`https://api.coingecko.com/api/v3/coins/${id}/market_chart`, { + params: { + vs_currency, + days, + precision + }, + }) + + + const chart = imports.Graph.timeline( + prices.map((y, _) => ({ x: new Date(y[0]), y: y[1] })), + { + low: Math.min(...prices.map((y, _) => y[1])), + + high: Math.max(...prices.map((y, _) => y[1])), + + points: false, text: false, + width: 480 * (1 + data.large), + height: 200 + } + ) + + + //Results + return { + chart, + id, + precision, + days:{"1":"Today", "14":"2 Weeks", "30":"1 Month", max :"All-time"}[days], + symbol: coin.symbol, + name: coin.name, + current_price: coin.market_data.current_price[vs_currency], + price_change_percentage_24h: coin.market_data.price_change_percentage_24h, + vs_currency, + logo:coin.image.small, + } + } + //Handle errors + catch (error) { + throw imports.format.error(error) + } +} + diff --git a/source/plugins/community/crypto/metadata.yml b/source/plugins/community/crypto/metadata.yml new file mode 100644 index 00000000000..b68a2df9e91 --- /dev/null +++ b/source/plugins/community/crypto/metadata.yml @@ -0,0 +1,52 @@ +name: 🪙 Crypto +category: community +description: | + Generates a SVG image containing crypto metrics from a given address. + This plugin using coingecko API to fetch crypto prices. + check https://www.coingecko.com/vi/api/documentation for more information. +examples: + default: https://via.placeholder.com/468x60?text=No%20preview%20available +authors: + - dajneem23 +supports: + - user + - organization + - repository +scopes: [] +inputs: + + plugin_crypto: + description: | + Enable crypto plugin + type: boolean + default: no + + plugin_crypto_id: + description: | + Crypto id + type: string + default: "" + example: bitcoin + + plugin_crypto_vs_currency: + description: | + The target currency of market data (usd, eur, jpy, etc.) + type: string + default: "usd" + example: "usd" + + plugin_crypto_days: + description: | + Data up to number of days ago (eg. 1,14,30,max) + type: string + default: "1" + example: 1 + + plugin_crypto_precision: + description: | + The number of decimal places to use + type: number + default: 2 + example: 2 + + diff --git a/source/templates/classic/partials/_.json b/source/templates/classic/partials/_.json index dcc317eb823..775c443328b 100644 --- a/source/templates/classic/partials/_.json +++ b/source/templates/classic/partials/_.json @@ -33,6 +33,7 @@ "support", "stackoverflow", "leetcode", + "crypto", "stock", "achievements", "screenshot", diff --git a/source/templates/classic/partials/crypto.ejs b/source/templates/classic/partials/crypto.ejs new file mode 100644 index 00000000000..f98963f4d42 --- /dev/null +++ b/source/templates/classic/partials/crypto.ejs @@ -0,0 +1,68 @@ +<% if (plugins.crypto) { %> +
+

+ + <%= plugins.crypto.symbol ? `${plugins.crypto.symbol?.toUpperCase()}` : "" %> +

+ <% if (plugins.crypto.error) { %> +
+
+
+ + + + <%= plugins.crypto.error.message %> +
+
+
+ <% } else { %> +
+
+
+ + + + <%= `${plugins.crypto.current_price.toFixed(plugins.crypto.precision || 2) } ${plugins.crypto.vs_currency?.toUpperCase()}` %> +
+
+
+
+ + + + <%= plugins.crypto.days %> +
+
+
+
+ <% if (plugins.crypto.price_change_percentage_24h > 0) { %> + + + + <% } else { %> + + + + <% } %> <%= plugins.crypto.price_change_percentage_24h ?plugins.crypto.price_change_percentage_24h.toFixed(2) : 0 %>% +
+
+
+
<%- plugins.crypto.chart %>
+ <% } %> +
+<% } %> diff --git a/source/templates/repository/partials/_.json b/source/templates/repository/partials/_.json index 67a63c08e74..2422896dfc7 100644 --- a/source/templates/repository/partials/_.json +++ b/source/templates/repository/partials/_.json @@ -12,6 +12,7 @@ "rss", "screenshot", "stock", + "crypto", "contributors", "sponsors", "licenses"