Skip to content

Instantly share code, notes, and snippets.

@kaosf
Last active March 24, 2024 11:53
Show Gist options
  • Save kaosf/3e70f3e75a41438bd93495d889051ee0 to your computer and use it in GitHub Desktop.
Save kaosf/3e70f3e75a41438bd93495d889051ee0 to your computer and use it in GitHub Desktop.
Get cryptocurrency price history with CoinGecko
# Get every month (almost) open price.
# Bash, curl and jq are required.
# Modify YEAR, ID, +09:00 and jpy for yourself.
YEAR=2023
ID=bitcoin
for MONTH in $(seq -w 1 12); do
FROM=$(date --date="${YEAR}-${MONTH}-01T00:00:00+09:00" +"%s")
TO=$( date --date="${YEAR}-${MONTH}-01T01:00:00+09:00" +"%s")
FILENAME=${YEAR}-${MONTH}.json
if [ ! -f $FILENAME ]; then
sleep 1m
curl "https://api.coingecko.com/api/v3/coins/${ID}/market_chart/range?vs_currency=jpy&from=${FROM}&to=${TO}" > $FILENAME
fi
cat $FILENAME | jq '.prices[][1]'
done
# ref. https://www.coingecko.com/api/documentations/v3#/coins/get_coins__id__market_chart_range
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment