Conversation
…ncy futures in Streamlit Three bugs caused Streamlit examples to fail while CLI equivalents worked fine: 1. ExchangeTimingData AttributeError (Market Holidays) ExchangeTimingData objects were being treated as dicts. Replaced the combined getattr/e.get() one-liner with explicit isinstance checks for str, dict, and object types. 2. MCX Crude Spread returned 0 results get_futures_sorted() hardcoded segments="FO" (NSE equity), but MCX commodity futures live in the "COMM" segment. Added a `segment` parameter to get_futures_sorted() (default "FO" for backward compatibility) and passed segment="COMM" for the MCX call. 3. Currency Futures Spread returned 0 results Same issue — currency futures use segments="CURR", not "FO". Passed segment="CURR" for both NSE and BSE fallback calls. Root cause in all cases: CLI scripts called search_instrument() directly with the correct segment, while the Streamlit app used the shared helper get_futures_sorted() which had the segment hardcoded to "FO".
Added current month expiry
upstox-security-review
approved these changes
Mar 27, 2026
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
ExchangeTimingData AttributeError (Market Holidays):
open_exchangesreturns SDK objects, not dicts. Replaced the combined
getattr/e.get()one-liner with explicit
isinstancechecks forstr,dict, and objecttypes.
MCX Crude Spread returns 0 results:
get_futures_sorted()hardcodedsegments="FO"(NSE equity), but MCX commodity futures live in"COMM".Added a
segmentparameter toget_futures_sorted()(default"FO"forbackward compatibility) and passed
segment="COMM"for the MCX call.Currency Futures Spread returns 0 results: Same root cause — currency
futures use
segments="CURR", not"FO". Passedsegment="CURR"forboth the NSE and BSE fallback calls in Streamlit.
live_depth_usdinr.py fails on expiry day: The
expiry="current_month"filter returns no results on or after the contract's expiry date. Removed
the filter so all available contracts are fetched, and the existing
sort-by-expiry logic picks the nearest active contract automatically.
Root cause (MCX / Currency)
CLI scripts called
search_instrument()directly with the correct segmentvalue, while the Streamlit app used the shared helper
get_futures_sorted()which had the segment hardcoded to
"FO".Files changed
interactive_examples/utils.py— addedsegmentparam toget_futures_sorted()interactive_examples/streamlit_app.py— passed correct segments for MCX and currency; fixedExchangeTimingDataisinstance handlinginteractive_examples/market_data/live_depth_usdinr.py— removedexpiry="current_month"filterTest plan
AttributeErrorCRUDEOILreturns near/far contractsUSDINRreturns near/far contractslive_depth_usdinr.pyresolves contracts successfully on and around expiry day