Skip to content

Commit 3fe24ca

Browse files
authored
Merge pull request #14 from drift-labs:goldhaxx/feature/market-filters-for-health-page
Enhance health page with market filtering options for perpetual and spot positions
2 parents 1521df2 + 011c301 commit 3fe24ca

File tree

1 file changed

+36
-5
lines changed

1 file changed

+36
-5
lines changed

src/page/health.py

Lines changed: 36 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -96,8 +96,11 @@ def health_page():
9696
with perp_col:
9797
st.markdown("### **Largest perp positions:**")
9898

99+
# Create a container for the filter controls
100+
perp_filter_col1, perp_filter_col2 = st.columns(2)
101+
99102
# Add number input to control how many positions to show
100-
num_positions = st.number_input(
103+
num_positions = perp_filter_col1.number_input(
101104
"Number of values to return for perp positions",
102105
min_value=10,
103106
max_value=100,
@@ -106,6 +109,18 @@ def health_page():
106109
key="num_perp_positions"
107110
)
108111

112+
# Add market index selector
113+
perp_market_options = [{"label": f"{idx} ({cfg.symbol})", "value": idx}
114+
for idx, cfg in enumerate(mainnet_perp_market_configs) if cfg is not None]
115+
perp_market_options.insert(0, {"label": "All Markets", "value": None})
116+
117+
selected_perp_market = perp_filter_col2.selectbox(
118+
"Filter by market",
119+
options=[opt["value"] for opt in perp_market_options],
120+
format_func=lambda x: next((opt["label"] for opt in perp_market_options if opt["value"] == x), "All Markets"),
121+
key="perp_market_filter"
122+
)
123+
109124
# Add bypass cache toggle when in debug mode
110125
bypass_cache = False
111126
if debug_mode:
@@ -121,6 +136,7 @@ def health_page():
121136
"largest_perp_positions",
122137
params={
123138
"number_of_positions": num_positions,
139+
"market_index": selected_perp_market,
124140
"bypass_cache": "true" if bypass_cache else "false"
125141
},
126142
retry=True,
@@ -163,7 +179,7 @@ def health_page():
163179
"most_levered_perp_positions_above_1m",
164180
params={
165181
"number_of_positions": num_positions,
166-
"market_index": None
182+
"market_index": selected_perp_market
167183
},
168184
retry=True,
169185
)
@@ -204,8 +220,11 @@ def health_page():
204220

205221
with spot_col:
206222
st.markdown("### **Largest spot borrows:**")
223+
# Create a container for the spot filter controls
224+
spot_filter_col1, spot_filter_col2 = st.columns(2)
225+
207226
# Add number input to control how many positions to show
208-
spot_num_positions = st.number_input(
227+
spot_num_positions = spot_filter_col1.number_input(
209228
"Number of values to return for spot borrows",
210229
min_value=10,
211230
max_value=100,
@@ -214,6 +233,18 @@ def health_page():
214233
key="num_spot_positions"
215234
)
216235

236+
# Add market index selector for spot markets
237+
spot_market_options = [{"label": f"{idx} ({cfg.symbol})", "value": idx}
238+
for idx, cfg in enumerate(mainnet_spot_market_configs) if cfg is not None]
239+
spot_market_options.insert(0, {"label": "All Markets", "value": None})
240+
241+
selected_spot_market = spot_filter_col2.selectbox(
242+
"Filter by market",
243+
options=[opt["value"] for opt in spot_market_options],
244+
format_func=lambda x: next((opt["label"] for opt in spot_market_options if opt["value"] == x), "All Markets"),
245+
key="spot_market_filter"
246+
)
247+
217248
# Add bypass cache toggle when in debug mode
218249
spot_bypass_cache = False
219250
if debug_mode:
@@ -229,7 +260,7 @@ def health_page():
229260
"largest_spot_borrows",
230261
params={
231262
"number_of_positions": spot_num_positions,
232-
"market_index": None,
263+
"market_index": selected_spot_market,
233264
"bypass_cache": "true" if spot_bypass_cache else "false"
234265
},
235266
retry=True,
@@ -273,7 +304,7 @@ def health_page():
273304
"most_levered_spot_borrows_above_1m",
274305
params={
275306
"number_of_positions": spot_num_positions,
276-
"market_index": None
307+
"market_index": selected_spot_market
277308
},
278309
retry=True,
279310
)

0 commit comments

Comments
 (0)