Skip to content

Commit

Permalink
Add loading screen
Browse files Browse the repository at this point in the history
  • Loading branch information
SinaKhalili committed Oct 14, 2024
1 parent 72ec657 commit 1a8dbb6
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 17 deletions.
49 changes: 35 additions & 14 deletions src/page/asset_liability.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,23 +15,44 @@


def asset_liab_matrix_page():
mode = st.selectbox("Options", options, format_func=lambda x: labels[x])
if mode is None:
mode = 0
params = st.query_params
mode = int(params.get("mode", 0))
perp_market_index = int(params.get("perp_market_index", 0))

perp_market_index = st.selectbox(
"Market index", [x.market_index for x in mainnet_perp_market_configs]
mode = st.selectbox(
"Options", options, format_func=lambda x: labels[x], index=options.index(mode)
)
if perp_market_index is None:
perp_market_index = 0

result = api(
"asset-liability",
"matrix",
"0" if mode is None else str(mode),
"0" if perp_market_index is None else str(perp_market_index),
as_json=True,
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:
result = api(
"asset-liability",
"matrix",
"0" if mode is None else str(mode),
"0" if perp_market_index is None else str(perp_market_index),
as_json=True,
)
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:
st.write(e)
st.stop()

res = pd.DataFrame(result["res"])
df = pd.DataFrame(result["df"])

Expand Down
24 changes: 21 additions & 3 deletions src/page/price_shock.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,13 @@ def price_shock_plot(user_leverages, oracle_distort: float):


def price_shock_page():
# Get query parameters
params = st.query_params
print(params, "params")

cov = params.get("cov", "ignore stables")
oracle_distort = float(params.get("oracle_distort", 0.05))

cov_col, distort_col = st.columns(2)
cov = cov_col.selectbox(
"covariance:",
Expand All @@ -106,16 +113,19 @@ def price_shock_page():
"sol + lst only",
"meme",
],
index=0,
index=["ignore stables", "sol + lst only", "meme"].index(cov),
)

oracle_distort = distort_col.selectbox(
"oracle distortion:",
[0.05, 0.1, 0.2, 0.5, 1],
index=0,
index=[0.05, 0.1, 0.2, 0.5, 1].index(oracle_distort),
help="step size of oracle distortions",
)

# Update query parameters
st.query_params.update({"cov": cov, "oracle_distort": oracle_distort})

result = api(
"price-shock",
"usermap",
Expand All @@ -126,7 +136,15 @@ def price_shock_page():
},
as_json=True,
)
st.write(result)
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()

# st.write(result)

fig = price_shock_plot(result, oracle_distort)
st.plotly_chart(fig)
Expand Down

0 comments on commit 1a8dbb6

Please sign in to comment.