def test_get_orders(
        self,
        mock_requests_get,
        mock_fidelity_orders_html,
        expected_header,
        expected_orders,
    ):
        mock_requests_get.get().text = mock_fidelity_orders_html
        header, ret = get_orders()

        assertions.assertEqual.__self__.maxDiff = None
        assertions.assertEqual(
            header.replace("\r\n", "\n"), expected_header.replace("\r\n", "\n")
        )
        assertions.assertEqual(
            ret.to_csv().replace("\r\n", "\n"), expected_orders.replace("\r\n", "\n")
        )
예제 #2
0
def ford_command():
    """Display Orders by Fidelity Customers. [Source: Fidelity]"""

    # Debug
    if cfg.DEBUG:
        logger.debug("disc-ford")
    order_header, df_orders = fidelity_model.get_orders()

    df_orders = df_orders.head(n=30).iloc[:, :-1]
    df_orders = df_orders.applymap(str)

    font_color = (["white"] * 2 + [[
        "#ad0000" if boolv else "#0d5700"
        for boolv in df_orders["Price Change"].str.contains("-")
    ]] + [["white"] * 3])

    df_orders.set_index("Symbol", inplace=True)
    df_orders = df_orders.apply(lambda x: x.str.slice(0, 20))

    dindex = len(df_orders.index)
    fig = df2img.plot_dataframe(
        df_orders,
        fig_size=(1500, (40 + (40 * dindex))),
        col_width=[1, 3, 2.2, 3, 2, 2],
        tbl_cells=dict(
            align=["left", "center", "left", "left", "center"],
            font=dict(color=font_color),
            height=35,
        ),
        template="plotly_dark",
        font=dict(
            family="Consolas",
            size=20,
        ),
        paper_bgcolor="rgba(0, 0, 0, 0)",
    )
    imagefile = save_image("disc-ford.png", fig)

    return {
        "title": "Fidelity Customer Orders",
        "imagefile": imagefile,
    }
예제 #3
0
def orders_view(num: int, export: str):
    """Prints last N orders by Fidelity customers. [Source: Fidelity]

    Parameters
    ----------
    num: int
        Number of stocks to display
    export : str
        Export dataframe data to csv,json,xlsx file
    """
    order_header, df_orders = fidelity_model.get_orders()
    print(order_header, ":")

    pd.set_option("display.max_colwidth", None)

    if gtff.USE_COLOR:
        df_orders["Buy / Sell Ratio"] = df_orders["Buy / Sell Ratio"].apply(
            buy_sell_ratio_color_red_green
        )
        df_orders["Price Change"] = df_orders["Price Change"].apply(
            price_change_color_red_green
        )

    df_orders = df_orders.head(n=num).iloc[:, :-1]

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

    export_data(
        export,
        os.path.dirname(os.path.abspath(__file__)),
        "ford",
        df_orders,
    )
예제 #4
0
def orders_view(num: int, export: str):
    """Prints last N orders by Fidelity customers. [Source: Fidelity]

    Parameters
    ----------
    num: int
        Number of stocks to display
    export : str
        Export dataframe data to csv,json,xlsx file
    """
    order_header, df_orders = fidelity_model.get_orders()

    pd.set_option("display.max_colwidth", None)

    if gtff.USE_COLOR:
        df_orders["Buy / Sell Ratio"] = df_orders["Buy / Sell Ratio"].apply(
            lambda_buy_sell_ratio_color_red_green)
        df_orders["Price Change"] = df_orders["Price Change"].apply(
            lambda_price_change_color_red_green)

    df_orders = df_orders.head(n=num).iloc[:, :-1]

    print_rich_table(
        df_orders,
        headers=[x.title() for x in df_orders.columns],
        show_index=False,
        title=f"{order_header}:",
    )
    console.print("")

    export_data(
        export,
        os.path.dirname(os.path.abspath(__file__)),
        "ford",
        df_orders,
    )
예제 #5
0
async def ford_command(ctx):
    """Display Orders by Fidelity Customers. [Source: Fidelity]

    Parameters
    ----------
    num: Number of stocks to display
    """

    try:
        # Debug
        if cfg.DEBUG:
            logger.debug("!ford")
        order_header, df_orders = fidelity_model.get_orders()

        df_orders = df_orders.head(n=30).iloc[:, :-1]
        df_orders = df_orders.applymap(str)

        font_color = (["white"] * 2 + [[
            "#ad0000" if boolv else "#0d5700"
            for boolv in df_orders["Price Change"].str.contains("-")
        ]] + [["white"] * 3])

        df_orders.set_index("Symbol", inplace=True)
        df_orders = df_orders.apply(lambda x: x.str.slice(0, 20))

        dindex = len(df_orders.index)
        fig = df2img.plot_dataframe(
            df_orders,
            fig_size=(1500, (40 + (40 * dindex))),
            col_width=[1, 3, 2.2, 3, 2, 2],
            tbl_cells=dict(
                align=["left", "center", "left", "left", "center"],
                font=dict(color=font_color),
                height=35,
            ),
            template="plotly_dark",
            font=dict(
                family="Consolas",
                size=20,
            ),
            paper_bgcolor="rgba(0, 0, 0, 0)",
        )
        imagefile = "disc-ford.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 = "Fidelity Customer Orders"
        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 Fidelity Customer Orders",
            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)
예제 #6
0
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 + [[
        "#e4003a" if boolv else "#00ACFF"
        for boolv in df_orders["Price Change"].str.contains("-")
    ]] + [["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,
    }
def test_get_orders(recorder):
    order_header, df_orders = fidelity_model.get_orders()
    recorder.capture(order_header)
    recorder.capture(df_orders)