def high_short_interest(num: int, export: str):
    """Prints top N high shorted interest stocks from https://www.highshortinterest.com

    Parameters
    ----------
    num: int
        Number of stocks to display
    export : str
        Export dataframe data to csv,json,xlsx file
    """
    df_high_short_interest = shortinterest_model.get_high_short_interest()
    df_high_short_interest = df_high_short_interest.iloc[1:].head(n=num)

    print(
        tabulate(
            df_high_short_interest,
            headers=df_high_short_interest.columns,
            floatfmt=".2f",
            showindex=False,
            tablefmt="fancy_grid",
        ),
        "\n",
    )

    export_data(
        export,
        os.path.dirname(os.path.abspath(__file__)),
        "lowfloat",
        df_high_short_interest,
    )
def high_short_interest(num: int, export: str):
    """Prints top N high shorted interest stocks from https://www.highshortinterest.com

    Parameters
    ----------
    num: int
        Number of stocks to display
    export : str
        Export dataframe data to csv,json,xlsx file
    """
    df_high_short_interest = shortinterest_model.get_high_short_interest()

    if df_high_short_interest.empty:
        console.print("No data available.", "\n")
        return

    df_high_short_interest = df_high_short_interest.iloc[1:].head(n=num)

    print_rich_table(
        df_high_short_interest,
        headers=list(df_high_short_interest.columns),
        show_index=False,
        title="Top Interest Stocks",
    )
    console.print("")

    export_data(
        export,
        os.path.dirname(os.path.abspath(__file__)),
        "hsi",
        df_high_short_interest,
    )
def high_short_interest(num: int, export: str):
    """Prints top N high shorted interest stocks from https://www.highshortinterest.com

    Parameters
    ----------
    num: int
        Number of stocks to display
    export : str
        Export dataframe data to csv,json,xlsx file
    """
    df_high_short_interest = shortinterest_model.get_high_short_interest()

    if df_high_short_interest.empty:
        print("No data available.", "\n")
        return

    df_high_short_interest = df_high_short_interest.iloc[1:].head(n=num)

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

    export_data(
        export,
        os.path.dirname(os.path.abspath(__file__)),
        "hsi",
        df_high_short_interest,
    )
Exemple #4
0
async def hsi_command(ctx, num="10"):
    """Show top high short interest stocks of over 20% ratio [shortinterest.com]"""

    try:
        # Debug user input
        if cfg.DEBUG:
            print(f"\n!stocks.dps.hsi {num}")

        # Check for argument
        if not num.lstrip("-").isnumeric():
            raise Exception("Number has to be an integer")

        num = int(num)

        if num < 0:
            raise Exception("Number has to be above 0")

        # Retrieve data
        df = shortinterest_model.get_high_short_interest()
        df = df.iloc[1:].head(n=num)

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

        # Output data
        future_column_name = df["Ticker"]
        df = df.transpose()
        df.columns = future_column_name
        df.drop("Ticker")
        columns = []
        initial_str = "Page 0: Overview"
        i = 1
        for column in df.columns.values:
            initial_str = initial_str + "\nPage " + str(i) + ": " + column
            i += 1
        columns.append(
            discord.Embed(
                title="Stocks: [highshortinterest.com] Top High Short Interest",
                description=initial_str,
                colour=cfg.COLOR,
            ).set_author(
                name=cfg.AUTHOR_NAME,
                icon_url=cfg.AUTHOR_ICON_URL,
            ))
        for column in df.columns.values:
            columns.append(
                discord.Embed(
                    title=
                    "Stocks: [highshortinterest.com] Top High Short Interest",
                    description="```" + df[column].fillna("").to_string() +
                    "```",
                    colour=cfg.COLOR,
                ).set_author(
                    name=cfg.AUTHOR_NAME,
                    icon_url=cfg.AUTHOR_ICON_URL,
                ))

        await pagination(columns, ctx)

    except Exception as e:
        embed = discord.Embed(
            title=
            "ERROR Stocks: [highshortinterest.com] Top High Short Interest",
            colour=cfg.COLOR,
            description=e,
        )
        embed.set_author(
            name=cfg.AUTHOR_NAME,
            icon_url=cfg.AUTHOR_ICON_URL,
        )

        await ctx.send(embed=embed)
