mirror of
https://github.com/OpenBB-finance/OpenBB.git
synced 2026-11-02 23:41:27 +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>
133 lines
3.9 KiB
Python
133 lines
3.9 KiB
Python
import logging
|
|
import os
|
|
|
|
import df2img
|
|
import disnake
|
|
|
|
import bots.config_discordbot as cfg
|
|
from bots import helpers
|
|
from bots.config_discordbot import gst_imgur
|
|
from bots.menus.menu import Menu
|
|
from gamestonk_terminal.decorators import log_start_end
|
|
from gamestonk_terminal.etf.discovery import wsj_model
|
|
|
|
logger = logging.getLogger(__name__)
|
|
|
|
|
|
@log_start_end(log=logger)
|
|
def etfs_disc_command(sort=""):
|
|
"""Displays ETF's Top Gainers/Decliners, Most Active [Wall Street Journal]"""
|
|
|
|
# Debug
|
|
if cfg.DEBUG:
|
|
logger.debug("etfs")
|
|
|
|
df_etfs = wsj_model.etf_movers(sort, export=True)
|
|
|
|
if df_etfs.empty:
|
|
raise Exception("No available data found")
|
|
|
|
df_etfs.set_index(" ", inplace=True)
|
|
prfx = "Top"
|
|
if sort == "active":
|
|
prfx = "Most"
|
|
title = f"ETF Movers ({prfx} {sort.capitalize()})"
|
|
|
|
dindex = len(df_etfs.index)
|
|
if dindex > 15:
|
|
embeds: list = []
|
|
# Output
|
|
i, i2, end = 0, 0, 15
|
|
df_pg, embeds_img, images_list = [], [], []
|
|
while i < dindex:
|
|
df_pg = df_etfs.iloc[i:end]
|
|
df_pg.append(df_pg)
|
|
fig = df2img.plot_dataframe(
|
|
df_pg,
|
|
fig_size=(1200, (40 + (40 * dindex))),
|
|
col_width=[1, 9, 1.5, 1.5, 1.5, 1.5],
|
|
tbl_header=cfg.PLT_TBL_HEADER,
|
|
tbl_cells=cfg.PLT_TBL_CELLS,
|
|
font=cfg.PLT_TBL_FONT,
|
|
row_fill_color=cfg.PLT_TBL_ROW_COLORS,
|
|
paper_bgcolor="rgba(0, 0, 0, 0)",
|
|
)
|
|
fig.update_traces(cells=(dict(align=["left"])))
|
|
imagefile = "disc-etfs.png"
|
|
imagefile = helpers.save_image(imagefile, fig)
|
|
|
|
if cfg.IMAGES_URL or cfg.IMGUR_CLIENT_ID != "REPLACE_ME":
|
|
image_link = cfg.IMAGES_URL + imagefile
|
|
images_list.append(imagefile)
|
|
else:
|
|
imagefile_save = cfg.IMG_DIR / imagefile
|
|
uploaded_image = gst_imgur.upload_image(
|
|
imagefile_save, title="something"
|
|
)
|
|
image_link = uploaded_image.link
|
|
os.remove(imagefile_save)
|
|
|
|
embeds_img.append(
|
|
f"{image_link}",
|
|
)
|
|
embeds.append(
|
|
disnake.Embed(
|
|
title=title,
|
|
colour=cfg.COLOR,
|
|
),
|
|
)
|
|
i2 += 1
|
|
i += 15
|
|
end += 15
|
|
|
|
# Author/Footer
|
|
for i in range(0, i2):
|
|
embeds[i].set_author(
|
|
name=cfg.AUTHOR_NAME,
|
|
url=cfg.AUTHOR_URL,
|
|
icon_url=cfg.AUTHOR_ICON_URL,
|
|
)
|
|
embeds[i].set_footer(
|
|
text=cfg.AUTHOR_NAME,
|
|
icon_url=cfg.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="🟢"),
|
|
]
|
|
|
|
output = {
|
|
"view": Menu,
|
|
"title": title,
|
|
"embed": embeds,
|
|
"choices": choices,
|
|
"embeds_img": embeds_img,
|
|
"images_list": images_list,
|
|
}
|
|
else:
|
|
fig = df2img.plot_dataframe(
|
|
df_etfs,
|
|
fig_size=(1200, (40 + (40 * dindex))),
|
|
col_width=[1, 9, 1.5, 1.5, 1.5, 1.5],
|
|
tbl_header=cfg.PLT_TBL_HEADER,
|
|
tbl_cells=cfg.PLT_TBL_CELLS,
|
|
font=cfg.PLT_TBL_FONT,
|
|
row_fill_color=cfg.PLT_TBL_ROW_COLORS,
|
|
paper_bgcolor="rgba(0, 0, 0, 0)",
|
|
)
|
|
fig.update_traces(cells=(dict(align=["left"])))
|
|
imagefile = helpers.save_image("disc-etfs.png", fig)
|
|
|
|
output = {
|
|
"title": title,
|
|
"imagefile": imagefile,
|
|
}
|
|
|
|
return output
|