Files
OpenBB/bots/stocks/disc/ford.py
teh_coderer 07c053fcff Bots plots refactor.. 90% html size decrease! (#1686)
* 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>
2022-04-15 10:41:17 +01:00

115 lines
3.1 KiB
Python
Executable File

import logging
import disnake
from bots import imps
from openbb_terminal.decorators import log_start_end
from openbb_terminal.stocks.discovery import fidelity_model
logger = logging.getLogger(__name__)
@log_start_end(log=logger)
def ford_command():
"""Display Orders by Fidelity Customers. [Source: Fidelity]"""
# Debug
if imps.DEBUG:
logger.debug("disc ford")
order_header, df_orders = fidelity_model.get_orders() # pylint: disable=W0612
df_orders = df_orders.head(n=30).iloc[:, :-1]
df_orders = df_orders.applymap(str)
font_color = (
["white"] * 2
+ [imps.in_decreasing_color_list(df_orders["Price Change"])]
+ [["white"] * 3]
)
df_orders = df_orders.rename(
columns={"# Buy Orders": "# Buy's", "# Sell Orders": "# Sell's"}
)
df_orders.set_index("Symbol", inplace=True)
df_orders = df_orders.apply(lambda x: x.str.slice(0, 30))
title = "Fidelity Customer Orders"
dindex = len(df_orders.index)
embeds: list = []
# Output
i, i2, end = 0, 0, 15
df_pg, embeds_img, images_list = [], [], []
while i < dindex:
df_pg = df_orders.iloc[i:end]
df_pg.append(df_pg)
fig = imps.plot_df(
df_pg,
fig_size=(900, (40 + (40 * dindex))),
col_width=[1, 2.4, 2.35, 4, 1.5, 1.5],
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", "center", "center", "center", "right"],
font=dict(color=font_color),
)
)
)
imagefile = "disc-ford.png"
imagefile = imps.save_image(imagefile, fig)
if imps.IMAGES_URL or not imps.IMG_HOST_ACTIVE:
image_link = imps.multi_image(imagefile)
images_list.append(imagefile)
else:
image_link = imps.multi_image(imagefile)
embeds_img.append(
f"{image_link}",
)
embeds.append(
disnake.Embed(
title=title,
colour=imps.COLOR,
),
)
i2 += 1
i += 15
end += 15
# Author/Footer
for i in range(0, i2):
embeds[i].set_author(
name=imps.AUTHOR_NAME,
url=imps.AUTHOR_URL,
icon_url=imps.AUTHOR_ICON_URL,
)
embeds[i].set_footer(
text=imps.AUTHOR_NAME,
icon_url=imps.AUTHOR_ICON_URL,
)
i = 0
for i in range(0, i2):
embeds[i].set_image(url=embeds_img[i])
i += 1
embeds[0].set_footer(text=f"Page 1 of {len(embeds)}")
choices = [
disnake.SelectOption(label="Home", value="0", emoji="🟢"),
]
return {
"view": imps.Menu,
"title": title,
"embed": embeds,
"choices": choices,
"embeds_img": embeds_img,
"images_list": images_list,
}