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 <a.ferrari88@gmail.com>
Co-authored-by: Theodore Aptekarev <aptekarev@gmail.com>
This commit is contained in:
alexferrari88
2022-05-05 18:38:13 +02:00
committed by GitHub
parent 2ce3fe460b
commit 5791c09135
2 changed files with 6 additions and 3 deletions

View File

@@ -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"]

View File

@@ -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)