Update price.py
Top() gets "T", "B", or "M", with trillions rounding to 2 decimals, billions rounding to 1 decimal, and millions not rounding at all.
This commit is contained in:
parent
efa7c4a0fb
commit
b212831237
33
price.py
33
price.py
|
@ -421,8 +421,17 @@ def top(bot, trigger):
|
||||||
r = requests.get('https://api.coingecko.com/api/v3/global')
|
r = requests.get('https://api.coingecko.com/api/v3/global')
|
||||||
j = r.json()
|
j = r.json()
|
||||||
usd_total_mkt_cap = float(j['data']['total_market_cap']['usd'])
|
usd_total_mkt_cap = float(j['data']['total_market_cap']['usd'])
|
||||||
total_mcap_short = int(int(round(usd_total_mkt_cap,-9))/int(1e9))
|
total_mcap_short = 0
|
||||||
rounded_total_mcap = str(total_mcap_short)+"B"
|
magnitude_sym = "M"
|
||||||
|
if usd_total_mkt_cap >= 1e12:
|
||||||
|
total_mcap_short = round(usd_total_mkt_cap/float(1e12),2)
|
||||||
|
magnitude_sym = "T"
|
||||||
|
elif usd_total_mkt_cap >= 1e9:
|
||||||
|
total_mcap_short = round(usd_total_mkt_cap/float(1e9),1)
|
||||||
|
magnitude_sym = "B"
|
||||||
|
else:
|
||||||
|
total_mcap_short = round(usd_total_mkt_cap/float(1e6),0)
|
||||||
|
rounded_total_mcap = str(total_mcap_short)+magnitude_sym
|
||||||
topXstring += "Total market cap $" + rounded_total_mcap + " | "
|
topXstring += "Total market cap $" + rounded_total_mcap + " | "
|
||||||
except:
|
except:
|
||||||
bot.say("Can't connect to coinmarketcap API")
|
bot.say("Can't connect to coinmarketcap API")
|
||||||
|
@ -442,16 +451,18 @@ def top(bot, trigger):
|
||||||
rank = i['market_cap_rank']
|
rank = i['market_cap_rank']
|
||||||
price_usd = float(i['current_price'])
|
price_usd = float(i['current_price'])
|
||||||
market_cap_usd = float(i['market_cap'])
|
market_cap_usd = float(i['market_cap'])
|
||||||
if market_cap_usd >= 1e9:
|
mcap_short = 0
|
||||||
if market_cap_usd >= 1e10:
|
magnitude_sym = "M"
|
||||||
market_cap_short = int(int(round(market_cap_usd,-9))/int(1e9))
|
if market_cap_usd >= 1e12:
|
||||||
|
mcap_short = round(market_cap_usd/float(1e12),2)
|
||||||
|
magnitude_sym = "T"
|
||||||
|
elif market_cap_usd >= 1e9:
|
||||||
|
mcap_short = round(market_cap_usd/float(1e9),1)
|
||||||
|
magnitude_sym = "B"
|
||||||
else:
|
else:
|
||||||
market_cap_short = float(round(market_cap_usd,-8)/1e9)
|
#mcap_short = "tiny"
|
||||||
rounded_mcap = str(market_cap_short)+"B"
|
mcap_short = round(market_cap_usd/float(1e6),0)
|
||||||
else:
|
rounded_mcap = str(mcap_short)+magnitude_sym
|
||||||
#rounded_mcap = "tiny"
|
|
||||||
market_cap_short = float(round(market_cap_usd,-5)/1e6)
|
|
||||||
rounded_mcap = str(market_cap_short)+"M"
|
|
||||||
topXstring += "{0}. {1} ${2} | ".format(rank, symbol, rounded_mcap) #TODO: add price_usd, rounded
|
topXstring += "{0}. {1} ${2} | ".format(rank, symbol, rounded_mcap) #TODO: add price_usd, rounded
|
||||||
bot.say(topXstring[:-2])
|
bot.say(topXstring[:-2])
|
||||||
except:
|
except:
|
||||||
|
|
Loading…
Reference in New Issue