-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
9f5c6d5
commit 0298a56
Showing
7 changed files
with
390 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
import json | ||
|
||
from driftpy.constants.perp_markets import mainnet_perp_market_configs | ||
from driftpy.constants.spot_markets import mainnet_spot_market_configs | ||
from lib.api import api2 | ||
import pandas as pd | ||
from requests.exceptions import JSONDecodeError | ||
import streamlit as st | ||
|
||
|
||
options = [0, 1, 2, 3] | ||
labels = [ | ||
"none", | ||
"liq within 50% of oracle", | ||
"maint. health < 10%", | ||
"init. health < 10%", | ||
] | ||
|
||
|
||
def asset_liab_matrix_cached_page(): | ||
params = st.query_params | ||
mode = int(params.get("mode", 0)) | ||
perp_market_index = int(params.get("perp_market_index", 0)) | ||
|
||
mode = st.selectbox( | ||
"Options", options, format_func=lambda x: labels[x], index=options.index(mode) | ||
) | ||
st.query_params.update({"mode": mode}) | ||
|
||
perp_market_index = st.selectbox( | ||
"Market index", | ||
[x.market_index for x in mainnet_perp_market_configs], | ||
index=[x.market_index for x in mainnet_perp_market_configs].index( | ||
perp_market_index | ||
), | ||
) | ||
st.query_params.update({"perp_market_index": perp_market_index}) | ||
|
||
try: | ||
url = f"asset-liability/matrix/{0 if mode is None else mode}/{0 if perp_market_index is None else perp_market_index}" | ||
result = api2(url) | ||
if "result" in result and result["result"] == "miss": | ||
st.write("Fetching data for the first time...") | ||
st.image( | ||
"https://i.gifer.com/origin/8a/8a47f769c400b0b7d81a8f6f8e09a44a_w200.gif" | ||
) | ||
st.write("Check again in one minute!") | ||
st.stop() | ||
|
||
except Exception as e: | ||
if type(e) == JSONDecodeError: | ||
print("HIT A JSONDecodeError...", e) | ||
st.write("Fetching data for the first time...") | ||
st.image( | ||
"https://i.gifer.com/origin/8a/8a47f769c400b0b7d81a8f6f8e09a44a_w200.gif" | ||
) | ||
st.write("Check again in one minute!") | ||
st.stop() | ||
else: | ||
st.write(e) | ||
st.stop() | ||
|
||
res = pd.DataFrame(result["res"]) | ||
df = pd.DataFrame(result["df"]) | ||
|
||
st.write(f"{df.shape[0]} users for scenario") | ||
st.write(res) | ||
|
||
tabs = st.tabs(["FULL"] + [x.symbol for x in mainnet_spot_market_configs]) | ||
tabs[0].dataframe(df, hide_index=True) | ||
|
||
for idx, tab in enumerate(tabs[1:]): | ||
important_cols = [x for x in df.columns if "spot_" + str(idx) in x] | ||
toshow = df[["spot_asset", "net_usd_value"] + important_cols] | ||
toshow = toshow[toshow[important_cols].abs().sum(axis=1) != 0].sort_values( | ||
by="spot_" + str(idx) + "_all", ascending=False | ||
) | ||
tab.write(f"{ len(toshow)} users with this asset to cover liabilities") | ||
tab.dataframe(toshow, hide_index=True) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
from lib.api import api2 | ||
import plotly.express as px | ||
import streamlit as st | ||
|
||
from utils import fetch_result_with_retry | ||
|
||
|
||
def health_cached_page(): | ||
health_distribution = api2("health/health_distribution") | ||
largest_perp_positions = api2("health/largest_perp_positions") | ||
most_levered_positions = api2("health/most_levered_perp_positions_above_1m") | ||
largest_spot_borrows = api2("health/largest_spot_borrows") | ||
most_levered_borrows = api2("health/most_levered_spot_borrows_above_1m") | ||
|
||
print(health_distribution) | ||
|
||
fig = px.bar( | ||
health_distribution, | ||
x="Health Range", | ||
y="Counts", | ||
title="Health Distribution", | ||
hover_data={"Notional Values": ":,"}, # Custom format for notional values | ||
labels={"Counts": "Num Users", "Notional Values": "Notional Value ($)"}, | ||
) | ||
|
||
fig.update_traces( | ||
hovertemplate="<b>Health Range: %{x}</b><br>Count: %{y}<br>Notional Value: $%{customdata[0]:,.0f}<extra></extra>" | ||
) | ||
|
||
with st.container(): | ||
st.plotly_chart(fig, use_container_width=True) | ||
|
||
perp_col, spot_col = st.columns([1, 1]) | ||
|
||
with perp_col: | ||
st.markdown("### **Largest perp positions:**") | ||
st.dataframe(largest_perp_positions, hide_index=True) | ||
st.markdown("### **Most levered perp positions > $1m:**") | ||
st.dataframe(most_levered_positions, hide_index=True) | ||
|
||
with spot_col: | ||
st.markdown("### **Largest spot borrows:**") | ||
st.dataframe(largest_spot_borrows, hide_index=True) | ||
st.markdown("### **Most levered spot borrows > $750k:**") | ||
st.dataframe(most_levered_borrows, hide_index=True) |
Oops, something went wrong.