mirror of
https://github.com/OpenBB-finance/OpenBB.git
synced 2026-10-28 21:12:16 +00:00
* First commit * Renamed to bot * change from discordbot to bots imports * refractor cmds + autocomplete helpers + updated dps plots/candle + quote cmd * isort fix * Update helpers.py * Added first refactor * Added commands and refactor * Added description handler * Through grains * ta + image border helper * Added indices * merged * Finished econ * options refactor * dark_pool_shorts, candle, quote done * pagination/dropdown logic to helpers + fixes * dd/disc/insider done + add image logic to helpers * linting * removed plt style * Almost done with Gov * fixing conflicts * Finished gov (excpect ones mentioned) * screener done * Test bug refactor * Store changes to switch * Finished refactor * Fixed error * Delete ::40 * Fixed issue * Fixed black * finished * fixes Co-authored-by: teh_coderer <me@tehcoderer.com> Co-authored-by: didierlopes.eth <dro.lopes@campus.fct.unl.pt>
68 lines
1.6 KiB
Python
68 lines
1.6 KiB
Python
import df2img
|
|
import pandas as pd
|
|
|
|
import bots.config_discordbot as cfg
|
|
from bots.config_discordbot import logger
|
|
from bots.helpers import save_image
|
|
from gamestonk_terminal.economy import wsj_model
|
|
|
|
|
|
def indices_command():
|
|
"""US indices overview [Wall St. Journal]"""
|
|
# Debug user input
|
|
if cfg.DEBUG:
|
|
logger.debug("econ-indices")
|
|
|
|
# Retrieve data
|
|
df = wsj_model.us_indices()
|
|
|
|
# Check for argument
|
|
if df.empty:
|
|
raise Exception("No available data found")
|
|
|
|
df["Price"] = pd.to_numeric(df["Price"].astype(float))
|
|
df["Chg"] = pd.to_numeric(df["Chg"].astype(float))
|
|
df["%Chg"] = pd.to_numeric(df["%Chg"].astype(float))
|
|
|
|
formats = {"Price": "${:.2f}", "Chg": "${:.2f}", "%Chg": "{:.2f}%"}
|
|
for col, value in formats.items():
|
|
# pylint: disable=W0640
|
|
df[col] = df[col].map(lambda x: value.format(x))
|
|
|
|
# Debug user output
|
|
if cfg.DEBUG:
|
|
logger.debug(df)
|
|
|
|
df = df[
|
|
[
|
|
"Price",
|
|
"Chg",
|
|
"%Chg",
|
|
]
|
|
]
|
|
|
|
df = df.fillna("")
|
|
df.set_index(" ", inplace=True)
|
|
|
|
dindex = len(df.index)
|
|
fig = df2img.plot_dataframe(
|
|
df,
|
|
fig_size=(800, (40 + (40 * dindex))),
|
|
col_width=[8, 3, 3],
|
|
tbl_cells=dict(
|
|
align=["left", "center"],
|
|
height=35,
|
|
),
|
|
template="plotly_dark",
|
|
font=dict(
|
|
family="Consolas",
|
|
size=20,
|
|
),
|
|
paper_bgcolor="rgba(0, 0, 0, 0)",
|
|
)
|
|
imagefile = save_image("econ-indices.png", fig)
|
|
return {
|
|
"title": "Economy: [WSJ] US Indices",
|
|
"imagefile": imagefile,
|
|
}
|