diff --git a/1h.sh b/1h.sh new file mode 100644 index 0000000000000000000000000000000000000000..cb8e574a00bd52b710e4be35f2d34b77201e03a0 --- /dev/null +++ b/1h.sh @@ -0,0 +1,44 @@ +#!/bin/bash + +DB_USER="root" +DB_PASS="" +DB_HOST="localhost" +DB_NAME="bitcoin" + +URL="https://api.cryptocompare.coindesk.com/index/cc/v1/historical/minutes?market=cadli&instrument=BTC-USD&limit=61" + +FILE="/mnt/c/xampp/htdocs/1314_data_management_2/1h.txt" + +function fetch() +{ + echo "Fetching data..." + curl -s -L "$URL" > "$FILE" + if [[ $? -ne 0 ]]; then + echo "Failed to fetch data from $URL" + exit 1 + fi +} + +function analysis() +{ + echo "Analyzing data..." + open=$(jq -r '.Data[0].OPEN' "$FILE") + high=$(jq -r '.Data[0].HIGH' "$FILE") + low=$(jq -r '.Data[0].LOW' "$FILE") + volume=$(jq -r '.Data[0].VOLUME' "$FILE") + quote_volume=$(jq -r '.Data[0].QUOTE_VOLUME' "$FILE") + open=$(printf "%.8f" $open) + high=$(printf "%.8f" $high) + low=$(printf "%.8f" $low) + volume=$(printf "%.8f" $volume) + quote_volume=$(printf "%.8f" $quote_volume) + tim=$(jq -r '.Data[0].TIMESTAMP' "$FILE") + real_tim=$(date -d @$tim '+%Y-%m-%d %H:%M:%S') + SQL_QUERY="INSERT INTO \`hour\`(price, time, highest_price, lowest_price, trading_volume, total_quoted_quantity) VALUES($open, '$real_tim', $high, $low, $volume ,$quote_volume)" + mysql -u "$DB_USER" -h "$DB_HOST" -D "$DB_NAME" -e "$SQL_QUERY" +} + +fetch + +analysis +