Skip to content

Fix ExchangeTimingData AttributeError and wrong segment for MCX/curre…#141

Merged
elninad merged 1 commit intomasterfrom
fix/streamlit-exchange-timing-segment-errors
Mar 27, 2026
Merged

Fix ExchangeTimingData AttributeError and wrong segment for MCX/curre…#141
elninad merged 1 commit intomasterfrom
fix/streamlit-exchange-timing-segment-errors

Conversation

@svishi
Copy link
Contributor

@svishi svishi commented Mar 27, 2026

…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".

…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".
@elninad elninad merged commit 6c3a3d8 into master Mar 27, 2026
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants