From f9070ae1b66e61e53e873d74735cb25032c6d5ba Mon Sep 17 00:00:00 2001 From: jc5e24 <jc5e24@soton.ac.uk> Date: Wed, 11 Dec 2024 04:33:16 +0000 Subject: [PATCH] Upload New File --- 1h.sh | 44 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 1h.sh diff --git a/1h.sh b/1h.sh new file mode 100644 index 0000000..cb8e574 --- /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 + -- GitLab