mirror of
https://github.com/OpenBB-finance/OpenBB.git
synced 2026-11-05 00:42:19 +00:00
* update * init * req * fix * req * meh * updates * syspath * update * local plotly, and scope logic * refactor * oops typo * plot dpi fixes * fix tests * fix * poetry update, reqs * some adjustments * added plot settings for scat/options Co-authored-by: Colin Delahunty <72827203+colin99d@users.noreply.github.com> Co-authored-by: didierlopes.eth <dro.lopes@campus.fct.unl.pt>
79 lines
1.9 KiB
Python
Executable File
79 lines
1.9 KiB
Python
Executable File
import logging
|
|
|
|
import pandas as pd
|
|
|
|
from bots import imps
|
|
from openbb_terminal.decorators import log_start_end
|
|
from openbb_terminal.economy import finviz_model
|
|
|
|
logger = logging.getLogger(__name__)
|
|
|
|
|
|
@log_start_end(log=logger)
|
|
def softs_command():
|
|
"""Displays softs futures data [Finviz]"""
|
|
|
|
# Debug user input
|
|
if imps.DEBUG:
|
|
logger.debug("econ-softs")
|
|
|
|
# Retrieve data
|
|
d_futures = finviz_model.get_futures()
|
|
df = pd.DataFrame(d_futures["Softs"])
|
|
|
|
# Check for argument
|
|
if df.empty:
|
|
raise Exception("No available data found")
|
|
|
|
formats = {"last": "${:.2f}", "prevClose": "${:.2f}", "change": "<b>{:.2f}%</b>"}
|
|
for col, value in formats.items():
|
|
df[col] = df[col].map(lambda x: value.format(x)) # pylint: disable=W0640
|
|
|
|
# Debug user output
|
|
if imps.DEBUG:
|
|
logger.debug(df)
|
|
|
|
df = df.sort_values(by="ticker", ascending=False)
|
|
df = df.fillna("")
|
|
df.set_index("label", inplace=True)
|
|
|
|
df = df[
|
|
[
|
|
"prevClose",
|
|
"last",
|
|
"change",
|
|
]
|
|
]
|
|
|
|
df.index.names = [""]
|
|
df = df.rename(
|
|
columns={"prevClose": "PrevClose", "last": "Last", "change": "Change"}
|
|
)
|
|
|
|
font_color = ["white"] * 3 + [imps.in_decreasing_color_list(df["Change"])]
|
|
|
|
fig = imps.plot_df(
|
|
df,
|
|
fig_size=(550, (40 + (40 * len(df.index)))),
|
|
col_width=[5, 3, 3],
|
|
tbl_header=imps.PLT_TBL_HEADER,
|
|
tbl_cells=imps.PLT_TBL_CELLS,
|
|
font=imps.PLT_TBL_FONT,
|
|
row_fill_color=imps.PLT_TBL_ROW_COLORS,
|
|
paper_bgcolor="rgba(0, 0, 0, 0)",
|
|
)
|
|
fig.update_traces(
|
|
cells=(
|
|
dict(
|
|
align=["center", "right"],
|
|
font=dict(color=font_color),
|
|
)
|
|
)
|
|
)
|
|
imagefile = imps.save_image("econ-softs.png", fig)
|
|
|
|
return {
|
|
"title": "Economy: [Finviz] Softs Futures",
|
|
"imagefile": imagefile,
|
|
}
|