-
Notifications
You must be signed in to change notification settings - Fork 0
/
cngko_tool.py
113 lines (80 loc) · 3.22 KB
/
cngko_tool.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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
import configs
from pycoingecko import CoinGeckoAPI
from requests.exceptions import ConnectionError
# connect to coin gecko api
coin_gecko = CoinGeckoAPI()
# validates the token's ticker input
def validate_coin(ticker):
try:
# empty ticker (coin gecko sets search to bitcoin for empty strings)
if ticker == "":
return False
coin_gecko.get_coin_by_id(id=ticker.lower())
return True
except ValueError:
return False
except ConnectionError:
return configs.CONNECTION_ERROR_TEXT
# returns the simplified name for the coin (i.e Bitcoin -> BTC)
def get_symbol(ticker):
try:
coin = coin_gecko.get_coin_by_id(id=ticker)
return coin[configs.COINGECKO_SYMBOL].upper()
except ConnectionError:
return configs.CONNECTION_ERROR_TEXT
# returns the full name of the coin (i.e. Bitcoin, Etherium)
def get_name(ticker):
try:
coin = coin_gecko.get_coin_by_id(id=ticker)
return coin[configs.COINGECKO_NAME].upper()
except ConnectionError:
return configs.CONNECTION_ERROR_TEXT
# returns the hashing algorithm the coin uses (i.e. Proof of Stake)
def get_hashing_algorithm(ticker):
try:
coin = coin_gecko.get_coin_by_id(id=ticker)
return coin[configs.COINGECKO_HASHINGALGO]
except ConnectionError:
return configs.CONNECTION_ERROR_TEXT
# returns the description of the token
def get_description(ticker):
try:
coin = coin_gecko.get_coin_by_id(id=ticker)
return coin[configs.COINGECKO_DESC][configs.COINGECKO_ENGLISH]
except ConnectionError:
return configs.CONNECTION_ERROR_TEXT
# returns the current market price the coin is going for
def get_current_price(ticker):
try:
coin = coin_gecko.get_coin_by_id(id=ticker.lower())
return coin[configs.COINGECKO_MARKETDATA][configs.COINGECKO_CURRENTPRICE][configs.COINGECKO_USD]
except ConnectionError:
return configs.CONNECTION_ERROR_TEXT
# returns the number of coins currently in the pool
def get_circulating_supply(ticker):
try:
coin = coin_gecko.get_coin_by_id(id=ticker)
return coin[configs.COINGECKO_MARKETDATA][configs.COINGECKO_CIRCULATINGSUPPLY]
except ConnectionError:
return configs.CONNECTION_ERROR_TEXT
# returns the number of possible coins that exist
def get_total_supply(ticker):
try:
coin = coin_gecko.get_coin_by_id(id=ticker)
return coin[configs.COINGECKO_MARKETDATA][configs.COINGECKO_TOTALSUPPLY]
except ConnectionError:
return configs.CONNECTION_ERROR_TEXT
# returns the market cap of the token (i.e. coin price * circ supply)
def get_market_cap(ticker):
try:
coin = coin_gecko.get_coin_by_id(id=ticker)
return coin[configs.COINGECKO_MARKETDATA][configs.COINGECKO_MARKETCAP][configs.COINGECKO_USD]
except ConnectionError:
return configs.CONNECTION_ERROR_TEXT
# returns the price change of the token within the 24 hour range
def get_price_change_percentage_24h(ticker):
try:
coin = coin_gecko.get_coin_by_id(id=ticker)
return coin[configs.COINGECKO_MARKETDATA][configs.COINGECKO_PRICECHANGEPERCENT24H]
except ConnectionError:
return configs.CONNECTION_ERROR_TEXT