def get_market_data(self) -> pd.DataFrame: """Get all the base market information about given coin. [Source: CoinGecko] Returns ------- pandas.DataFrame Base market information about coin Metric,Value """ market_data = self.coin.get("market_data", {}) market_columns_denominated = [ "market_cap", "fully_diluted_valuation", "total_volume", "high_24h", "low_24h", ] denominated_data = create_dictionary_with_prefixes( market_columns_denominated, market_data, DENOMINATION) market_single_columns = [ "market_cap_rank", "total_supply", "max_supply", "circulating_supply", "price_change_percentage_24h", "price_change_percentage_7d", "price_change_percentage_30d", "price_change_percentage_60d", "price_change_percentage_1y", "market_cap_change_24h", ] single_stats = {} for col in market_single_columns: single_stats[col] = market_data.get(col) single_stats.update(denominated_data) try: single_stats["circulating_supply_to_total_supply_ratio"] = ( single_stats["circulating_supply"] / single_stats["total_supply"]) except (ZeroDivisionError, TypeError) as e: logger.exception(str(e)) console.print(e) df = pd.Series(single_stats).to_frame().reset_index() df.columns = ["Metric", "Value"] df["Metric"] = df["Metric"].apply( lambda x: lambda_replace_underscores_in_column_names(x) if isinstance(x, str) else x) return df[df["Value"].notna()]
def _get_base_market_data_info(self): """Helper method that fetches all the base market/price information about given coin Returns ------- dict """ market_dct = {} market_data = self.coin.get("market_data") for stat in [ "total_supply", "max_supply", "circulating_supply", "price_change_percentage_24h", "price_change_percentage_7d", "price_change_percentage_30d", ]: market_dct[stat] = market_data.get(stat) prices = create_dictionary_with_prefixes(["current_price"], market_data, DENOMINATION) market_dct.update(prices) return market_dct