Class: DhanHQ::Models::OptionChain
- Defined in:
- lib/DhanHQ/models/option_chain.rb
Overview
Rate Limits: You can call the Option Chain API once every 3 seconds. This rate limit is enforced because OI data updates slowly compared to LTP or other data parameters. The client's internal rate limiter automatically throttles calls to prevent exceeding limits.
Data Filtering: The model automatically filters out strikes where both
Call (CE) and Put (PE) options have zero last_price, keeping the payload compact
and focused on actively traded strikes.
Model for fetching option chain data for any option instrument across exchanges.
The Option Chain API provides the entire option chain for any underlying instrument across NSE, BSE, and MCX exchanges. For each strike price, you get Open Interest (OI), Greeks (Delta, Theta, Gamma, Vega), Volume, Last Traded Price, Best Bid/Ask prices, Implied Volatility (IV), and other option analytics.
Constant Summary
Constants included from ResponseHelper
ResponseHelper::STATUS_ERROR_FALLBACK
Instance Attribute Summary
Attributes inherited from BaseModel
Class Method Summary collapse
-
.fetch(params) ⇒ HashWithIndifferentAccess
Fetches the entire option chain for a specified underlying instrument and expiry.
-
.fetch_expiry_list(params) ⇒ Array<String>
(also: expiry_list)
Fetches the list of active expiry dates for an underlying instrument.
-
.resource ⇒ DhanHQ::Resources::OptionChain
Provides a shared instance of the OptionChain resource.
- .validation_contract ⇒ Object
Instance Method Summary collapse
Methods inherited from BaseModel
all, api, api_type, #assign_attributes, attributes, create, #delete, #destroy, find, #id, #initialize, #new_record?, #optionchain_api?, parse_collection_response, #persisted?, resource_path, #save, #save!, #to_request_params, #update, #valid?, validate_attributes, where
Methods included from APIHelper
Methods included from AttributeHelper
#camelize_keys, #inspect, #normalize_keys, #snake_case, #titleize_keys
Methods included from ValidationHelper
#valid?, #validate!, #validate_params!
Methods included from RequestHelper
Constructor Details
This class inherits a constructor from DhanHQ::BaseModel
Class Method Details
.fetch(params) ⇒ HashWithIndifferentAccess
Fetches the entire option chain for a specified underlying instrument and expiry.
Retrieves real-time option chain data across all strikes for the given underlying. The response includes Open Interest (OI), Greeks, Volume, Last Traded Price, Best Bid/Ask prices, Implied Volatility (IV), and other option analytics for both Call (CE) and Put (PE) options at each strike price.
92 93 94 95 96 97 98 99 |
# File 'lib/DhanHQ/models/option_chain.rb', line 92 def fetch(params) validate_params!(params, DhanHQ::Contracts::OptionChainContract) response = resource.fetch(params) return {}.with_indifferent_access unless response[:status] == "success" normalize_chain(response[:data]).with_indifferent_access end |
.fetch_expiry_list(params) ⇒ Array<String> Also known as: expiry_list
Fetches the list of active expiry dates for an underlying instrument.
109 110 111 112 113 114 |
# File 'lib/DhanHQ/models/option_chain.rb', line 109 def fetch_expiry_list(params) validate_params!(params, DhanHQ::Contracts::OptionChainExpiryListContract) response = resource.expirylist(params) response[:status] == "success" ? response[:data] : [] end |
.resource ⇒ DhanHQ::Resources::OptionChain
Provides a shared instance of the OptionChain resource.
62 63 64 |
# File 'lib/DhanHQ/models/option_chain.rb', line 62 def resource @resource ||= DhanHQ::Resources::OptionChain.new end |
.validation_contract ⇒ Object
66 67 68 |
# File 'lib/DhanHQ/models/option_chain.rb', line 66 def validation_contract @validation_contract ||= DhanHQ::Contracts::OptionChainContract.new end |
Instance Method Details
#validation_contract ⇒ Object
53 54 55 |
# File 'lib/DhanHQ/models/option_chain.rb', line 53 def validation_contract self.class.validation_contract end |