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:
parent
e603c5345a
commit
6cfbbeb992
23
bot.py
23
bot.py
@ -165,7 +165,26 @@ 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
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
@ -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))
|
||||||
|
36
functions.py
36
functions.py
@ -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
|
Loading…
x
Reference in New Issue
Block a user