Last active
November 1, 2021 18:24
-
-
Save mattchilds1/a679dcc24e149a7585ac479ffaab84dc to your computer and use it in GitHub Desktop.
xbar plugin to display coin gecko portfolio price for single coin
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
| #!/bin/bash | |
| # <xbar.title>Coingecko - Portfolio Price</xbar.title> | |
| # <xbar.version>v0.0.1</xbar.version> | |
| # <xbar.author>MattChilds</xbar.author> | |
| # <xbar.author.github>mattchilds1</xbar.author.github> | |
| # <xbar.desc>Displays current portfolio amount of a particular coin using Coingecko data.</xbar.desc> | |
| # <xbar.image></xbar.image> | |
| # <xbar.dependencies>bash,jq</xbar.dependencies> | |
| # <xbar.abouturl>https://github.com/mattchilds1 // TODO Add Gist</xbar.abouturl> | |
| # ******************* Config ******************* | |
| COIN_ID="" # COIN ID from coingecko GET /coins/list e.g. bitcoin | |
| CURRENCY="usd" # Currency to display amount in e.g. USD | |
| NUMBER_OF_COINS=2 # Holding of currency, e.g. 2 or 20000 (if you're lucky) | |
| ICON="🤑" # Icon to be used in Menu bar | |
| # ********************************************** | |
| PATH=/usr/local/bin:${PATH} | |
| export PATH | |
| LANG=en_US.UTF-8 | |
| export LANG | |
| if [ ! $(command -v jq) ]; then | |
| echo "⚠" | |
| echo "---" | |
| echo "jq Not Installed" | |
| echo "---" | |
| echo "Refresh | refresh=true" | |
| exit | |
| fi | |
| API_RESULT=$(curl -X 'GET' https://api.coingecko.com/api/v3/simple/price\?ids=$COIN_ID\&vs_currencies=$CURRENCY -H 'accept: application/json') | |
| # TEST DATA TOGGLE API_RESULT="{\"hoge-finance\":{\"usd\":123443}}" | |
| # Problem calling API | |
| if [ -z "$API_RESULT" ]; then | |
| echo "⚠" | |
| echo "---" | |
| echo "No Information" | |
| echo "Refresh | refresh=true" | |
| exit | |
| fi | |
| PRICE=$(echo $API_RESULT | jq -r '."'$COIN_ID'".'$CURRENCY'') | |
| CURRENT_VALUE=$(echo "$PRICE * $NUMBER_OF_COINS" | bc -l) | |
| echo "$ICON $CURRENT_VALUE" | |
| echo "---" | |
| # Options | |
| echo "---" | |
| echo "Update | refresh=true" | |
| echo "-- Open Plugin Folder… | href=file://${0%/*}/" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment