code: """CoinMarketCap model"""
  __docformat__ = "numpy"
  
  import logging
  
  import pandas as pd
  from coinmarketcapapi import CoinMarketCapAPI, CoinMarketCapAPIError
  
  import openbb_terminal.config_terminal as cfg
  from openbb_terminal.decorators import log_start_end
  from openbb_terminal.rich_config import console
  
  logger = logging.getLogger(__name__)
  
  FILTERS = ["Symbol", "CMC_Rank", "LastPrice", "DayPctChange", "MarketCap"]
  
  
  @log_start_end(log=logger)
  def get_cmc_top_n() -> pd.DataFrame:
      """Shows top n coins. [Source: CoinMarketCap]
  
      Returns
      -------
      pd.DataFrame
          Top coin on CoinMarketCap
  
      """
      df = pd.DataFrame()
  
      try:
          cmc = CoinMarketCapAPI(cfg.API_CMC_KEY)
          ratings = cmc.cryptocurrency_listings_latest().data
  
          symbol, rank, price, pchange1d, mkt_cap = [], [], [], [], []
  
          for coin in ratings:
              symbol.append(coin["symbol"])
              rank.append(coin["cmc_rank"])
              price.append(coin["quote"]["USD"]["price"])
              pchange1d.append(coin["quote"]["USD"]["percent_change_24h"])
              mkt_cap.append(coin["quote"]["USD"]["market_cap"] / (10**9))
  
          df = pd.DataFrame(data=[symbol, rank, price, pchange1d, mkt_cap]).transpose()
          df.columns = [
              "Symbol",
              "CMC_Rank",
              "Last Price",
              "1 Day Pct Change",
              "Market Cap ($B)",
          ]
      except CoinMarketCapAPIError as e:
          if "API Key" in str(e):
              console.print("[red]Invalid API Key[/red]\n")
          else:
              console.print(e)
  
      return df
   import logging
  
  import disnake
  import pandas as pd
  
  from bots import imps
  from openbb_terminal.decorators import log_start_end
  from openbb_terminal.stocks.government import quiverquant_model
  
  logger = logging.getLogger(__name__)
  
  
  @log_start_end(log=logger)
  def lastcontracts_command(past_transactions_days: int = 2, num: int = 20):
      """Displays last government contracts [quiverquant.com]"""
  
      # Debug user input
      if imps.DEBUG:
          logger.debug("gov lastcontracts %s %s", past_transactions_days, num)
  
      df_contracts = quiverquant_model.get_government_trading("contracts")
  
      if df_contracts.empty:
          logger.debug("No government contracts found")
          raise Exception("No government contracts found")
  
      df_contracts.sort_values("Date", ascending=False)
  
      df_contracts["Date"] = pd.to_datetime(df_contracts["Date"])
      df_contracts["Date"] = df_contracts["Date"].dt.date
  
      df_contracts.drop_duplicates(inplace=True)
      df_contracts = df_contracts[
          df_contracts["Date"].isin(
              df_contracts["Date"].unique()[:past_transactions_days]
          )
      ]
  
      df_contracts = df_contracts[["Date", "Ticker", "Amount", "Agency"]][:num]
      choices = [
          disnake.SelectOption(label="Overview", value="0", emoji="🟢"),
      ]
      title = "Stocks: [quiverquant.com] Top buy government trading"
      initial_str = "Overview"
      i = 1
      for col_name in df_contracts["Ticker"].values:
          menu = f"\nPage {i}: {col_name}"
          initial_str += f"\nPage {i}: {col_name}"
          choices.append(
              disnake.SelectOption(label=menu, value=f"{i}", emoji="🟢"),
          )
          i += 1
  
      embeds = []
      df_contracts = df_contracts.T
      reports = [f"{initial_str}"]
      embeds.append(
          disnake.Embed(
              title=title,
              description=initial_str,
              colour=imps.COLOR,
          ).set_author(
              name=imps.AUTHOR_NAME,
              icon_url=imps.AUTHOR_ICON_URL,
          )
      )
      for column in df_contracts.columns.values:
          description = "```" + df_contracts[column].fillna("").to_string() + "```"
          embeds.append(
              disnake.Embed(description=description, colour=imps.COLOR,).set_author(
                  name=imps.AUTHOR_NAME,
                  icon_url=imps.AUTHOR_ICON_URL,
              )
          )
          reports.append(f"{description}")
  
      return {
          "view": imps.Menu,
          "title": title,
          "description": reports,
          "embed": embeds,
          "choices": choices,
      }
  
apis: pandas.DataFrame
apis: pandas.to_datetime