def display_glbonds(export: str):
    """Global bonds. [Source: Wall St. Journal]

    Parameters
    ----------
    export : str
        Export dataframe data to csv,json,xlsx file
    """
    df_data = wsj_model.global_bonds()
    if df_data.empty:
        print("No global bonds data available\n")
        return

    if gtff.USE_TABULATE_DF:
        print(
            tabulate(
                df_data,
                showindex=False,
                headers=df_data.columns,
                floatfmt=".2f",
                tablefmt="fancy_grid",
            )
        )
    else:
        print(df_data.to_string(index=False))
    print("")

    export_data(
        export,
        os.path.dirname(os.path.abspath(__file__)),
        "glbonds",
        df_data,
    )
Exemple #2
0
def display_glbonds(export: str):
    """Global bonds. [Source: Wall St. Journal]

    Parameters
    ----------
    export : str
        Export dataframe data to csv,json,xlsx file
    """
    df_data = wsj_model.global_bonds()
    if df_data.empty:
        console.print("No global bonds data available\n")
        return

    print_rich_table(df_data,
                     show_index=False,
                     headers=list(df_data.columns),
                     title="Global Bonds")
    console.print("")

    export_data(
        export,
        os.path.dirname(os.path.abspath(__file__)),
        "glbonds",
        df_data,
    )
Exemple #3
0
async def glbonds_command(ctx):
    """Global bonds overview [Wall St. Journal]"""

    try:
        # Debug user input
        if cfg.DEBUG:
            print("\n!economy.glbonds")

        # Retrieve data
        df_data = wsj_model.global_bonds()

        # Debug user output
        if cfg.DEBUG:
            print(df_data.to_string())

        # Output data
        if df_data.empty:
            df_data_str = "No global bonds data available"
        else:
            df_data_str = "```" + df_data.to_string(index=False) + "```"

        embed = discord.Embed(
            title="Economy: [WSJ] Global Bonds",
            description=df_data_str,
            colour=cfg.COLOR,
        )
        embed.set_author(
            name=cfg.AUTHOR_NAME,
            icon_url=cfg.AUTHOR_ICON_URL,
        )

        await ctx.send(embed=embed)

    except Exception as e:
        embed = discord.Embed(
            title="ERROR Economy: [WSJ] Global Bonds",
            colour=cfg.COLOR,
            description=e,
        )
        embed.set_author(
            name=cfg.AUTHOR_NAME,
            icon_url=cfg.AUTHOR_ICON_URL,
        )

        await ctx.send(embed=embed)
Exemple #4
0
async def glbonds_command(ctx, arg=""):
    """Gets the global bonds data from GST and sends it

    Parameters
    -----------
    arg: str
        -h or help

    Returns
    -------
    discord message
        Sends a message containing an embed of global bonds data to the user
    """

    try:
        # Debug
        if cfg.DEBUG:
            print(f"!stocks.economy.glbonds {arg}")

        # Help
        if arg == "-h" or arg == "help":
            help_txt = "Global Bonds [Source: Wall St. Journal]\n"
            embed = discord.Embed(
                title="Economy: [WSJ] Global Bonds HELP",
                description=help_txt,
                colour=cfg.COLOR,
            )
            embed.set_author(
                name=cfg.AUTHOR_NAME,
                icon_url=cfg.AUTHOR_ICON_URL,
            )

        else:
            df_data = wsj_model.global_bonds()
            if df_data.empty:
                df_data_str = "No global bonds data available"
            else:
                df_data_str = "```" + df_data.to_string(index=False) + "```"

            embed = discord.Embed(
                title="Economy: [WSJ] Global Bonds",
                description=df_data_str,
                colour=cfg.COLOR,
            )
            embed.set_author(
                name=cfg.AUTHOR_NAME,
                icon_url=cfg.AUTHOR_ICON_URL,
            )

        await ctx.send(embed=embed)

    except Exception as e:
        title = "INTERNAL ERROR"
        embed = discord.Embed(title=title, colour=cfg.COLOR)
        embed.set_author(
            name=cfg.AUTHOR_NAME,
            icon_url=cfg.AUTHOR_ICON_URL,
        )
        embed.set_description(
            "Try updating the bot, make sure DEBUG is True in the config "
            "and restart it.\nIf the error still occurs open a issue at: "
            "https://github.com/GamestonkTerminal/GamestonkTerminal/issues"
            f"\n{e}"
        )
        if cfg.DEBUG:
            print(e)
