Skip to content

Commit

Permalink
Fix crypto/defi/anchor (#4892)
Browse files Browse the repository at this point in the history
* handle defi anchor exceptions

* reason

* mypy

---------

Co-authored-by: Henrique Joaquim <[email protected]>
  • Loading branch information
montezdesousa and hjoaquim authored Apr 26, 2023
1 parent 0d7318b commit 45a0609
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 16 deletions.
7 changes: 5 additions & 2 deletions openbb_terminal/cryptocurrency/defi/cryptosaurio_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

from openbb_terminal.decorators import log_start_end
from openbb_terminal.helper_funcs import request
from openbb_terminal.rich_config import console

logger = logging.getLogger(__name__)

Expand All @@ -33,13 +34,15 @@ def get_anchor_data(address: str = "") -> Tuple[pd.DataFrame, pd.DataFrame, str]
"""

if not address.startswith("terra"):
raise Exception(
console.print(
"Select a valid address. Valid terra addresses start with 'terra'"
)
return pd.DataFrame(), pd.DataFrame(), ""

response = request(f"{api_url}/get-anchor-protocol-data-v2/{address}")
if response.status_code != 200:
raise Exception(f"Status code: {response.status_code}. Reason: {response.text}")
console.print(f"Status code: {response.status_code}. Reason: {response.reason}")
return pd.DataFrame(), pd.DataFrame(), ""

data = response.json()
df = pd.DataFrame(reversed(data["historicalData"]))
Expand Down
31 changes: 17 additions & 14 deletions openbb_terminal/cryptocurrency/defi/cryptosaurio_view.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,10 @@ def display_anchor_data(

df, df_deposits, stats_str = cryptosaurio_model.get_anchor_data(address=address)

console.print(f"\n{stats_str}\n")
if stats_str:
console.print(f"\n{stats_str}\n")

if show_transactions:
if not df_deposits.empty and show_transactions:
print_rich_table(
df_deposits,
headers=list(df_deposits.columns),
Expand All @@ -52,18 +53,20 @@ def display_anchor_data(
export=bool(export),
)

fig = OpenBBFigure(yaxis_title="Earnings Value [UST]")
fig.set_title("Earnings in Anchor Earn")
if not df.empty:
fig = OpenBBFigure(yaxis_title="Earnings Value [UST]")
fig.set_title("Earnings in Anchor Earn")

fig.add_scatter(x=df["time"], y=df["yield"], name="Earnings")
fig.add_scatter(x=df["time"], y=df["yield"], name="Earnings")

export_data(
export,
os.path.dirname(os.path.abspath(__file__)),
"anchor",
df,
sheet_name,
fig,
)
export_data(
export,
os.path.dirname(os.path.abspath(__file__)),
"anchor",
df,
sheet_name,
fig,
)

return fig.show(external=external_axes)
return fig.show(external=external_axes)
return None

0 comments on commit 45a0609

Please sign in to comment.