Skip to content

Fix Streamlit segment mismatches, ExchangeTimingData error, and expiry-day failure in live depth USDINR#142

Open
svishi wants to merge 2 commits intomasterfrom
fix/streamlit-exchange-timing-segment-errors
Open

Fix Streamlit segment mismatches, ExchangeTimingData error, and expiry-day failure in live depth USDINR#142
svishi wants to merge 2 commits intomasterfrom
fix/streamlit-exchange-timing-segment-errors

Conversation

@svishi
Copy link
Copy Markdown
Contributor

@svishi svishi commented Mar 27, 2026

Summary

  • ExchangeTimingData AttributeError (Market Holidays): open_exchanges
    returns SDK objects, not dicts. Replaced the combined getattr/e.get()
    one-liner with explicit isinstance checks for str, dict, and object
    types.

  • MCX Crude Spread returns 0 results: get_futures_sorted() hardcoded
    segments="FO" (NSE equity), but MCX commodity futures live in "COMM".
    Added a segment parameter to get_futures_sorted() (default "FO" for
    backward 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". Passed segment="CURR" for
    both 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 segment
value, while the Streamlit app used the shared helper get_futures_sorted()
which had the segment hardcoded to "FO".

Files changed

  • interactive_examples/utils.py — added segment param to get_futures_sorted()
  • interactive_examples/streamlit_app.py — passed correct segments for MCX and currency; fixed ExchangeTimingData isinstance handling
  • interactive_examples/market_data/live_depth_usdinr.py — removed expiry="current_month" filter

Test plan

  • Market Holidays loads without AttributeError
  • MCX Crude Spread with CRUDEOIL returns near/far contracts
  • Currency Futures Spread with USDINR returns near/far contracts
  • live_depth_usdinr.py resolves contracts successfully on and around expiry day

svishi added 2 commits March 27, 2026 10:12
…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
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.

2 participants