mirror of
https://gitlab.com/simple-stock-bots/simple-telegram-stock-bot.git
synced 2025-08-03 03:51:26 +00:00
original progress from a few weekends ago
This commit is contained in:
163
bot.py
163
bot.py
@@ -198,110 +198,6 @@ def symbol_detect(update: Update, context: CallbackContext):
|
||||
)
|
||||
|
||||
|
||||
def dividend(update: Update, context: CallbackContext):
|
||||
"""/dividend or /div command and then finds dividend info on that symbol."""
|
||||
info(f"Dividend command ran by {update.message.chat.username}")
|
||||
message = update.message.text
|
||||
chat_id = update.message.chat_id
|
||||
|
||||
if message.strip().split("@")[0] == "/dividend":
|
||||
update.message.reply_text(
|
||||
"This command gives info on the next dividend date for a symbol.\nExample: /dividend $tsla"
|
||||
)
|
||||
return
|
||||
|
||||
symbols = s.find_symbols(message)
|
||||
|
||||
if symbols:
|
||||
context.bot.send_chat_action(chat_id=chat_id, action=telegram.ChatAction.TYPING)
|
||||
for reply in s.dividend_reply(symbols):
|
||||
update.message.reply_text(
|
||||
text=reply,
|
||||
parse_mode=telegram.ParseMode.MARKDOWN,
|
||||
disable_notification=True,
|
||||
)
|
||||
|
||||
|
||||
def news(update: Update, context: CallbackContext):
|
||||
"""/news command then finds news info on that symbol."""
|
||||
info(f"News command ran by {update.message.chat.username}")
|
||||
message = update.message.text
|
||||
chat_id = update.message.chat_id
|
||||
|
||||
if message.strip().split("@")[0] == "/news":
|
||||
update.message.reply_text(
|
||||
"This command gives the most recent english news for a symbol.\nExample: /news $tsla"
|
||||
)
|
||||
return
|
||||
|
||||
symbols = s.find_symbols(message, trending_weight=10)
|
||||
|
||||
if symbols:
|
||||
context.bot.send_chat_action(chat_id=chat_id, action=telegram.ChatAction.TYPING)
|
||||
|
||||
for reply in s.news_reply(symbols):
|
||||
update.message.reply_text(
|
||||
text=reply,
|
||||
parse_mode=telegram.ParseMode.MARKDOWN,
|
||||
disable_notification=True,
|
||||
)
|
||||
|
||||
|
||||
def information(update: Update, context: CallbackContext):
|
||||
"""/info command then finds info on that symbol."""
|
||||
info(f"Information command ran by {update.message.chat.username}")
|
||||
message = update.message.text
|
||||
chat_id = update.message.chat_id
|
||||
|
||||
if message.strip().split("@")[0] == "/info":
|
||||
update.message.reply_text(
|
||||
"This command gives information on a symbol.\nExample: /info $tsla"
|
||||
)
|
||||
return
|
||||
|
||||
symbols = s.find_symbols(message)
|
||||
|
||||
if symbols:
|
||||
context.bot.send_chat_action(chat_id=chat_id, action=telegram.ChatAction.TYPING)
|
||||
|
||||
for reply in s.info_reply(symbols):
|
||||
update.message.reply_text(
|
||||
text=reply,
|
||||
parse_mode=telegram.ParseMode.MARKDOWN,
|
||||
disable_notification=True,
|
||||
)
|
||||
|
||||
|
||||
def search(update: Update, context: CallbackContext):
|
||||
"""
|
||||
Searches on full list of stocks and crypto descriptions
|
||||
then returns the top matches in order of smallest symbol name length.
|
||||
"""
|
||||
info(f"Search command ran by {update.message.chat.username}")
|
||||
message = update.message.text.replace("/search ", "")
|
||||
chat_id = update.message.chat_id
|
||||
|
||||
if message.strip().split("@")[0] == "/search":
|
||||
update.message.reply_text(
|
||||
"This command searches for symbols supported by the bot.\nExample: /search Tesla Motors or /search $tsla"
|
||||
)
|
||||
return
|
||||
|
||||
context.bot.send_chat_action(chat_id=chat_id, action=telegram.ChatAction.TYPING)
|
||||
queries = s.inline_search(message, matches=10)
|
||||
if not queries.empty:
|
||||
reply = "*Search Results:*\n`$ticker` : Company Name\n`" + ("-" * 21) + "`\n"
|
||||
for _, query in queries.iterrows():
|
||||
desc = query["description"]
|
||||
reply += "`" + desc.replace(": ", "` : ") + "\n"
|
||||
|
||||
update.message.reply_text(
|
||||
text=reply,
|
||||
parse_mode=telegram.ParseMode.MARKDOWN,
|
||||
disable_notification=True,
|
||||
)
|
||||
|
||||
|
||||
def intra(update: Update, context: CallbackContext):
|
||||
"""returns a chart of intraday data for a symbol"""
|
||||
info(f"Intra command ran by {update.message.chat.username}")
|
||||
@@ -411,56 +307,6 @@ def chart(update: Update, context: CallbackContext):
|
||||
)
|
||||
|
||||
|
||||
def stat(update: Update, context: CallbackContext):
|
||||
"""returns key statistics on symbol"""
|
||||
info(f"Stat command ran by {update.message.chat.username}")
|
||||
message = update.message.text
|
||||
chat_id = update.message.chat_id
|
||||
|
||||
if message.strip().split("@")[0] == "/stat":
|
||||
update.message.reply_text(
|
||||
"This command returns key statistics for a symbol.\nExample: /stat $tsla"
|
||||
)
|
||||
return
|
||||
|
||||
symbols = s.find_symbols(message)
|
||||
|
||||
if symbols:
|
||||
context.bot.send_chat_action(chat_id=chat_id, action=telegram.ChatAction.TYPING)
|
||||
|
||||
for reply in s.stat_reply(symbols):
|
||||
update.message.reply_text(
|
||||
text=reply,
|
||||
parse_mode=telegram.ParseMode.MARKDOWN,
|
||||
disable_notification=True,
|
||||
)
|
||||
|
||||
|
||||
def cap(update: Update, context: CallbackContext):
|
||||
"""returns market cap for symbol"""
|
||||
info(f"Cap command ran by {update.message.chat.username}")
|
||||
message = update.message.text
|
||||
chat_id = update.message.chat_id
|
||||
|
||||
if message.strip().split("@")[0] == "/cap":
|
||||
update.message.reply_text(
|
||||
"This command returns the market cap for a symbol.\nExample: /cap $tsla"
|
||||
)
|
||||
return
|
||||
|
||||
symbols = s.find_symbols(message)
|
||||
|
||||
if symbols:
|
||||
context.bot.send_chat_action(chat_id=chat_id, action=telegram.ChatAction.TYPING)
|
||||
|
||||
for reply in s.cap_reply(symbols):
|
||||
update.message.reply_text(
|
||||
text=reply,
|
||||
parse_mode=telegram.ParseMode.MARKDOWN,
|
||||
disable_notification=True,
|
||||
)
|
||||
|
||||
|
||||
def trending(update: Update, context: CallbackContext):
|
||||
"""returns currently trending symbols and how much they've moved in the past trading day."""
|
||||
info(f"Trending command ran by {update.message.chat.username}")
|
||||
@@ -510,7 +356,6 @@ def inline_query(update: Update, context: CallbackContext):
|
||||
|
||||
results = []
|
||||
for _, row in matches.iterrows():
|
||||
|
||||
results.append(
|
||||
InlineQueryResultArticle(
|
||||
str(uuid4()),
|
||||
@@ -588,15 +433,7 @@ def main():
|
||||
dp.add_handler(CommandHandler("start", start))
|
||||
dp.add_handler(CommandHandler("help", help))
|
||||
dp.add_handler(CommandHandler("license", license))
|
||||
dp.add_handler(CommandHandler("dividend", dividend))
|
||||
dp.add_handler(CommandHandler("div", dividend))
|
||||
dp.add_handler(CommandHandler("news", news))
|
||||
dp.add_handler(CommandHandler("info", information))
|
||||
dp.add_handler(CommandHandler("stat", stat))
|
||||
dp.add_handler(CommandHandler("stats", stat))
|
||||
dp.add_handler(CommandHandler("cap", cap))
|
||||
dp.add_handler(CommandHandler("trending", trending))
|
||||
dp.add_handler(CommandHandler("search", search))
|
||||
dp.add_handler(CommandHandler("random", rand_pick))
|
||||
dp.add_handler(CommandHandler("donate", donate))
|
||||
dp.add_handler(CommandHandler("status", status))
|
||||
|
Reference in New Issue
Block a user