def display_coins(category: str,
                  top: int = 250,
                  sortby: str = "Symbol",
                  export: str = "") -> None:
    """Display top coins [Source: CoinGecko]

    Parameters
    ----------
    category: str
        Coingecko category. If no category is passed it will search for all coins. (E.g., smart-contract-platform)
    top: int
        Number of records to display
    sortby: str
        Key to sort data
    export : str
        Export dataframe data to csv,json,xlsx file
    """
    df = pycoingecko_model.get_coins(top=top, category=category)
    if not df.empty:
        df = df[[
            "symbol",
            "name",
            "total_volume",
            "market_cap",
            "market_cap_rank",
            "price_change_percentage_7d_in_currency",
            "price_change_percentage_24h_in_currency",
        ]]
        df = df.set_axis(
            COINS_COLUMNS,
            axis=1,
            inplace=False,
        )
        if sortby in COINS_COLUMNS:
            df = df[(df["Volume [$]"].notna())
                    & (df["Market Cap [$]"].notna())].sort_values(
                        by=sortby, ascending=False)
        for col in ["Volume [$]", "Market Cap [$]"]:
            if col in df.columns:
                df[col] = df[col].apply(
                    lambda x: lambda_very_long_number_formatter(x))
        print_rich_table(
            df.head(top),
            headers=list(df.columns),
            show_index=False,
        )
        console.print("")

        export_data(
            export,
            os.path.dirname(os.path.abspath(__file__)),
            "cgtop",
            df,
        )
    else:
        console.print("\nUnable to retrieve data from CoinGecko.\n")
def get_stable_coins(top: int = 20) -> pd.DataFrame:
    """Returns top stable coins [Source: CoinGecko]

    Returns
    -------
    pandas.DataFrame
        Rank, Name, Symbol, Price, Change_24h, Exchanges, Market_Cap, Change_30d, Url
    """

    df = get_coins(top=top, category="stablecoins")
    return df[COINS_COLUMNS]
Exemple #3
0
def test_get_coins(kwargs, recorder):
    result = pycoingecko_model.get_coins(**kwargs)
    recorder.capture(result)