Skip to content

Commit

Permalink
added warning message
Browse files Browse the repository at this point in the history
  • Loading branch information
Dprof-in-tech committed Sep 30, 2024
1 parent f33031b commit 5120703
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 15 deletions.
1 change: 1 addition & 0 deletions app.py
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,7 @@ def main():
protocol_main_chart_data = protocol_main_chart_data_mapping[protocol]
if protocol_main_chart_data is None or protocol_main_chart_data.empty:
logging.warning(f"No data for pair {debt_token} - {collateral_token} from {protocol}")
streamlit.subheader(f":warning: No liquidable debt for the {collateral_token} collateral token and the {debt_token} debt token exists on the lending protocol.")
continue
protocol_loans_data = protocol_loans_data_mapping[protocol]
if main_chart_data.empty:
Expand Down
49 changes: 34 additions & 15 deletions src/main_chart.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,23 +103,42 @@ def get_main_chart_figure(
color_map_liquidity = {"debt_token_supply": "#1f77b4"} # blue
figure = plotly.graph_objs.Figure()

custom_columns = [
"liquidable_debt",
"liquidable_debt_zkLend",
"liquidable_debt_at_interval_Nostra Alpha",
"liquidable_debt_at_interval_Nostra Mainnet"
]
customdata = []
for col in custom_columns:
if col in data.columns:
customdata.append(data[col].values)
else:
customdata.append([0] * len(data)) # Use 0 if the column is missing

# Transpose customdata to match rows to records
customdata = list(zip(*customdata))

# Add bars for each protocol and the total liquidable debt
for col in color_map_protocol.keys():
figure.add_trace(plotly.graph_objs.Bar(
x=data["collateral_token_price"],
y=data[col],
name = col.replace("liquidable_debt_at_interval", f"Liquidable {debt_token} debt").replace("_", " "),
marker_color = color_map_protocol[col],
opacity = 0.7,
customdata=data[["liquidable_debt", "liquidable_debt_zkLend", "liquidable_debt_at_interval_Nostra Alpha", "liquidable_debt_at_interval_Nostra Mainnet"]].values,
hovertemplate=(
"<b>Price:</b> %{x}<br>"
"<b>Total Volume:</b> %{customdata[0]:,.2f}<br>"
"<b>ZkLend Volume:</b> %{customdata[1]:,.2f}<br>"
"<b>Nostra Alpha Volume:</b> %{customdata[2]:,.2f}<br>"
"<b>Nostra Mainnet Volume:</b> %{customdata[3]:,.2f}<br>"
),
))
try:
figure.add_trace(plotly.graph_objs.Bar(
x=data["collateral_token_price"],
y=data[col],
name = col.replace("liquidable_debt_at_interval", f"Liquidable {debt_token} debt").replace("_", " "),
marker_color = color_map_protocol[col],
opacity = 0.7,
customdata=customdata,
hovertemplate=(
"<b>Price:</b> %{x}<br>"
"<b>Total Volume:</b> %{customdata[0]:,.2f}<br>"
"<b>ZkLend Volume:</b> %{customdata[1]:,.2f}<br>"
"<b>Nostra Alpha Volume:</b> %{customdata[2]:,.2f}<br>"
"<b>Nostra Mainnet Volume:</b> %{customdata[3]:,.2f}<br>"
),
))
except KeyError: # If `KeyError` is raised from accessing data[col]
continue # Skip this trace

# Add a separate trace for debt_token_supply with overlay mode
figure.add_trace(plotly.graph_objs.Bar(
Expand Down

0 comments on commit 5120703

Please sign in to comment.