Skip to content

Instantly share code, notes, and snippets.

@pingiun
Last active July 30, 2020 13:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pingiun/98d231eda06b1af25998bbd8d60d68a5 to your computer and use it in GitHub Desktop.
Save pingiun/98d231eda06b1af25998bbd8d60d68a5 to your computer and use it in GitHub Desktop.
Get the latest BTC price from Bisq and compare with Coinbase. This script is a Bitbar plugin: https://getbitbar.com
#!/usr/local/bin/bash
# Donations are always apreciated: 337tQLpE6u7itDzju1d3zdnWBr1qR9mNNW
# Can be changed to any currency both Bisq and Coinbase support (usd, eur are tested)
currency="eur"
alt_currency="usd"
tickers=$(curl -sS "https://markets.bisq.network/api/ticker/")
coinbase=$(curl -sS "https://api.coinbase.com/v2/prices/BTC-${currency}/buy")
coinbase_buy=$(/usr/local/bin/jq -r ".data.amount" <<< "${coinbase}")
alt_coinbase=$(curl -sS "https://api.coinbase.com/v2/prices/BTC-${alt_currency}/buy")
alt_coinbase_buy=$(/usr/local/bin/jq -r ".data.amount" <<< "${alt_coinbase}")
# Coinbase buy and sell are reversed from Bisq
btc_last=$(/usr/local/bin/jq -r ".btc_${currency}.last" <<< "${tickers}")
btc_buy=$(/usr/local/bin/jq -r ".btc_${currency}.buy" <<< "${tickers}")
btc_sell=$(/usr/local/bin/jq -r ".btc_${currency}.sell" <<< "${tickers}")
bsq_buy=$(/usr/local/bin/jq -r ".bsq_btc.buy" <<< "${tickers}")
bsq_sell=$(/usr/local/bin/jq -r ".bsq_btc.sell" <<< "${tickers}")
bsq_price=$(echo "${coinbase_buy} * ${bsq_sell}" | bc)
# Alternative currency
alt_btc_last=$(/usr/local/bin/jq -r ".btc_${alt_currency}.last" <<< "${tickers}")
alt_btc_buy=$(/usr/local/bin/jq -r ".btc_${alt_currency}.buy" <<< "${tickers}")
alt_btc_sell=$(/usr/local/bin/jq -r ".btc_${alt_currency}.sell" <<< "${tickers}")
alt_bsq_buy=$(/usr/local/bin/jq -r ".bsq_btc.buy" <<< "${tickers}")
alt_bsq_sell=$(/usr/local/bin/jq -r ".bsq_btc.sell" <<< "${tickers}")
alt_bsq_price=$(echo "${alt_coinbase_buy} * ${bsq_sell}" | bc)
if (( $(echo "${coinbase_buy} < ${btc_sell}" | bc -l) )); then
color="|color=red"
elif (( $(echo "${coinbase_buy} > ${btc_sell}" | bc -l) )); then
color="|color=green"
fi
printf "₿%.2f${color}\n" "${btc_sell}"
echo "---"
echo "Last: ${btc_last}"
echo "Last: ${alt_btc_last}|alternate=true"
echo "Buy: ${btc_sell}"
echo "Buy: ${alt_btc_sell}|alternate=true"
echo "Sell: ${btc_buy}"
echo "Sell: ${alt_btc_buy}|alternate=true"
echo "BSQ Buy: ${bsq_sell}"
echo "BSQ Buy: ${alt_bsq_sell}|alternate=true"
echo "BSQ Sell: ${bsq_buy}"
echo "BSQ Sell: ${alt_bsq_buy}|alternate=true"
printf "1 BSQ=%.2f ${currency^^}\n" "${bsq_price}"
printf "1 BSQ=%.2f ${alt_currency^^}|alternate=true\n" "${alt_bsq_price}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment