Added chart to ticker command
This commit is contained in:
parent
67121365cb
commit
4e05e6f487
3 changed files with 27 additions and 1 deletions
7
main.py
7
main.py
|
@ -32,7 +32,7 @@ async def ticker(ctx, stock):
|
|||
stock = stock.upper()
|
||||
|
||||
data = yfi.stock_info(stock)
|
||||
return await ctx.send(
|
||||
await ctx.send(
|
||||
inspect.cleandoc(
|
||||
"""**{ticker}**
|
||||
|
||||
|
@ -44,6 +44,11 @@ async def ticker(ctx, stock):
|
|||
)
|
||||
)
|
||||
|
||||
image = t2.generate_chart(stock, yfi.stock_history(stock))
|
||||
|
||||
await ctx.send(file=discord.File(image, "chart.png"))
|
||||
image.close()
|
||||
|
||||
|
||||
@bot.command(aliases=["pft"])
|
||||
async def portfolio_text(ctx):
|
||||
|
|
14
table2.py
14
table2.py
|
@ -1,5 +1,6 @@
|
|||
import matplotlib.pyplot as plt
|
||||
import matplotlib, io
|
||||
import plotly.express as px
|
||||
from datetime import datetime
|
||||
|
||||
|
||||
|
@ -81,3 +82,16 @@ def generate_table(headers, data, title="", bg="skyblue", border="steelblue"):
|
|||
plt.savefig(image_buffer, format="png")
|
||||
image_buffer.seek(0)
|
||||
return image_buffer
|
||||
|
||||
|
||||
def generate_chart(ticker, data):
|
||||
fig = px.line(
|
||||
history,
|
||||
x=data.index,
|
||||
y="Open",
|
||||
title="{} Stock Prices".format(ticker),
|
||||
labels={"Open": "Price Per Share"},
|
||||
)
|
||||
|
||||
img_bytes = fig.to_image(format="png")
|
||||
return img_bytes
|
||||
|
|
7
yfi.py
7
yfi.py
|
@ -15,6 +15,13 @@ def stock_info(ticker):
|
|||
return stock
|
||||
|
||||
|
||||
def stock_history(ticker, timespan="6mo", interval="1d"):
|
||||
if not stock_exists(ticker):
|
||||
return False
|
||||
|
||||
return yf.Ticker(stock).history("6mo", interval="1d", prepost=True)
|
||||
|
||||
|
||||
def get_current_price(ticker):
|
||||
yf_obj = yf.Ticker(ticker)
|
||||
todays_data = yf_obj.history(period="1d")
|
||||
|
|
Loading…
Add table
Reference in a new issue