· 4 years ago · Mar 09, 2021, 04:14 PM
1import requests
2from binance.client import Client
3
4def getBTC(client):
5 btc = client.get_ticker(symbol='BTCUSDT')
6 print(f"The percent for BTCUSDT is {btc.get('priceChangePercent')}")
7
8
9def getCrypto(client,cryptoName,price):
10 _symbol = cryptoName + 'USDT'
11 request = client.get_ticker(symbol=_symbol)
12 print(f"The percent for {_symbol} is {request.get('priceChangePercent')}")
13 if price != 0:
14 if request.get('lastPrice') >= price:
15 print(f"{request.get('lastPrice')} is greater than given value({price})")
16 return
17
18def showBTC(client):
19 while(True):
20 getBTC(client)
21
22
23def main():
24 api_key = "6Wj1MKgnwKjxI2OvtvTXXuxekm2h5A4mBVtMj9QkUSYOnmZOr1ecwivMEMbPNEet"
25 secret_key = "ZTYA1Cher0oBxcXrZEtWJ2fw9lyL8PhxMv1siCCOfgbQMSBwpyFHT8M4vQjw5WK5"
26 client = Client(api_key, secret_key)
27
28 choice = input("Press 1 for BTC percentage\nPress 2 to check other cryptos\n")
29 if int(choice) == 1:
30 showBTC(client)
31 elif int(choice) == 2:
32 cryptoName = input("Give crypto name to check percentage\n").upper()
33 if cryptoName == "BTC":
34 showBTC(client)
35
36 price = input("Give price to check(0 for empty)\n")
37 getCrypto(client,cryptoName,int(price))
38
39
40if __name__ == "__main__":
41 main()
42