Exemple #5
0
async def hsi_command(ctx, arg="10"):
    """Gets high shorted interest data from GST and sends it

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

    Returns
    -------
    discord message
        Sends a message containing an embed of the stocks with the top high
        shorted interest to the user
    """

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

        # Help
        if arg == "-h" or arg == "help":
            help_txt = "Display top high shorted interest stocks [Source: highshortinterest.com]\n"
            help_txt += "\nPossible arguments:\n"
            help_txt += "<NUM> Number of stocks to display. Default: 10"
            embed = discord.Embed(
                title="Stocks: [highshortinterest.com] Top High Short Interest HELP",
                description=help_txt,
                colour=cfg.COLOR,
            )
            embed.set_author(
                name=cfg.AUTHOR_NAME,
                icon_url=cfg.AUTHOR_ICON_URL,
            )

            await ctx.send(embed=embed)

        else:
            try:
                # Parse argument
                num = int(arg)
                if num < 0:
                    raise ValueError("Number has to be above 0")
            except ValueError:
                title = "ERROR Stocks: [SEC] Failure-to-deliver"
                embed = discord.Embed(title=title, colour=cfg.COLOR)
                embed.set_author(
                    name=cfg.AUTHOR_NAME,
                    icon_url=cfg.AUTHOR_ICON_URL,
                )
                embed.set_description(
                    "No number (int) entered."
                    "\nEnter a valid (positive) number, example: 10"
                )
                await ctx.send(embed=embed)
                if cfg.DEBUG:
                    print("ERROR: No (positive) int entered")
                return

            df = shortinterest_model.get_high_short_interest()
            df = df.iloc[1:].head(n=num)

            future_column_name = df["Ticker"]
            df = df.transpose()
            df.columns = future_column_name
            df.drop("Ticker")
            columns = []
            initial_str = "Page 0: Overview"
            i = 1
            for column in df.columns.values:
                initial_str = initial_str + "\nPage " + str(i) + ": " + column
                i += 1
            columns.append(
                discord.Embed(
                    title="Stocks: [highshortinterest.com] Top High Short Interest",
                    description=initial_str,
                    colour=cfg.COLOR,
                ).set_author(
                    name=cfg.AUTHOR_NAME,
                    icon_url=cfg.AUTHOR_ICON_URL,
                )
            )
            for column in df.columns.values:
                columns.append(
                    discord.Embed(
                        title="Stocks: [highshortinterest.com] Top High Short Interest",
                        description="```" + df[column].fillna("").to_string() + "```",
                        colour=cfg.COLOR,
                    ).set_author(
                        name=cfg.AUTHOR_NAME,
                        icon_url=cfg.AUTHOR_ICON_URL,
                    )
                )

            await pagination(columns, ctx)

    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}"
        )
        await ctx.send(embed=embed)
        if cfg.DEBUG:
            print(e)
Exemple #6
0
def hsi_command(num: int = 10):
    """Show top high short interest stocks of over 20% ratio [shortinterest.com]"""

    # Debug user input
    if cfg.DEBUG:
        logger.debug("dps-hsi %s", num)

    # Check for argument
    if num < 0:
        raise Exception("Number has to be above 0")

    # Retrieve data
    df = shortinterest_model.get_high_short_interest()
    df = df.iloc[1:].head(n=num)

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

    # Output data
    title = "Stocks: [highshortinterest.com] Top High Short Interest"

    future_column_name = df["Ticker"]
    df = df.transpose()
    df.columns = future_column_name
    df.drop("Ticker")
    embeds = []
    choices = [
        disnake.SelectOption(label="Overview", value="0", emoji="🟢"),
    ]
    initial_str = "Overview"
    i = 1
    for col_name in df.columns.values:
        menu = f"\nPage {i}: {col_name}"
        initial_str += f"\nPage {i}: {col_name}"
        choices.append(
            disnake.SelectOption(label=menu, value=f"{i}", emoji="🟢"), )
        i += 1

    reports = [f"{initial_str}"]
    embeds.append(
        disnake.Embed(
            title=title,
            description=initial_str,
            colour=cfg.COLOR,
        ).set_author(
            name=cfg.AUTHOR_NAME,
            icon_url=cfg.AUTHOR_ICON_URL,
        ))
    for column in df.columns.values:
        description = "```" + df[column].fillna("").to_string() + "```"
        embeds.append(
            disnake.Embed(
                title=title,
                description=description,
                colour=cfg.COLOR,
            ).set_author(
                name=cfg.AUTHOR_NAME,
                icon_url=cfg.AUTHOR_ICON_URL,
            ))
        reports.append(f"{description}")

    return {
        "view": Menu,
        "title": title,
        "description": reports,
        "embed": embeds,
        "choices": choices,
    }
Exemple #7
0
async def hsi_command(ctx, num: int = 10):
    """Show top high short interest stocks of over 20% ratio [shortinterest.com]"""

    try:
        # Debug user input
        if cfg.DEBUG:
            logger.debug("!stocks.dps.hsi %s", num)

        # Check for argument
        if num < 0:
            raise Exception("Number has to be above 0")

        # Retrieve data
        df = shortinterest_model.get_high_short_interest()
        df = df.iloc[1:].head(n=num)

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

        # Output data
        future_column_name = df["Ticker"]
        df = df.transpose()
        df.columns = future_column_name
        df.drop("Ticker")
        columns = []
        choices = [
            disnake.SelectOption(label="Overview", value="0", emoji="🟢"),
        ]
        initial_str = "Overview"
        i = 1
        for col_name in df.columns.values:
            menu = f"\nPage {i}: {col_name}"
            initial_str += f"\nPage {i}: {col_name}"
            choices.append(
                disnake.SelectOption(label=menu, value=f"{i}", emoji="🟢"), )
            i += 1
        columns.append(
            disnake.Embed(
                title="Stocks: [highshortinterest.com] Top High Short Interest",
                description=initial_str,
                colour=cfg.COLOR,
            ).set_author(
                name=cfg.AUTHOR_NAME,
                icon_url=cfg.AUTHOR_ICON_URL,
            ))
        for column in df.columns.values:
            columns.append(
                disnake.Embed(
                    title=
                    "Stocks: [highshortinterest.com] Top High Short Interest",
                    description="```" + df[column].fillna("").to_string() +
                    "```",
                    colour=cfg.COLOR,
                ).set_author(
                    name=cfg.AUTHOR_NAME,
                    icon_url=cfg.AUTHOR_ICON_URL,
                ))

        await ctx.send(embed=columns[0], view=Menu(columns, choices))

    except Exception as e:
        embed = disnake.Embed(
            title=
            "ERROR Stocks: [highshortinterest.com] Top High Short Interest",
            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)
def test_get_high_short_interest(recorder):
    result_df = shortinterest_model.get_high_short_interest()

    recorder.capture(result_df)