diff --git a/src/page/asset_liability.py b/src/page/asset_liability.py index 15ffed8..5423df1 100644 --- a/src/page/asset_liability.py +++ b/src/page/asset_liability.py @@ -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"]) diff --git a/src/page/price_shock.py b/src/page/price_shock.py index f89f541..8b4477d 100644 --- a/src/page/price_shock.py +++ b/src/page/price_shock.py @@ -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:", @@ -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", @@ -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)