summaryrefslogtreecommitdiffstats
path: root/runtime/vim48x48.xpm
stat options
Period:
Authors:

Commits per author per week (path 'runtime/vim48x48.xpm')

AuthorW33 2024W34 2024W35 2024W36 2024Total
Total00000
Mirror of https://github.com/OpenBB-finance/OpenBBTerminalmatthias
summaryrefslogtreecommitdiffstats
path: root/openbb_terminal/cryptocurrency/nft/nftpricefloor_view.py
blob: dfd2c6f504bd6ed79a1f90f75d93570087a6621c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
""" NFT Price Floor View """
__docformat__ = "numpy"

# flake8: noqa

import logging
import os
from typing import List, Optional
from matplotlib import pyplot as plt
from openbb_terminal import config_terminal as cfg
from openbb_terminal.config_plot import PLOT_DPI
from openbb_terminal.config_terminal import theme
from openbb_terminal.cryptocurrency.nft import nftpricefloor_model
from openbb_terminal.decorators import log_start_end
from openbb_terminal.helper_funcs import (
    export_data,
    is_valid_axes_count,
    plot_autoscale,
    print_rich_table,
)
from openbb_terminal.rich_config import console

logger = logging.getLogger(__name__)


@log_start_end(log=logger)
def display_collections(
    show_fp: bool = False,
    show_sales: bool = False,
    limit: int = 5,
    export: str = "",
    sheet_name: str = None,
):
    """Display NFT collections. [Source: https://nftpricefloor.com/]

    Parameters
    ----------
    show_fp : bool
        Show NFT Price Floor for top collections
    limit: int
        Number of NFT collections to display
    export : str
        Export dataframe data to csv,json,xlsx file
    """
    df = nftpricefloor_model.get_collections()

    if df.empty:
        console.print("No data found.", "\n")
    else:
        df = df[
            [
                "slug",
                "floorInfo.currentFloorEth",
                "totalSupply",
                "listedCount",
                "blockchain",
            ]
        ]
        if show_fp or show_sales:
            _, ax = plt.subplots(figsize=plot_autoscale(), dpi=PLOT_DPI)
            for collection in df["slug"].head(limit).values:
                df_collection = nftpricefloor_model.get_floor_price(collection)
                if not df_collection.empty:
                    values = (
                        df_collection["floorEth"]
                        if show_fp
                        else df_collection["salesCount"]
                    )
                    ax.plot(df_collection.index, values, label=collection)
            ax.set_ylabel("Floor Price [ETH]" if show_fp else "Sales")
            cfg.theme.style_primary_axis(ax)
            ax.legend()
            ax.set_title("Collections Floor Price" if show_fp else "Collections Sales")
            cfg.theme.visualize_output()

        print_rich_table(
            df.head(limit),
            headers=list(df.columns),
            show_index=False,
            title="NFT Collections",
        )

    export_data(
        export,
        os.path.dirname(os.path.abspath(__file__)),
        "collections",
        df,
        sheet_name,
    )


@log_start_end(log=logger)
def display_floor_price(
    slug: str,
    limit: int = 10,
    export: str = "",
    sheet_name: str = None,
    external_axes: Optional[List[plt.Axes]] = None,
    raw: bool = False,
):
    """Display NFT collection floor price over time. [Source: https://nftpricefloor.com/]

    Parameters
    ----------
    slug: str
        NFT collection slug
    raw: bool
        Flag to display raw data
    limit: int
        Number of raw data to show
    sheet_name: str
        Optionally specify the name of the sheet the data is exported to.
    export: str
        Format to export data
    external_axes : Optional[List[plt.Axes]], optional
        External axes (2 axes are expected in the list), by default None
    """
    df = nftpricefloor_model.get_floor_price(slug)
    if df.empty:
        console.print("No data found.", "\n")
    elif not df.empty:
        if raw:
            print_rich_table(
                df.head(limit),
                index_name="date",
                headers=list(df.columns),
                show_index=True,
                title=f"{slug} Floor Price",
            )
        # This plot has 1 axis
        if external_axes is None:
            _, ax = plt.subplots(figsize=plot_autoscale(), dpi=PLOT_DPI)
        elif is_valid_axes_count(external_axes, 1):
            (ax,) = external_axes
        ax.bar(df.index, df["salesCount"], color=theme.down_color, label="Sales")
        ax.set_xlim(
            df.index[0],
            df.index[-1],
        )

        ax2 = ax.twinx()
        ax2.plot(df["floorEth"], color=theme.up_color, label="Floor Price")
        ax2.set_ylabel("Sales", labelpad=20)
        ax2.set_zorder(ax2.get_zorder() + 1)
        ax.patch.set_visible(False)
        ax2.yaxis.set_label_position("left")
        ax.set_ylabel("Floor Price [ETH]", labelpad=30)
        ax.set_title(f"{slug} Floor Price")
        ax.legend(loc="upper left")
        ax2.legend(loc="upper right")
        cfg.theme.style_primary_axis(ax)

        if external_axes is None:
            cfg.theme.visualize_output()

        export_data(
            export,
            os.path.dirname(os.path.abspath(__file__)),
            "fp",
            df,
            sheet_name,
        )