Exemple #5
0
def glbonds_command():
    """Global bonds overview [Wall St. Journal]"""

    # Debug user input
    if imps.DEBUG:
        logger.debug("econ-glbonds")

    # Retrieve data
    df = wsj_model.global_bonds()

    # Check for argument
    if df.empty:
        raise Exception("No available data found")

    df["Rate (%)"] = pd.to_numeric(df["Rate (%)"].astype(float))
    df["Yld (%)"] = pd.to_numeric(df["Yld (%)"].astype(float))
    df["Yld Chg (%)"] = pd.to_numeric(df["Yld Chg (%)"].astype(float))

    formats = {
        "Rate (%)": "{:.2f}%",
        "Yld (%)": "{:.2f}%",
        "Yld Chg (%)": "<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.to_string())

    df = df.fillna("")
    df = df.replace(("Government Bond", "10 Year"), ("Gov .Bond", "10yr"),
                    regex=True)
    df.set_index(" ", inplace=True)
    df = df.set_axis(
        [
            "Rate",
            "Yld",
            "Yld Chg",
        ],
        axis="columns",
    )

    font_color = ["white"] * 3 + [[
        "#e4003a" if boolv else "#00ACFF"
        for boolv in df["Yld Chg"].str.contains("-")
    ]]

    fig = imps.plot_df(
        df,
        fig_size=(500, (40 + (40 * len(df.index)))),
        col_width=[8, 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-glbonds.png", fig)

    return {"title": "Economy: [WSJ] Global Bonds", "imagefile": imagefile}
Exemple #6
0
async def glbonds_command(ctx):
    """Global bonds overview [Wall St. Journal]"""

    try:
        # Debug user input
        if cfg.DEBUG:
            logger.debug("econ-glbonds")

        # Retrieve data
        df = wsj_model.global_bonds()

        # Check for argument
        if df.empty:
            raise Exception("No available data found")

        df["Rate (%)"] = pd.to_numeric(df["Rate (%)"].astype(float))
        df["Yld (%)"] = pd.to_numeric(df["Yld (%)"].astype(float))
        df["Yld Chg (%)"] = pd.to_numeric(df["Yld Chg (%)"].astype(float))

        formats = {
            "Rate (%)": "{:.2f}%",
            "Yld (%)": "{:.2f}%",
            "Yld Chg (%)": "{:.2f}%",
        }
        for col, value in formats.items():
            df[col] = df[col].map(lambda x: value.format(x))  # pylint: disable=W0640

        # Debug user output
        if cfg.DEBUG:
            logger.debug(df.to_string())

        df = df.fillna("")
        df = df.replace(("Government Bond", "10 Year"), ("Gov .Bond", "10yr"),
                        regex=True)
        df.set_index(" ", inplace=True)
        df = df.set_axis(
            [
                "Rate",
                "Yld",
                "Yld Chg",
            ],
            axis="columns",
        )
        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",
                height=35,
            ),
            template="plotly_dark",
            font=dict(
                family="Consolas",
                size=20,
            ),
            paper_bgcolor="rgba(0, 0, 0, 0)",
        )
        imagefile = "econ-glbonds.png"
        df2img.save_dataframe(fig=fig, filename=imagefile)
        image = Image.open(imagefile)
        image = autocrop_image(image, 0)
        image.save(imagefile, "PNG", quality=100)
        image = disnake.File(imagefile)
        title = "Economy: [WSJ] Global Bonds"
        embed = disnake.Embed(title=title, colour=cfg.COLOR)
        embed.set_image(url=f"attachment://{imagefile}")
        embed.set_author(
            name=cfg.AUTHOR_NAME,
            icon_url=cfg.AUTHOR_ICON_URL,
        )
        os.remove(imagefile)

        await ctx.send(embed=embed, file=image)

    except Exception as e:
        embed = disnake.Embed(
            title="ERROR Economy: [WSJ] Global Bonds",
            colour=cfg.COLOR,
            description=e,
        )
        embed.set_author(
            name=cfg.AUTHOR_NAME,
            icon_url=cfg.AUTHOR_ICON_URL,
        )

        await ctx.send(embed=embed, delete_after=30.0)
Exemple #7
0
def glbonds_command():
    """Global bonds overview [Wall St. Journal]"""

    # Debug user input
    if cfg.DEBUG:
        logger.debug("econ-glbonds")

    # Retrieve data
    df = wsj_model.global_bonds()

    # Check for argument
    if df.empty:
        raise Exception("No available data found")

    df["Rate (%)"] = pd.to_numeric(df["Rate (%)"].astype(float))
    df["Yld (%)"] = pd.to_numeric(df["Yld (%)"].astype(float))
    df["Yld Chg (%)"] = pd.to_numeric(df["Yld Chg (%)"].astype(float))

    formats = {
        "Rate (%)": "{:.2f}%",
        "Yld (%)": "{:.2f}%",
        "Yld Chg (%)": "{:.2f}%",
    }
    for col, value in formats.items():
        df[col] = df[col].map(lambda x: value.format(x))  # pylint: disable=W0640

    # Debug user output
    if cfg.DEBUG:
        logger.debug(df.to_string())

    df = df.fillna("")
    df = df.replace(("Government Bond", "10 Year"), ("Gov .Bond", "10yr"),
                    regex=True)
    df.set_index(" ", inplace=True)
    df = df.set_axis(
        [
            "Rate",
            "Yld",
            "Yld Chg",
        ],
        axis="columns",
    )
    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",
            height=35,
        ),
        template="plotly_dark",
        font=dict(
            family="Consolas",
            size=20,
        ),
        paper_bgcolor="rgba(0, 0, 0, 0)",
    )
    imagefile = save_image("econ-glbonds.png", fig)

    return {"title": "Economy: [WSJ] Global Bonds", "imagefile": imagefile}