-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
75 lines (68 loc) · 2.5 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
#Developed and generated By @Momalekiii
# Import library's We need
import requests
import time
# Define the API URL and headers
api_url = "https://pro-api.coinmarketcap.com/v1/cryptocurrency/listings/latest"
headers = {
"X-CMC_PRO_API_KEY": "YOUR_API_KEY_HERE",
"Accept": "application/json"
}
# Define the percentage threshold
percentage_threshold = 70
# Define a function to get the coin data from the API
def get_coin_data(coin_symbol):
# Make a GET request to the API
response = requests.get(api_url, headers=headers)
# Check if the response is successful
if response.status_code == 200:
# Parse the JSON data
data = response.json()
# Loop through the data to find the coin
for coin in data["data"]:
if coin["symbol"] == coin_symbol:
# Return the coin data as a dictionary
return {
"name": coin["name"],
"symbol": coin["symbol"],
"price": coin["quote"]["USD"]["price"],
"volume_24h": coin["quote"]["USD"]["volume_24h"],
"percent_change_24h": coin["quote"]["USD"]["percent_change_24h"]
}
# If the response is not successful, return None
else:
return None
# Define a function to check if the coin meets the criteria
def check_coin_criteria(coin_symbol):
# Get the coin data
coin_data = get_coin_data(coin_symbol)
# Check if the coin data is valid
if coin_data:
# Print the coin data
print(f"{coin_data['name']} ({coin_data['symbol']})")
print(f"Price: ${coin_data['price']:.2f}")
print(f"Volume 24h: ${coin_data['volume_24h']:.2f}")
print(f"Percent Change 24h: {coin_data['percent_change_24h']:.2f}%")
# Check if the percent change is higher than the threshold
if coin_data["percent_change_24h"] > percentage_threshold:
# Print a message
print(f"Alert! {coin_data['name']} has increased by more than {percentage_threshold}% in the last 24 hours!")
else:
# Print a message
print(f"No alert. {coin_data['name']} has not increased by more than {percentage_threshold}% in the last 24 hours.")
else:
# Print an error message
print("Error: Could not get the coin data.")
# Define the main function
def main():
# Ask the user for the coin symbol or name
coin_input = input("Enter the coin symbol or name: ")
# Convert the input to uppercase
coin_input = coin_input.upper()
# Run the check coin criteria function every 10 seconds
while True:
check_coin_criteria(coin_input)
time.sleep(10)
# Call the main function
if __name__ == "__main__":
main()