diff --git a/1d.sh b/1d.sh new file mode 100644 index 0000000000000000000000000000000000000000..96ce0ad0c21f8f7d9b9a294ecb766594f3744938 --- /dev/null +++ b/1d.sh @@ -0,0 +1,43 @@ +#!/bin/bash + +DB_USER="root" +DB_PASS="" +DB_HOST="localhost" +DB_NAME="bitcoin" + +URL="https://api.cryptocompare.coindesk.com/index/cc/v1/historical/hours?market=cadli&instrument=BTC-USD&limit=25" + +FILE="/mnt/c/xampp/htdocs/1314_data_management_2/1d.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 \`day\` (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