diff --git a/interactive_examples/streamlit_app.py b/interactive_examples/streamlit_app.py index 708a4e4..c181441 100644 --- a/interactive_examples/streamlit_app.py +++ b/interactive_examples/streamlit_app.py @@ -324,7 +324,7 @@ def contango_label(spread): c1, c2, c3 = st.columns([2, 1, 1]) query = c1.text_input("Search query", value="NIFTY") exch = c2.selectbox("Exchange", ["NSE", "BSE", "MCX"]) - exact = c3.checkbox("Exact underlying match", value=True, + exact = c3.checkbox("Exact underlying match", value=False, help="Filter strictly by underlying_symbol to avoid e.g. NIFTYNXT50 when searching NIFTY") if st.button("🔍 Search", type="primary"): diff --git a/interactive_examples/utils.py b/interactive_examples/utils.py index 128b542..d45cb28 100644 --- a/interactive_examples/utils.py +++ b/interactive_examples/utils.py @@ -161,7 +161,7 @@ def get_futures_sorted( query: str, exchange: str = "NSE", exact_symbol: bool = False, - segment: str = "FO", + segment: str = None, ): """ Search for futures contracts and return them sorted by expiry (nearest first). @@ -170,12 +170,16 @@ def get_futures_sorted( matches *query* (case-insensitive) are returned — useful when searching 'NIFTY' to avoid picking up NIFTYNXT50, BANKNIFTY, etc. - Use segment="COMM" for MCX commodity futures (e.g. CRUDEOIL, NATURALGAS). - Use segment="FO" (default) for NSE/BSE equity futures. + The segment is derived from *exchange* when not given explicitly: + MCX commodities (e.g. CRUDEOIL, NATURALGAS) use "COMM"; NSE/BSE equity + futures use "FO". Pass segment explicitly to override (e.g. "CURR" for + currency futures on NSE/BSE). Returns list of instrument dicts, each with keys like: instrument_key, trading_symbol, expiry, lot_size, underlying_symbol """ + if segment is None: + segment = "COMM" if exchange.upper() == "MCX" else "FO" response = search_instrument( api_client, query,