Skip to content
Snippets Groups Projects
Commit 5709ffca authored by jc5e24's avatar jc5e24
Browse files

Upload New File

parent f9070ae1
Branches main
No related tags found
No related merge requests found
1d.sh 0 → 100644
#!/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
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment