1
0
mirror of https://gitlab.com/simple-stock-bots/simple-telegram-stock-bot.git synced 2025-07-25 07:31:48 +00:00
This commit is contained in:
2021-06-23 14:17:50 -07:00
parent ae0075b986
commit baf45e09c8
4 changed files with 111 additions and 0 deletions

View File

@@ -252,6 +252,43 @@ class cg_Crypto:
else:
return f"{symbol.symbol} returned an error."
def cap_reply(self, coin: Coin) -> str:
"""Gets market Cap for each symbol in the list
Parameters
----------
symbols : List[str]
List of coin symbols
Returns
-------
Dict[str, str]
Each symbol passed in is a key with its value being a human readable formatted string of the symbols markey cap.
"""
response = r.get(
f"https://api.coingecko.com/api/v3/simple/price?ids={coin.id}&vs_currencies={self.vs_currency}&include_market_cap=true",
timeout=5,
)
if response.status_code == 200:
try:
data = response.json()[coin.id]
price = data[self.vs_currency]
cap = data[self.vs_currency + "_market_cap"]
except KeyError:
return f"{coin.id} returned an error."
if cap == 0:
return f"The market cap for {coin.name} is not available for unknown reasons."
message = f"The current price of {coin.name} is $**{price:,}** and its market cap is $**{cap:,.2f}** {self.vs_currency.upper()}"
else:
message = f"The Coin: {coin.name} was not found or returned and error."
return message
def info_reply(self, symbol: Coin) -> str:
"""Gets information on stock symbols.