1
0
mirror of https://gitlab.com/simple-stock-bots/simple-discord-stock-bot.git synced 2025-06-16 15:17:29 +00:00
This commit is contained in:
Anson Biggs 2021-02-11 19:38:19 -07:00
parent ad0abb07be
commit e2b2a61bb2

35
bot.py
View File

@ -170,6 +170,41 @@ async def intra(ctx, sym: str):
) )
@bot.command()
async def chart(ctx, sym: str):
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
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')}"
)
await ctx.send(
content=caption,
file=discord.File(
buf,
filename=f"{symbol.upper()}:{datetime.date.today().strftime('1M%d%b%Y')}.png",
),
)
@bot.event @bot.event
async def on_message(message): async def on_message(message):