Skip to content

Instantly share code, notes, and snippets.

@jvalrog
Created January 28, 2018 10:15
Show Gist options
  • Save jvalrog/d123a5129a3a5de1a1aad612be851dc3 to your computer and use it in GitHub Desktop.
Save jvalrog/d123a5129a3a5de1a1aad612be851dc3 to your computer and use it in GitHub Desktop.
GDAX bash tool to download currency pair prices
#!/bin/bash
function perror {
echo "$*" >&2
}
function check_dependency {
if ! command -v $1 &> /dev/null
then
perror "Missing dependency: '$1'. Please install it first."
exit 1
fi
}
if [ $# -ne 1 ]
then
perror "Usage: $(basename $0) <currency pair>"
perror
perror " * <currency pair> is a supported GDAX.COM currency pair like:"
perror " BTC-USD, BTC-EUR, ETH-BTC, ..."
perror
perror " * Example: \"$(basename $0) BTC-USD\""
exit 2
fi
check_dependency "curl"
check_dependency "jq"
check_dependency "tr"
pair_data=$(curl -s https://api.gdax.com/products/$1/ticker)
if [ $? -ne 0 ]
then
perror "Error while downloading currency pair data."
perror "Please check your internet connection."
exit 3
fi
price=$(echo $pair_data | jq '.ask' | tr -d '"')
if [ "$price" = "null" ]
then
perror "Error processing pair data."
perror "Please check if the currency pair is supported by GDAX.COM or wrongly spelled."
exit 3
fi
echo $price
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment