From e2b2a61bb2ecf488576e47320f8dd5dcee9b98e9 Mon Sep 17 00:00:00 2001 From: Anson Biggs Date: Thu, 11 Feb 2021 19:38:19 -0700 Subject: [PATCH] Close #8 --- bot.py | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/bot.py b/bot.py index c1b016c..d2854fd 100644 --- a/bot.py +++ b/bot.py @@ -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 async def on_message(message):