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

added stat command

This commit is contained in:
Anson Biggs 2020-10-02 18:34:55 -07:00
parent e603c5345a
commit 6cfbbeb992
2 changed files with 66 additions and 13 deletions

23
bot.py
View File

@ -165,10 +165,29 @@ def intra(update, context):
buf.seek(0) buf.seek(0)
update.message.reply_photo( update.message.reply_photo(
photo=buf, caption=f"", parse_mode=telegram.ParseMode.MARKDOWN, photo=buf,
caption=f"",
parse_mode=telegram.ParseMode.MARKDOWN,
) )
def stat(update, context):
"""
https://iexcloud.io/docs/api/#key-stats
"""
message = update.message.text
chat_id = update.message.chat_id
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).items():
update.message.reply_text(
text=reply[1], parse_mode=telegram.ParseMode.MARKDOWN
)
def inline_query(update, context): def inline_query(update, context):
""" """
Handles inline query. Handles inline query.
@ -232,6 +251,8 @@ def main():
dp.add_handler(CommandHandler("div", dividend)) dp.add_handler(CommandHandler("div", dividend))
dp.add_handler(CommandHandler("news", news)) dp.add_handler(CommandHandler("news", news))
dp.add_handler(CommandHandler("info", info)) dp.add_handler(CommandHandler("info", info))
dp.add_handler(CommandHandler("stat", stat))
dp.add_handler(CommandHandler("stats", stat))
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)) dp.add_handler(CommandHandler("intra", intra))

View File

@ -78,13 +78,15 @@ Market data is provided by [IEX Cloud](https://iexcloud.io)
symbols = self.symbol_list symbols = self.symbol_list
symbols["Match"] = symbols.apply( symbols["Match"] = symbols.apply(
lambda x: fuzz.ratio(search, f"{x['symbol']}".lower()), axis=1, lambda x: fuzz.ratio(search, f"{x['symbol']}".lower()),
axis=1,
) )
symbols.sort_values(by="Match", ascending=False, inplace=True) symbols.sort_values(by="Match", ascending=False, inplace=True)
if symbols["Match"].head().sum() < 300: if symbols["Match"].head().sum() < 300:
symbols["Match"] = symbols.apply( symbols["Match"] = symbols.apply(
lambda x: fuzz.partial_ratio(search, x["name"].lower()), axis=1, lambda x: fuzz.partial_ratio(search, x["name"].lower()),
axis=1,
) )
symbols.sort_values(by="Match", ascending=False, inplace=True) symbols.sort_values(by="Match", ascending=False, inplace=True)
@ -224,3 +226,33 @@ Market data is provided by [IEX Cloud](https://iexcloud.io)
df["DT"] = pd.to_datetime(df["date"] + "T" + df["minute"]) df["DT"] = pd.to_datetime(df["date"] + "T" + df["minute"])
df = df.set_index("DT") df = df.set_index("DT")
return df return df
def stat_reply(self, symbols: list):
infoMessages = {}
for symbol in symbols:
IEXurl = f"https://cloud.iexapis.com/stable/stock/{symbol}/stats?token={self.IEX_TOKEN}"
response = r.get(IEXurl)
if response.status_code == 200:
data = response.json()
infoMessages[
symbol
] = f"""
Company Name: {data['companyName']}\n
Market Cap: {data['marketcap']}
52 Week (high-low):{data['week52high']}-{data['week52low']}
Number of Employees: {data['employees']}
Next Earnings Date: {data['nextEarningsDate']}
Dividend Info:
\tYield: {round(data['dividendYield'],4)*100}%
\tNext Date: {data['nextDividendDate']}
\tEx Date: {data['exDividendDate']}
"""
else:
infoMessages[
symbol
] = f"No information found for: {symbol}\nEither today is boring or the symbol does not exist."
return infoMessages