Class: Bberg::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/bberg/client.rb

Overview

Main class for making synchronous bberg data requests.

Instance Method Summary collapse

Constructor Details

#initialize(host = "localhost", port = 8194) ⇒ Client

Create a new instance of Client

Parameters:

  • host (String) (defaults to: "localhost")

    host running bberg we want to connect to

  • port (Fixnum) (defaults to: 8194)

    port to connect to



13
14
15
16
17
# File 'lib/bberg/client.rb', line 13

def initialize(host = "localhost", port = 8194)
  @session_options = Bberg::Native::SessionOptions.new
  @session_options.setServerHost("localhost")
  @session_options.setServerPort(8194)
end

Instance Method Details

#get_holidays_for_calendar(currency, calendar, start_date, end_date) ⇒ Array

Convencience method to perform a reference data request for holiday calendar data.

Parameters:

  • currency (String)

    which settlement currency to use for calendar.

  • calendar (String)

    name of calendar.

  • start_date (Date|Time)

    when to start calendar from.

  • end_date (Date|Time)

    when to end calendar.

Returns:

  • (Array)

    an array of Dates.



45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/bberg/client.rb', line 45

def get_holidays_for_calendar(currency, calendar, start_date, end_date)
  overrides = Hash[
    "CALENDAR_START_DATE", start_date,
    "CALENDAR_END_DATE", end_date
  ]
  overrides["SETTLEMENT_CALENDAR_CODE"] = calendar unless calendar.nil?
  options = Hash[ :fields => ["CALENDAR_HOLIDAYS"]]
  options[:overrides] = overrides
  
  response = self.reference_data_request(currency, options)
  result = response[currency]["CALENDAR_HOLIDAYS"].map {|o| o["Holiday Date"]}
  result
end

#historical_data_request(identifiers, start_time, end_time, options = {}) ⇒ Hash

Perform a historical data request.

Parameters:

  • identifiers (#each|String)

    a list of identifiers for this request

  • start_time (Time)

    start of historical range

  • end_time (Time)

    end of historical range

  • options_arg (Hash)

    specification of what fields or other parameters to use for the request.

Returns:

  • (Hash)

    result in Hash format.



25
26
27
28
# File 'lib/bberg/client.rb', line 25

def historical_data_request(identifiers, start_time, end_time, options = {})
  request = Bberg::Requests::HistoricalDataRequest.new(@session_options, identifiers, start_time, end_time, options)
  request.perform_request
end

#reference_data_request(identifiers, options) ⇒ Hash

Perform a reference data request.

Parameters:

  • identifiers (#each|String)

    a list of identifiers for this request

  • options_arg (Hash)

    specification of what fields or other parameters to use for the request.

Returns:

  • (Hash)

    result in Hash format.



34
35
36
37
# File 'lib/bberg/client.rb', line 34

def reference_data_request(identifiers, options)
  request = Bberg::Requests::ReferenceDataRequest.new(@session_options, identifiers, options)
  request.perform_request
end