Class: DhanHQ::Models::HistoricalData
- Defined in:
- lib/DhanHQ/models/historical_data.rb
Overview
For intraday data, only 90 days of data can be polled at once for any time interval. It is recommended to store this data locally for day-to-day analysis.
Model for fetching historical candle data (OHLC) for desired instruments across segments and exchanges.
This API provides historical price data in the form of candlestick data with timestamp, open, high, low, close, and volume information. Data is available in two formats:
- Daily: Daily candle data available back to the date of instrument inception
- Intraday: Minute-level candle data (1, 5, 15, 25, 60 minutes) available for the last 5 years
Constant Summary collapse
- HTTP_PATH =
Base path for historical data endpoints.
"/v2/charts"
Constants included from ResponseHelper
ResponseHelper::STATUS_ERROR_FALLBACK
Instance Attribute Summary
Attributes inherited from BaseModel
Class Method Summary collapse
-
.daily(params) ⇒ HashWithIndifferentAccess{Symbol => Array<Float, Integer>}
Fetches daily OHLC (Open, High, Low, Close) and volume data for the desired instrument.
-
.intraday(params) ⇒ HashWithIndifferentAccess{Symbol => Array<Float, Integer>}
Fetches intraday OHLC (Open, High, Low, Close) and volume data for minute-level timeframes.
-
.resource ⇒ DhanHQ::Resources::HistoricalData
Provides a shared instance of the HistoricalData resource.
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, validation_contract, #validation_contract, 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
.daily(params) ⇒ HashWithIndifferentAccess{Symbol => Array<Float, Integer>}
Fetches daily OHLC (Open, High, Low, Close) and volume data for the desired instrument.
Retrieves daily candle data for any scrip available back to the date of its inception. The data is returned as arrays where each index corresponds to a single trading day.
102 103 104 105 106 |
# File 'lib/DhanHQ/models/historical_data.rb', line 102 def daily(params) validated_params = validate_params!(params, DhanHQ::Contracts::HistoricalDataContract) response = resource.daily(validated_params) normalize(response) end |
.intraday(params) ⇒ HashWithIndifferentAccess{Symbol => Array<Float, Integer>}
Maximum 90 days of data can be fetched in a single request. For longer periods, make multiple requests or store data locally for analysis.
Fetches intraday OHLC (Open, High, Low, Close) and volume data for minute-level timeframes.
Retrieves minute-level candle data (1, 5, 15, 25, or 60 minutes) for desired instruments. Data is available for the last 5 years for all exchanges and segments for all active instruments.
Important: Only 90 days of data can be polled at once for any of the time intervals. It is recommended that you store this data locally for day-to-day analysis.
180 181 182 183 184 |
# File 'lib/DhanHQ/models/historical_data.rb', line 180 def intraday(params) validated_params = validate_params!(params, DhanHQ::Contracts::IntradayHistoricalDataContract) response = resource.intraday(validated_params) normalize(response) end |
.resource ⇒ DhanHQ::Resources::HistoricalData
Provides a shared instance of the HistoricalData resource.
46 47 48 |
# File 'lib/DhanHQ/models/historical_data.rb', line 46 def resource @resource ||= DhanHQ::Resources::HistoricalData.new end |