Class: Bberg::Requests::HistoricalDataRequest
- Inherits:
-
RefdataRequestBase
- Object
- RefdataRequestBase
- Bberg::Requests::HistoricalDataRequest
- Defined in:
- lib/bberg/requests/historical_data_request.rb
Overview
A class for preforming historical data requets.
Constant Summary collapse
- DEFAULT_OPTIONS =
Hash[ :fields => ["PX_SETTLE"]
Instance Method Summary collapse
-
#create_request ⇒ Object
Create a historical data request.
-
#initialize(session_options, identifiers, start_time, end_time, options_arg = {}) ⇒ HistoricalDataRequest
constructor
Create new instance.
-
#parse_response(event) ⇒ Hash
Parse event for HistoricalDataResponse.
Methods inherited from RefdataRequestBase
#convert_to_rb_date, #convert_to_rb_time, #convert_value_to_bberg, #create_ref_data_service, #get_correlation_id, #hash_merge_concat, #perform_request, #retrieve_response
Constructor Details
#initialize(session_options, identifiers, start_time, end_time, options_arg = {}) ⇒ HistoricalDataRequest
Create new instance.
21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/bberg/requests/historical_data_request.rb', line 21 def initialize(, identifiers, start_time, end_time, = {}) @session_options = @identifiers = unless identifiers.respond_to? 'each' [identifiers] else identifiers end @start_time = start_time @end_time = end_time @options = DEFAULT_OPTIONS.merge() end |
Instance Method Details
#create_request ⇒ Object
Create a historical data request.
37 38 39 40 41 42 43 44 45 46 |
# File 'lib/bberg/requests/historical_data_request.rb', line 37 def create_request request = @svc.createRequest("HistoricalDataRequest") request.set("startDate", @start_time.strftime("%Y%m%d")) request.set("endDate", @end_time.strftime("%Y%m%d")) request.set("periodicitySelection", @options[:frequency]) request.set("returnEids", false) @identifiers.each {|identifier| request.append("securities", identifier) } @options[:fields].each {|f| request.append("fields", f) } @request = request end |
#parse_response(event) ⇒ Hash
Parse event for HistoricalDataResponse.
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/bberg/requests/historical_data_request.rb', line 50 def parse_response(event) iter = event.() result = Hash.new while iter.hasNext() = iter.next() raise Bberg::BbergException.new("Got a response with incorrect correlation id!") if .correlationID != @req_id msg_type = .().toString() raise Bberg::BbergException.new("Expected message of type HistoricalDataResponse but got #{msg_type}") if msg_type != "HistoricalDataResponse" field_data = .getElement("securityData").getElement("fieldData") security_name = .getElement("securityData").getElementAsString("security") result[security_name] ||= [] (0..(field_data.numValues - 1)).each do |field_num| field_values = get_field_values(field_data, field_num) result[security_name] << field_values end end result end |