Hey Im trying to make pretty simple app that check actual btc price and check if last_price is lower or higher then actual, but I cant figure out why is app stuck on this statement and keep spamming only this one:
elif price > last_price:
if last_price != price:
print(Fore.GREEN + "Bitcoin price has increased: $", functions.getbtcprice())
Here is code: main.py
from btcapi import *
from colorama import Fore
def main():
last_price = -1
while True:
price = functions.getbtcprice()
if last_price == -1:
print("Bitcoin price: $",price)
last_price = price
elif price > last_price:
if last_price != price:
print(Fore.GREEN + "Bitcoin price has increased: $", functions.getbtcprice())
elif price < last_price:
if last_price != price:
print(Fore.RED + "Bitcoin price has decreased: $", functions.getbtcprice())
if __name__ == "__main__":
main()
and btcapi.py
import requests
import json
class functions:
def getbtcprice():
response = requests.get("https://api.coinbase.com/v2/prices/spot?currency=USD").text
response_info = json.loads(response)
return float(response_info["data"]["amount"])
Thats the problem:
What Im trying to do is print first time actual btc price and the next one value different then the first one check if its lower or higher and print specififc values
price > last_price
thenlast_price != price
, so I don't se the point of explicitly checking that condition. – John Colemanif
statement:if last_price == price: continue
. – ddejohnlast_price
every time you hit the API. – ddejohn