1
0
mirror of https://gitlab.com/simple-stock-bots/simple-discord-stock-bot.git synced 2025-08-01 19:11:34 +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() @bot.command()
async def intra(ctx, sym: str): async def intra(ctx, sym: str):
"""Get a chart for the stocks movement since market open.""" """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) df = s.intra_reply(symbol)
if df.empty: if df.empty:
await ctx.send("Invalid symbol please see `/help` for usage details.") await ctx.send("Invalid symbol please see `/help` for usage details.")
return return
buf = io.BytesIO() buf = io.BytesIO()
mpf.plot( mpf.plot(
df, df,
type="renko", type="renko",
title=f"\n${symbol.upper()}", title=f"\n${symbol.upper()}",
volume=True, volume=True,
style="yahoo", style="yahoo",
mav=20, mav=20,
savefig=dict(fname=buf, dpi=400, bbox_inches="tight"), savefig=dict(fname=buf, dpi=400, bbox_inches="tight"),
) )
buf.seek(0) buf.seek(0)
caption = ( caption = (
f"\nIntraday chart for ${symbol.upper()} from {df.first_valid_index().strftime('%I:%M')} to" 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" {df.last_valid_index().strftime('%I:%M')} ET on"
+ f" {datetime.date.today().strftime('%d, %b %Y')}" + f" {datetime.date.today().strftime('%d, %b %Y')}"
) )
await ctx.send( await ctx.send(
content=caption, content=caption,
file=discord.File( file=discord.File(
buf, buf,
filename=f"{symbol.upper()}:{datetime.date.today().strftime('%d%b%Y')}.png", filename=f"{symbol.upper()}:{datetime.date.today().strftime('%d%b%Y')}.png",
), ),
) )
await ctx.send(f"{s.price_reply([symbol])[symbol]}") await ctx.send(f"{s.price_reply([symbol])[symbol]}")
@bot.command() @bot.command()
async def chart(ctx, sym: str): async def chart(ctx, sym: str):
"""Get a chart for the stocks movement for the past month.""" """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) df = s.intra_reply(symbol)
if df.empty: if df.empty:
await ctx.send("Invalid symbol please see `/help` for usage details.") await ctx.send("Invalid symbol please see `/help` for usage details.")
return 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() caption = (
mpf.plot( f"\n1 Month chart for ${symbol.upper()} from {df.first_valid_index().strftime('%d, %b %Y')}"
df, + f" to {df.last_valid_index().strftime('%d, %b %Y')}"
type="candle", )
title=f"\n${symbol.upper()}",
volume=True,
style="yahoo",
savefig=dict(fname=buf, dpi=400, bbox_inches="tight"),
)
buf.seek(0)
caption = ( await ctx.send(
f"\n1 Month chart for ${symbol.upper()} from {df.first_valid_index().strftime('%d, %b %Y')}" content=caption,
+ f" to {df.last_valid_index().strftime('%d, %b %Y')}" file=discord.File(
) buf,
filename=f"{symbol.upper()}:{datetime.date.today().strftime('1M%d%b%Y')}.png",
await ctx.send( ),
content=caption, )
file=discord.File( await ctx.send(f"{s.price_reply([symbol])[symbol]}")
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 @bot.event