Пример #1
0
def display_defi_tvl(
    top: int,
    export: str = "",
    external_axes: Optional[List[plt.Axes]] = None,
) -> None:
    """Displays historical values of the total sum of TVLs from all listed protocols.
    [Source: https://docs.llama.fi/api]

    Parameters
    ----------
    top: int
        Number of records to display
    export : str
        Export dataframe data to csv,json,xlsx file
    external_axes : Optional[List[plt.Axes]], optional
        External axes (1 axis is expected in the list), by default None
    """

    # This plot has 1 axis
    if not external_axes:
        _, ax = plt.subplots(figsize=plot_autoscale(), dpi=PLOT_DPI)
    else:
        if len(external_axes) != 1:
            logger.error("Expected list of one axis item.")
            console.print("[red]Expected list of one axis item./n[/red]")
            return
        (ax, ) = external_axes

    df = llama_model.get_defi_tvl()
    df_data = df.copy()
    df = df.tail(top)

    ax.plot(df["date"], df["totalLiquidityUSD"], ms=2)
    # ax.set_xlim(df["date"].iloc[0], df["date"].iloc[-1])

    ax.set_ylabel("Total Value Locked ($)")
    ax.set_title("Total Value Locked in DeFi")
    ax.get_yaxis().set_major_formatter(
        ticker.FuncFormatter(lambda x, _: lambda_long_number_format(x)))
    cfg.theme.style_primary_axis(ax)

    if not external_axes:
        cfg.theme.visualize_output()

    export_data(
        export,
        os.path.dirname(os.path.abspath(__file__)),
        "stvl",
        df_data,
    )
Пример #2
0
def display_defi_tvl(top: int, export: str = "") -> None:
    """Displays historical values of the total sum of TVLs from all listed protocols.
    [Source: https://docs.llama.fi/api]

    Parameters
    ----------
    top: int
        Number of records to display
    export : str
        Export dataframe data to csv,json,xlsx file
    """

    df = llama_model.get_defi_tvl()
    df_data = df.copy()

    df = df.tail(top)

    fig, ax = plt.subplots(figsize=plot_autoscale(), dpi=PLOT_DPI)

    ax.plot(df["date"], df["totalLiquidityUSD"], "-ok", ms=2)
    ax.set_xlabel("Time")
    ax.set_xlim(df["date"].iloc[0], df["date"].iloc[-1])
    dateFmt = mdates.DateFormatter("%m/%d/%Y")

    ax.xaxis.set_major_formatter(dateFmt)
    ax.tick_params(axis="x", labelrotation=45)
    ax.set_ylabel("Total Value Locked ($)")
    ax.grid(b=True, which="major", color="#666666", linestyle="-")
    ax.minorticks_on()
    ax.grid(b=True, which="minor", color="#999999", linestyle="-", alpha=0.2)
    ax.set_title("Total Value Locked in DeFi")
    ax.get_yaxis().set_major_formatter(
        ticker.FuncFormatter(lambda x, _: long_number_format(x)))
    fig.tight_layout(pad=2)

    if gtff.USE_ION:
        plt.ion()
    plt.show()
    console.print("")

    export_data(
        export,
        os.path.dirname(os.path.abspath(__file__)),
        "stvl",
        df_data,
    )
Пример #3
0
def display_defi_tvl(top: int, export: str = "") -> None:
    """Displays historical values of the total sum of TVLs from all listed protocols.
    [Source: https://docs.llama.fi/api]

    Parameters
    ----------
    top: int
        Number of records to display
    export : str
        Export dataframe data to csv,json,xlsx file
    """

    df = llama_model.get_defi_tvl()
    df_data = df.copy()

    df = df.tail(top)
    df["totalLiquidityUSD"] = df["totalLiquidityUSD"] / 1_000_000_000

    plt.figure(figsize=plot_autoscale(), dpi=PLOT_DPI)

    plt.plot(df["date"], df["totalLiquidityUSD"], "-ok", ms=2)
    plt.xlabel("Time")
    plt.xlim(df["date"].iloc[0], df["date"].iloc[-1])
    plt.gcf().autofmt_xdate()
    plt.ylabel("Total Value Locked USD [1B]")
    plt.grid(b=True, which="major", color="#666666", linestyle="-")
    plt.minorticks_on()
    plt.grid(b=True, which="minor", color="#999999", linestyle="-", alpha=0.2)
    plt.title("Total Value Locked in DeFi [Billions USD]")
    if gtff.USE_ION:
        plt.ion()
    plt.show()
    print("")

    export_data(
        export,
        os.path.dirname(os.path.abspath(__file__)),
        "tvl",
        df_data,
    )
Пример #4
0
def test_get_defi_tvl(recorder):
    df = llama_model.get_defi_tvl()
    recorder.capture(df)