1
0
mirror of https://gitlab.com/simple-stock-bots/simple-stock-bot.git synced 2025-06-16 07:16:40 +00:00

added /trending command

This commit is contained in:
Anson Biggs 2021-03-28 23:31:21 -07:00
parent a4befde8ce
commit f4adfb1915
5 changed files with 76 additions and 8 deletions

View File

@ -424,3 +424,18 @@ class IEX_Symbol:
return m return m
else: else:
return f"No information found for: {symbol}\nEither today is boring or the symbol does not exist." return f"No information found for: {symbol}\nEither today is boring or the symbol does not exist."
def trending(self) -> list[str]:
"""Gets current coins trending on coingecko
Returns
-------
list[str]
list of $$ID: NAME
"""
stocks = r.get(
f"https://cloud.iexapis.com/stable/stock/market/list/mostactive?token={self.IEX_TOKEN}"
).json()
return [f"${s['symbol']}: {s['companyName']}" for s in stocks]

View File

@ -26,14 +26,15 @@ The bot detects _"Symbols"_ using either one or two dollar signs before the symb
Simply calling a symbol in any message that the bot can see will also return the price. So a message like: `I wonder if $$btc will go to the Moon now that $tsla accepts it as payment` would return the current price for both Bitcoin and Tesla. Simply calling a symbol in any message that the bot can see will also return the price. So a message like: `I wonder if $$btc will go to the Moon now that $tsla accepts it as payment` would return the current price for both Bitcoin and Tesla.
**Commands** **Commands**
- /donate [amount in USD] to donate. 🎗 - `/donate [amount in USD]` to donate. 🎗
- /dividend $[symbol] will return dividend information for the symbol. 📅 - `/dividend $[symbol]` Dividend information for the symbol. 📅
- /intra $[symbol] Plot of the stocks movement since the last market open. 📈 - `/intra $[symbol]` Plot of the stocks movement since the last market open. 📈
- /chart $[symbol] Plot of the stocks movement for the past 1 month. 📊 - `/chart $[symbol]` Plot of the stocks movement for the past 1 month. 📊
- /news $[symbol] News about the symbol. 📰 - `/news $[symbol]` News about the symbol. 📰
- /info $[symbol] General information about the symbol. - `/info $[symbol]` General information about the symbol.
- /stat $[symbol] Key statistics about the symbol. 🔢 - `/stat $[symbol]` Key statistics about the symbol. 🔢
- /help Get some help using the bot. 🆘 - `/trending` Trending Stocks and Cryptos.
- `/help` Get some help using the bot. 🆘
**Inline Features** **Inline Features**
You can type @SimpleStockBot `[search]` in any chat or direct message to search for the stock bots full list of stock symbols and return the price of the ticker. Then once you select the ticker want the bot will send a message as you in that chat with the latest stock price. You can type @SimpleStockBot `[search]` in any chat or direct message to search for the stock bots full list of stock symbols and return the price of the ticker. Then once you select the ticker want the bot will send a message as you in that chat with the latest stock price.

13
bot.py
View File

@ -365,6 +365,18 @@ def stat(update: Update, context: CallbackContext):
) )
def trending(update: Update, context: CallbackContext):
"""
Trending Symbols
"""
chat_id = update.message.chat_id
context.bot.send_chat_action(chat_id=chat_id, action=telegram.ChatAction.TYPING)
update.message.reply_text(text=s.trending(), parse_mode=telegram.ParseMode.MARKDOWN)
def inline_query(update: Update, context: CallbackContext): def inline_query(update: Update, context: CallbackContext):
""" """
Handles inline query. Handles inline query.
@ -448,6 +460,7 @@ def main():
dp.add_handler(CommandHandler("info", info)) dp.add_handler(CommandHandler("info", info))
dp.add_handler(CommandHandler("stat", stat)) dp.add_handler(CommandHandler("stat", stat))
dp.add_handler(CommandHandler("stats", stat)) dp.add_handler(CommandHandler("stats", stat))
dp.add_handler(CommandHandler("trending", trending))
dp.add_handler(CommandHandler("search", search)) dp.add_handler(CommandHandler("search", search))
dp.add_handler(CommandHandler("intraday", intra)) dp.add_handler(CommandHandler("intraday", intra))
dp.add_handler(CommandHandler("intra", intra, run_async=True)) dp.add_handler(CommandHandler("intra", intra, run_async=True))

View File

@ -263,3 +263,18 @@ class cg_Crypto:
return f"{symbol} does not have a description available." return f"{symbol} does not have a description available."
return f"No information found for: {symbol}\nEither today is boring or the symbol does not exist." return f"No information found for: {symbol}\nEither today is boring or the symbol does not exist."
def trending(self) -> list[str]:
"""Gets current coins trending on coingecko
Returns
-------
list[str]
list of $$ID: NAME
"""
coins = r.get("https://api.coingecko.com/api/v3/search/trending").json()[
"coins"
]
return [f"$${c['item']['id'].upper()}: {c['item']['name']}" for c in coins]

View File

@ -284,6 +284,30 @@ class Router:
return replies return replies
def trending(self) -> str:
"""Checks APIs for trending symbols.
Returns
-------
list[str]
List of preformatted strings to be sent to user.
"""
stocks = self.stock.trending()
coins = self.crypto.trending()
reply = "`Trending Stocks:\n"
reply += "-" * len("Trending Stocks:") + "\n"
for stock in stocks:
reply += stock + "\n"
reply += "\n\nTrending Crypto:\n"
reply += "-" * len("Trending Crypto:") + "\n"
for coin in coins:
reply += coin + "\n"
return reply + "`"
def random_pick(self) -> str: def random_pick(self) -> str:
choice = random.choice( choice = random.choice(