def display_exchange_rates(sortby: str, descend: bool, top: int, export: str) -> None: """Shows list of crypto, fiats, commodity exchange rates. [Source: CoinGecko] Parameters ---------- top: int Number of records to display sortby: str Key by which to sort data descend: bool Flag to sort data descending export : str Export dataframe data to csv,json,xlsx file """ df = gecko.get_exchange_rates().sort_values(by=sortby, ascending=descend) if not df.empty: if gtff.USE_TABULATE_DF: print( tabulate( df.head(top), headers=df.columns, floatfmt=".2f", showindex=False, tablefmt="fancy_grid", ), "\n", ) else: print(df.to_string, "\n") export_data( export, os.path.dirname(os.path.abspath(__file__)), "exrates", df, ) else: print("") print("Unable to retrieve data from CoinGecko.") print("")
def display_exchange_rates(sortby: str, descend: bool, top: int, export: str) -> None: """Shows list of crypto, fiats, commodity exchange rates. [Source: CoinGecko] Parameters ---------- top: int Number of records to display sortby: str Key by which to sort data descend: bool Flag to sort data descending export : str Export dataframe data to csv,json,xlsx file """ df = gecko.get_exchange_rates().sort_values(by=sortby, ascending=descend) if not df.empty: print_rich_table( df.head(top), headers=list(df.columns), show_index=False, title="Exchange Rates", ) console.print("") export_data( export, os.path.dirname(os.path.abspath(__file__)), "exrates", df, ) else: console.print("") console.print("Unable to retrieve data from CoinGecko.") console.print("")
def exchange_rates(other_args: List[str]): """Shows list of crypto, fiats, commodity exchange rates from CoinGecko Parameters ---------- other_args: List[str] Arguments to pass to argparse """ parser = argparse.ArgumentParser( prog="exrates", add_help=False, formatter_class=argparse.ArgumentDefaultsHelpFormatter, description=""" Shows list of crypto, fiats, commodity exchange rates from CoinGecko You can look on only top N number of records with --top, You can sort by Index, Name, Unit, Value, Type, and also use --descend flag to sort descending.""", ) parser.add_argument( "-t", "--top", dest="top", type=check_positive, help="top N number records", default=15, ) parser.add_argument( "-s", "--sort", dest="sortby", type=str, help="Sort by given column. Default: Index", default="Index", choices=["Index", "Name", "Unit", "Value", "Type"], ) parser.add_argument( "--descend", action="store_false", help="Flag to sort in descending order (lowest first)", dest="descend", default=True, ) try: ns_parser = parse_known_args_and_warn(parser, other_args) if not ns_parser: return df = gecko.get_exchange_rates().sort_values( by=ns_parser.sortby, ascending=ns_parser.descend) print( tabulate( df.head(ns_parser.top), headers=df.columns, floatfmt=".2f", showindex=False, tablefmt="fancy_grid", ), "\n", ) except Exception as e: print(e, "\n")