# ==============================================
# Configuration
PRIVKEY="PUT A HEX PRIVKEY HERE"
RELAY="wss://nostr-pub.wellorder.net"
RELAYBIS="wss://relay.nostr.band"
RELAYFALLBACK="wss://relay.damus.io"
POW=10
# Set the bet date and target
bet_date="2023-03-17 19:30:00"
target_btc_price=1000000
# Function to get the current Bitcoin price
get_btc_price() {
price=$(curl -s https://api.coindesk.com/v1/bpi/currentprice/BTC.json | jq '.bpi.USD.rate_float')
echo "${price}"
}
# Function to calculate the remaining time
get_remaining_time() {
now=$(date +%s)
end=$(date -d "$bet_date" +%s)
remaining_time=$(( end + 90 * 24 * 60 * 60 - now ))
echo "${remaining_time}"
}
# Function to format the price difference
format_price_difference() {
printf "%'d" "$(echo "$1" | awk '{print int($1+0.5)}')"
}
# Function to calculate the multiplier
calculate_multiplier() {
btc_price="$1"
difference="$2"
multiplier=$(echo "scale=2; $difference / $btc_price" | bc)
echo "${multiplier}"
}
# Function to build the remaining time message
build_remaining_time_message() {
days="$1"
hours="$2"
minutes="$3"
message=""
if (( days > 0 )); then
message="${days} days"
fi
if (( hours > 0 )); then
message="${message}${message:+, }${hours} hours"
fi
if (( minutes > 0 )); then
message="${message}${message:+, }${minutes} minutes"
fi
echo "$message"
}
# Main loop
while true; do
remaining_time=$(get_remaining_time)
# Check if the bet has ended
if (( remaining_time <= 0 )); then
btc_price=$(get_btc_price)
if (( $(echo "$btc_price >= $target_btc_price" | bc -l) )); then
MSG="The bet has ended. Balajis has won the bet!"
nostril --envelope --pow "$POW" --sec "$PRIVKEY" --content "$MSG" | tee >(websocat $RELAY) >(websocat $RELAYBIS) >(websocat $RELAYFALLBACK)
else
MSG="The bet has ended. Balajis has lost bet."
nostril --envelope --pow "$POW" --sec "$PRIVKEY" --content "$MSG" | tee >(websocat $RELAY) >(websocat $RELAYBIS) >(websocat $RELAYFALLBACK)
fi
exit 0
fi
# Calculate remaining time
days=$(( remaining_time / (24 * 60 * 60) ))
hours=$(( (remaining_time % (24 * 60 * 60)) / (60 * 60) ))
minutes=$(( (remaining_time % (60 * 60)) / 60 ))
# Get the current Bitcoin price
btc_price=$(get_btc_price)
difference=$(echo "$target_btc_price - $btc_price" | bc)
formatted_difference=$(format_price_difference "$difference")
multiplier=$(calculate_multiplier "$btc_price" "$difference")
# Determine when the next check will be
if (( days > 0 )); then
next_check="in 1 day"
sleep_duration="1d"
elif (( hours > 0 )); then
next_check="in 1 hour"
sleep_duration="1h"
else
next_check="in 1 minute"
sleep_duration="1m"
fi
remaining_time_message=$(build_remaining_time_message "$days" "$hours" "$minutes")
# Display the message
MSG="The bet will end in $remaining_time_message. Bitcoin has to go up $formatted_difference USD ($multiplier X) for the bet to be won by Balajis. "
ecHo "Next check: $next_check"
nostril --envelope --pow "$POW" --sec "$PRIVKEY" --content "$MSG" | tee >(websocat $RELAY) >(websocat $RELAYBIS) >(websocat $RELAYFALLBACK)
# Sleep until the next check
sleep "$sleep_duration"
done