1
0
mirror of https://gitlab.com/simple-stock-bots/simple-telegram-stock-bot.git synced 2025-07-25 07:31:48 +00:00

Fixed Inline #55

This commit is contained in:
2021-03-30 11:36:52 -07:00
parent 8dd3ef772f
commit 144dd1d218
4 changed files with 75 additions and 8 deletions

View File

@@ -278,3 +278,28 @@ class cg_Crypto:
]
return [f"$${c['item']['symbol'].upper()}: {c['item']['name']}" for c in coins]
def batch_price(self, coins: list[Coin]) -> list[str]:
query = ",".join([c.id for c in coins])
prices = r.get(
f"https://api.coingecko.com/api/v3/simple/price?ids={query}&vs_currencies=usd&include_24hr_change=true"
).json()
replies = []
for name, val in prices.items():
if price := val.get("usd"):
price = val.get("usd")
else:
replies.append(f"{name} price data unavailable.")
break
change = 0
if val.get("usd_24h_change") is not None:
change = val.get("usd_24h_change")
replies.append(
f"{name}: ${price:,} and has moved {change:.2f}% in the past 24 hours."
)
return replies