mirror of
https://github.com/OpenBB-finance/OpenBB.git
synced 2026-12-01 05:33:37 +00:00
* allow logs feature flag * Adding log collection md * upload last log at startup * additions/refractor * refactor * lint/black ++ * disc * TimeRotating Logger and upload to s3 * corrected regex error * makeup for config * logging/disc/sia/etf/++ * append .log before uploading * process to upload logs to s3 * candle ta/etfmcds * fix * ta candles * implement presignedURL * fixed regex * ma's in 1 cmd, delete older files * refactor ta candle * updates * black * moon? * Logger uploader * rotate every hour * only archive if successful * chavis suggestions * windows * ta * commands_dict update * discord tacmds * log_collection error fix * fix * fix * pylint * bb fix * only log filesize * fixes * discord logs * Delete log_collection.md * fixes for other bots on images * bots image upload fix * updated helpers/load candle * more ta cc/housekeeping/refactors/slashcmds * update bots cmds_dict * adjustments to font size/fixes * test fixs/disc earnings * missed a spot * fixes had > revesred * reversed the >< again oops * remove logger branch code blocking tests * black fix * fix missing sources in docstr/daily candle dt tz * load_candle refactor with docstring * moved insiders to disc * Lucas logging changes * Fixing log_collection.md * testing scenario * more ta converted * more ta * Update config_terminal : remove print of verbosity * table cfg/fix matplt/ screener + * fix * what's sleep? 1 more line.. or 2. scr df2img * juan more. fix news 1m chart issue * ticker.upper() fixes * Update log collection * Updating log collection - change tmp folder Co-authored-by: LBolte29 <lbolte@gmx.net> Co-authored-by: Chavithra PARANA <chavithra@gmail.com> Co-authored-by: LBolte29 <97528701+LBolte29@users.noreply.github.com> Co-authored-by: jose-donato <43375532+jose-donato@users.noreply.github.com> Co-authored-by: didierlopes.eth <dro.lopes@campus.fct.unl.pt>
155 lines
3.7 KiB
Python
155 lines
3.7 KiB
Python
import logging
|
|
|
|
import plotly.graph_objects as go
|
|
import yfinance as yf
|
|
from plotly.subplots import make_subplots
|
|
|
|
import bots.config_discordbot as cfg
|
|
from bots import helpers
|
|
from gamestonk_terminal.decorators import log_start_end
|
|
|
|
logger = logging.getLogger(__name__)
|
|
|
|
|
|
@log_start_end(log=logger)
|
|
def cc_hist_command(
|
|
ticker: str = None, expiry: str = "", strike: float = 10, opt_type: str = ""
|
|
):
|
|
"""Plot historical option prices
|
|
|
|
Parameters
|
|
----------
|
|
ticker: str
|
|
Stock ticker
|
|
expiry: str
|
|
expiration date
|
|
strike: float
|
|
Option strike price
|
|
put: bool
|
|
Calls for call
|
|
Puts for put
|
|
"""
|
|
|
|
# Debug
|
|
if cfg.DEBUG:
|
|
logger.info(f"opt hist {ticker} {strike} {opt_type} {expiry}")
|
|
|
|
# Check for argument
|
|
if ticker is None:
|
|
raise Exception("Stock ticker is required")
|
|
yf_ticker = yf.Ticker(ticker)
|
|
dates = list(yf_ticker.options)
|
|
|
|
if not dates:
|
|
raise Exception("Stock ticker is invalid")
|
|
|
|
options = yf.Ticker(ticker).option_chain(expiry)
|
|
|
|
if opt_type == "Calls":
|
|
options = options.calls
|
|
if opt_type == "Puts":
|
|
options = options.puts
|
|
|
|
chain_id = options.loc[options.strike == strike, "contractSymbol"].values[0]
|
|
df_hist = yf.download(chain_id)
|
|
df_hist.index.name = "date"
|
|
|
|
title = f"{ticker.upper()} {strike} {opt_type} expiring {expiry} Historical"
|
|
|
|
fig = make_subplots(
|
|
shared_xaxes=True,
|
|
specs=[[{"secondary_y": True}]],
|
|
)
|
|
fig.add_trace(
|
|
go.Candlestick(
|
|
x=df_hist.index,
|
|
open=df_hist.Open,
|
|
high=df_hist.High,
|
|
low=df_hist.Low,
|
|
close=df_hist.Close,
|
|
name="OHLC",
|
|
increasing_line_color="#00ACFF",
|
|
decreasing_line_color="#e4003a",
|
|
showlegend=False,
|
|
),
|
|
secondary_y=True,
|
|
)
|
|
fig.add_trace(
|
|
go.Bar(
|
|
x=df_hist.index,
|
|
y=df_hist.Volume,
|
|
name="Volume",
|
|
yaxis="y2",
|
|
marker_color="#fdc708",
|
|
opacity=0.3,
|
|
showlegend=False,
|
|
),
|
|
secondary_y=False,
|
|
)
|
|
if cfg.PLT_WATERMARK:
|
|
fig.add_layout_image(cfg.PLT_WATERMARK)
|
|
fig.update_layout(
|
|
margin=dict(l=0, r=0, t=25, b=5),
|
|
template=cfg.PLT_CANDLE_STYLE_TEMPLATE,
|
|
showlegend=False,
|
|
title=title,
|
|
title_x=0.1,
|
|
title_font_size=14,
|
|
yaxis2_title="Premium",
|
|
yaxis_title="Volume",
|
|
font=cfg.PLT_FONT,
|
|
yaxis=dict(
|
|
showgrid=False,
|
|
fixedrange=False,
|
|
side="left",
|
|
titlefont=dict(color="#fdc708", size=12),
|
|
tickfont=dict(
|
|
color="#fdc708",
|
|
size=14,
|
|
),
|
|
nticks=20,
|
|
),
|
|
yaxis2=dict(
|
|
side="right",
|
|
fixedrange=False,
|
|
anchor="x",
|
|
layer="above traces",
|
|
overlaying="y",
|
|
nticks=20,
|
|
tickfont=dict(
|
|
size=14,
|
|
),
|
|
showline=False,
|
|
),
|
|
xaxis=dict(
|
|
rangeslider=dict(visible=False),
|
|
type="date",
|
|
),
|
|
dragmode="pan",
|
|
)
|
|
fig.update_xaxes(
|
|
rangebreaks=[
|
|
dict(bounds=["sat", "mon"]),
|
|
],
|
|
)
|
|
|
|
imagefile = "opt_hist.png"
|
|
|
|
# Check if interactive settings are enabled
|
|
plt_link = ""
|
|
if cfg.INTERACTIVE:
|
|
plt_link = helpers.inter_chart(fig, imagefile, callback=False)
|
|
|
|
fig.update_layout(
|
|
width=800,
|
|
height=500,
|
|
)
|
|
|
|
imagefile = helpers.image_border(imagefile, fig=fig)
|
|
|
|
return {
|
|
"title": title,
|
|
"description": plt_link,
|
|
"imagefile": imagefile,
|
|
}
|