From 5791c091355585ee3df7a925100b048f11b4965f Mon Sep 17 00:00:00 2001 From: alexferrari88 <49028826+alexferrari88@users.noreply.github.com> Date: Thu, 5 May 2022 18:38:13 +0200 Subject: [PATCH] Fix bugs for fetching crypto prices on chain and displaying very small numbers in tables (#1762) * Fix bugs fetching token prices #1741 * Fix bug displaying very small floats in tables #1741 Co-authored-by: Alex Ferrari Co-authored-by: Theodore Aptekarev --- openbb_terminal/cryptocurrency/onchain/ethplorer_model.py | 5 +++-- openbb_terminal/helper_funcs.py | 4 +++- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/openbb_terminal/cryptocurrency/onchain/ethplorer_model.py b/openbb_terminal/cryptocurrency/onchain/ethplorer_model.py index c37293f0243..51ffe4a68fe 100644 --- a/openbb_terminal/cryptocurrency/onchain/ethplorer_model.py +++ b/openbb_terminal/cryptocurrency/onchain/ethplorer_model.py @@ -161,7 +161,7 @@ def make_request( if response.status_code == 200: result = response.json() - if result: + if not result: console.print("No data found") elif response.status_code == 401: @@ -532,7 +532,8 @@ def get_token_historical_price(address) -> pd.DataFrame: prices_df = pd.DataFrame(prices) prices_df["ts"] = prices_df["ts"].apply(lambda x: datetime.fromtimestamp(x)) - prices_df.drop("tmp", axis=1, inplace=True) + if "tmp" in prices_df.columns: + prices_df.drop("tmp", axis=1, inplace=True) return prices_df[ ["date", "open", "close", "high", "low", "volumeConverted", "cap", "average"] diff --git a/openbb_terminal/helper_funcs.py b/openbb_terminal/helper_funcs.py index e3fb8ee67f2..7ad7ecb9e51 100644 --- a/openbb_terminal/helper_funcs.py +++ b/openbb_terminal/helper_funcs.py @@ -190,7 +190,9 @@ def print_rich_table( for idx, values in zip(df.index.tolist(), df.values.tolist()): row = [str(idx)] if show_index else [] row += [ - str(x) if not isinstance(x, float) else f"{x:{floatfmt[idx]}}" + str(x) + if not isinstance(x, float) + else (f"{x:{floatfmt[idx]}}" if x >= 0.01 else f"{x:.2e}") for idx, x in enumerate(values) ] table.add_row(*row)