We will teach Python to monitor the cryptocurrency rate and notify if the rate is above or below the threshold.
We will connect the
requests library and import time:import requests
import time
We will create a function to get the BTC price in USD via the CoinGecko API:
def get_btc_price():
url = "https://api.coingecko.com/api/v3/simple/price?ids=bitcoin&vs_currencies=usd"
r = requests.get(url)
return r.json()["bitcoin"]["usd"]
Now β the main monitoring cycle. We will set a threshold and check the price every minute:
threshold = 65000 # specify your goal
while True:
price = get_btc_price()
print(f"BTC: ${price}")
if price > threshold:
print("π Time to sell!")
break
time.sleep(60)
π₯ You can also easily adapt it for Ethereum, DOGE, or even Telegram Token β just replace bitcoin with the desired coin in the URL.
πͺ @DataScience4