mirror of
https://gitlab.com/simple-stock-bots/simple-telegram-stock-bot.git
synced 2025-06-16 15:06:53 +00:00
added /trending command
This commit is contained in:
parent
a4befde8ce
commit
f4adfb1915
@ -424,3 +424,18 @@ class IEX_Symbol:
|
||||
return m
|
||||
else:
|
||||
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]
|
||||
|
17
T_info.py
17
T_info.py
@ -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.
|
||||
|
||||
**Commands**
|
||||
- /donate [amount in USD] to donate. 🎗️
|
||||
- /dividend $[symbol] will return dividend information for the symbol. 📅
|
||||
- /intra $[symbol] Plot of the stocks movement since the last market open. 📈
|
||||
- /chart $[symbol] Plot of the stocks movement for the past 1 month. 📊
|
||||
- /news $[symbol] News about the symbol. 📰
|
||||
- /info $[symbol] General information about the symbol. ℹ️
|
||||
- /stat $[symbol] Key statistics about the symbol. 🔢
|
||||
- /help Get some help using the bot. 🆘
|
||||
- `/donate [amount in USD]` to donate. 🎗️
|
||||
- `/dividend $[symbol]` Dividend information for the symbol. 📅
|
||||
- `/intra $[symbol]` Plot of the stocks movement since the last market open. 📈
|
||||
- `/chart $[symbol]` Plot of the stocks movement for the past 1 month. 📊
|
||||
- `/news $[symbol]` News about the symbol. 📰
|
||||
- `/info $[symbol]` General information about the symbol. ℹ️
|
||||
- `/stat $[symbol]` Key statistics about the symbol. 🔢
|
||||
- `/trending` Trending Stocks and Cryptos.
|
||||
- `/help` Get some help using the bot. 🆘
|
||||
|
||||
**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.
|
||||
|
13
bot.py
13
bot.py
@ -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):
|
||||
"""
|
||||
Handles inline query.
|
||||
@ -448,6 +460,7 @@ def main():
|
||||
dp.add_handler(CommandHandler("info", info))
|
||||
dp.add_handler(CommandHandler("stat", stat))
|
||||
dp.add_handler(CommandHandler("stats", stat))
|
||||
dp.add_handler(CommandHandler("trending", trending))
|
||||
dp.add_handler(CommandHandler("search", search))
|
||||
dp.add_handler(CommandHandler("intraday", intra))
|
||||
dp.add_handler(CommandHandler("intra", intra, run_async=True))
|
||||
|
15
cg_Crypto.py
15
cg_Crypto.py
@ -263,3 +263,18 @@ class cg_Crypto:
|
||||
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."
|
||||
|
||||
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]
|
||||
|
@ -284,6 +284,30 @@ class Router:
|
||||
|
||||
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:
|
||||
|
||||
choice = random.choice(
|
||||
|
Loading…
x
Reference in New Issue
Block a user