1
0
mirror of https://gitlab.com/simple-stock-bots/simple-stock-bot.git synced 2025-06-16 15:17:28 +00:00
This commit is contained in:
MisterBiggs 2021-06-22 00:08:04 -07:00
parent 55bf78a57b
commit 6baf893823
3 changed files with 28 additions and 11 deletions

View File

@ -489,6 +489,9 @@ class IEX_Symbol:
timeout=5, timeout=5,
) )
if stocks.status_code == 200: if stocks.status_code == 200:
return [f"${s['symbol']}: {s['companyName']}" for s in stocks.json()] return [
f"`${s['symbol']}`: {s['companyName']}, {s['changePercent']:.2f}%"
for s in stocks.json()
]
else: else:
return ["Trending Stocks Currently Unavailable."] return ["Trending Stocks Currently Unavailable."]

View File

@ -292,13 +292,27 @@ class cg_Crypto:
"https://api.coingecko.com/api/v3/search/trending", "https://api.coingecko.com/api/v3/search/trending",
timeout=5, timeout=5,
) )
try:
trending = []
if coins.status_code == 200: if coins.status_code == 200:
return [ for coin in coins.json()["coins"]:
f"$${c['item']['symbol'].upper()}: {c['item']['name']}" c = coin["item"]
for c in coins.json()["coins"]
] sym = c["symbol"].upper()
else: name = c["name"]
return ["Trending Coins Currently Unavailable."] change = r.get(
f"https://api.coingecko.com/api/v3/simple/price?ids={c['id']}&vs_currencies={self.vs_currency}&include_24hr_change=true"
).json()[c["id"]]["usd_24h_change"]
msg = f"`$${sym}`: {name}, {change:.2f}%"
trending.append(msg)
except Exception as e:
print(e)
trending = ["Trending Coins Currently Unavailable."]
return trending
def batch_price(self, coins: list[Coin]) -> list[str]: def batch_price(self, coins: list[Coin]) -> list[str]:
query = ",".join([c.id for c in coins]) query = ",".join([c.id for c in coins])

View File

@ -326,7 +326,7 @@ class Router:
stocks = self.stock.trending() stocks = self.stock.trending()
coins = self.crypto.trending() coins = self.crypto.trending()
reply = "`Trending Stocks:\n" reply = "Trending Stocks:\n"
reply += "-" * len("Trending Stocks:") + "\n" reply += "-" * len("Trending Stocks:") + "\n"
for stock in stocks: for stock in stocks:
reply += stock + "\n" reply += stock + "\n"
@ -336,7 +336,7 @@ class Router:
for coin in coins: for coin in coins:
reply += coin + "\n" reply += coin + "\n"
return reply + "`" return reply
def random_pick(self) -> str: def random_pick(self) -> str: