Skip to content

Conversation

@parva2612
Copy link

This PR introduces a complete refactor of the contract master download and instrument lookup logic to enhance efficiency, maintainability, and performance.

Key Improvements:

Centralized Master Contract Download:

  • Unified function download_master_contract() downloads and consolidates data across all exchanges.
  • Optional CSV export for persistence or debugging.

Optimized In-Memory Filtering:

  • Contract data is stored in-memory using pandas.DataFrame, eliminating repeated file I/O operations.
  • Fast and efficient lookup using pre-indexed dataframes (master_contract_df_symbol and master_contract_df_token).

Cleaned and Standardized Data:

  • Normalized column names and structure across all exchanges.
  • Expiry dates parsed and numeric fields (instrument_token, strike, lot_size) cast to correct types.
  • Dropped duplicates and null rows to ensure data consistency.

Improved Instrument Retrieval:

  • Simplified and optimized:
    • get_instrument_by_symbol()
    • get_instrument_by_token()
    • get_instrument_for_fno()
  • Enhanced validation (e.g., expiry presence, correct strike type).
  • Handles multiple instruments gracefully when applicable.

Backward Compatibility:

  • Returns Instrument objects consistent with the previous implementation.
  • Ensures compatibility with existing systems while improving overall structure.

Let me know if you'd like to include benchmarks, unit tests, or additional documentation updates before merging.

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.

1 participant