From ad0abb07bedda7c6877fbab8c39e0dbda0af00f3 Mon Sep 17 00:00:00 2001 From: Anson Biggs Date: Thu, 11 Feb 2021 19:32:58 -0700 Subject: [PATCH] Close #9 --- bot.py | 43 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) diff --git a/bot.py b/bot.py index 7417ab8..c1b016c 100644 --- a/bot.py +++ b/bot.py @@ -127,6 +127,49 @@ async def crypto(ctx, symbol: str): await ctx.send(reply) +import pandas as pd +import io + +import mplfinance as mpf + + +@bot.command() +async def intra(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="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')}" + ) + + await ctx.send( + content=caption, + file=discord.File( + buf, + filename=f"{symbol.upper()}:{datetime.date.today().strftime('%d%b%Y')}.png", + ), + ) + + @bot.event async def on_message(message):