Last active
March 24, 2024 11:53
-
-
Save kaosf/3e70f3e75a41438bd93495d889051ee0 to your computer and use it in GitHub Desktop.
Get cryptocurrency price history with CoinGecko
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
# 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 |
Public Domain
NYSL
WTFPL
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Trackback