1
0
mirror of https://gitlab.com/simple-stock-bots/simple-discord-stock-bot.git synced 2025-07-31 10:31:39 +00:00

added typing to commands that take longer

This commit is contained in:
2021-02-12 20:55:50 -07:00
parent fb13517a7d
commit f54f0cc04e

115
bot.py
View File

@@ -132,77 +132,78 @@ async def crypto(ctx, symbol: str):
@bot.command()
async def intra(ctx, sym: str):
"""Get a chart for the stocks movement since market open."""
with ctx.channel.typing():
symbol = s.find_symbols(sym)[0]
symbol = s.find_symbols(sym)[0]
df = s.intra_reply(symbol)
if df.empty:
await ctx.send("Invalid symbol please see `/help` for usage details.")
return
df = s.intra_reply(symbol)
if df.empty:
await ctx.send("Invalid symbol please see `/help` for usage details.")
return
buf = io.BytesIO()
mpf.plot(
df,
type="renko",
title=f"\n${symbol.upper()}",
volume=True,
style="yahoo",
mav=20,
savefig=dict(fname=buf, dpi=400, bbox_inches="tight"),
)
buf.seek(0)
buf = io.BytesIO()
mpf.plot(
df,
type="renko",
title=f"\n${symbol.upper()}",
volume=True,
style="yahoo",
mav=20,
savefig=dict(fname=buf, dpi=400, bbox_inches="tight"),
)
buf.seek(0)
caption = (
f"\nIntraday chart for ${symbol.upper()} from {df.first_valid_index().strftime('%I:%M')} to"
+ f" {df.last_valid_index().strftime('%I:%M')} ET on"
+ f" {datetime.date.today().strftime('%d, %b %Y')}"
)
caption = (
f"\nIntraday chart for ${symbol.upper()} from {df.first_valid_index().strftime('%I:%M')} to"
+ f" {df.last_valid_index().strftime('%I:%M')} ET on"
+ f" {datetime.date.today().strftime('%d, %b %Y')}"
)
await ctx.send(
content=caption,
file=discord.File(
buf,
filename=f"{symbol.upper()}:{datetime.date.today().strftime('%d%b%Y')}.png",
),
)
await ctx.send(f"{s.price_reply([symbol])[symbol]}")
await ctx.send(
content=caption,
file=discord.File(
buf,
filename=f"{symbol.upper()}:{datetime.date.today().strftime('%d%b%Y')}.png",
),
)
await ctx.send(f"{s.price_reply([symbol])[symbol]}")
@bot.command()
async def chart(ctx, sym: str):
"""Get a chart for the stocks movement for the past month."""
with ctx.channel.typing():
symbol = s.find_symbols(sym)[0]
symbol = s.find_symbols(sym)[0]
df = s.intra_reply(symbol)
if df.empty:
await ctx.send("Invalid symbol please see `/help` for usage details.")
return
df = s.intra_reply(symbol)
if df.empty:
await ctx.send("Invalid symbol please see `/help` for usage details.")
return
buf = io.BytesIO()
mpf.plot(
df,
type="candle",
title=f"\n${symbol.upper()}",
volume=True,
style="yahoo",
savefig=dict(fname=buf, dpi=400, bbox_inches="tight"),
)
buf.seek(0)
buf = io.BytesIO()
mpf.plot(
df,
type="candle",
title=f"\n${symbol.upper()}",
volume=True,
style="yahoo",
savefig=dict(fname=buf, dpi=400, bbox_inches="tight"),
)
buf.seek(0)
caption = (
f"\n1 Month chart for ${symbol.upper()} from {df.first_valid_index().strftime('%d, %b %Y')}"
+ f" to {df.last_valid_index().strftime('%d, %b %Y')}"
)
caption = (
f"\n1 Month chart for ${symbol.upper()} from {df.first_valid_index().strftime('%d, %b %Y')}"
+ f" to {df.last_valid_index().strftime('%d, %b %Y')}"
)
await ctx.send(
content=caption,
file=discord.File(
buf,
filename=f"{symbol.upper()}:{datetime.date.today().strftime('1M%d%b%Y')}.png",
),
)
await ctx.send(f"{s.price_reply([symbol])[symbol]}")
await ctx.send(
content=caption,
file=discord.File(
buf,
filename=f"{symbol.upper()}:{datetime.date.today().strftime('1M%d%b%Y')}.png",
),
)
await ctx.send(f"{s.price_reply([symbol])[symbol]}")
@bot.event