class OandaAPI::Configuration

Configures client API settings.

Constants

CONNECTION_POOL_SIZE
DATETIME_FORMAT
LABS_API_VERSION
MAX_NEW_CONNECTIONS_PER_SECOND
MAX_REQUESTS_PER_SECOND
OPEN_TIMEOUT
READ_TIMEOUT
REST_API_VERSION
USE_COMPRESSION
USE_REQUEST_THROTTLING

Public Instance Methods

connection_pool_size() click to toggle source

Maximum size of the persistent connection pool. @return [Numeric]

# File lib/oanda_api/configuration.rb, line 19
def connection_pool_size
  @connection_pool_size ||= CONNECTION_POOL_SIZE
end
connection_pool_size=(value) click to toggle source

Define the maximum size of the persistent connection pool. @return [Numeric]

# File lib/oanda_api/configuration.rb, line 25
def connection_pool_size=(value)
  fail ArgumentError, "must be a number > 0" unless value.is_a?(Numeric) && value > 0
  @connection_pool_size = value
end
datetime_format() click to toggle source

The format in which dates will be returned by the API (`:rfc3339` or `:unix`).

See the Oanda Development Guide for more details about {http://developer.oanda.com/rest-live/development-guide/#date_Time_Format DateTime formats}.

@return [Symbol]

# File lib/oanda_api/configuration.rb, line 33
def datetime_format
  @datetime_format ||= DATETIME_FORMAT
end
datetime_format=(value) click to toggle source

See {#datetime_format}. @param [Symbol] value @return [void]

# File lib/oanda_api/configuration.rb, line 40
def datetime_format=(value)
  fail ArgumentError, "Invalid datetime format" unless OandaAPI::DATETIME_FORMATS.include? value
  @datetime_format = value
end
headers() click to toggle source

@private @return [Hash] headers that are set on every request as a result of

configuration settings.
# File lib/oanda_api/configuration.rb, line 201
def headers
  h = {}
  h["X-Accept-Datetime-Format"] = datetime_format.to_s.upcase
  h["Accept-Encoding"] = "deflate, gzip" if use_compression?
  h
end
labs_api_version() click to toggle source

The Oanda Labs API version used by the client. @return [String]

# File lib/oanda_api/configuration.rb, line 47
def labs_api_version
  @labs_api_version ||= LABS_API_VERSION
end
labs_api_version=(value) click to toggle source

See {#labs_api_version}. @param [String] value @return [void]

# File lib/oanda_api/configuration.rb, line 54
def labs_api_version=(value)
  @labs_api_version = value
end
max_new_connections_per_second() click to toggle source

The maximum number of new connections per second allowed to be made

to the API. Only enforced if {#use_request_throttling?} is `true`.

@return [Numeric]

# File lib/oanda_api/configuration.rb, line 62
def max_new_connections_per_second
  @max_new_connections_per_second ||= MAX_NEW_CONNECTIONS_PER_SECOND
end
max_new_connections_per_second=(value) click to toggle source

See {#max_new_connections_per_second}. @param [Numeric] value @return [void]

# File lib/oanda_api/configuration.rb, line 69
def max_new_connections_per_second=(value)
  fail ArgumentError, "must be a number > 0" unless value.is_a?(Numeric) && value > 0
  @min_new_connection_interval = nil
  @max_new_connections_per_second = value
end
max_requests_per_second() click to toggle source

The maximum number of requests per second allowed to be made through the

API. Only enforced if {#use_request_throttling?} is `true`.

@return [Numeric]

# File lib/oanda_api/configuration.rb, line 88
def max_requests_per_second
  @max_requests_per_second ||= MAX_REQUESTS_PER_SECOND
end
max_requests_per_second=(value) click to toggle source

See {#max_requests_per_second}. @param [Numeric] value @return [void]

# File lib/oanda_api/configuration.rb, line 95
def max_requests_per_second=(value)
  fail ArgumentError, "must be a number > 0" unless value.is_a?(Numeric) && value > 0
  @min_request_interval = nil
  @max_requests_per_second = value
end
min_new_connection_interval() click to toggle source

The minimum amount of time in seconds that must elapse between

new connection attempts to the API.
Determined by {#max_new_connections_per_second}. Only enforced if
{#use_request_throttling?} is `true`.

@return [Float]

# File lib/oanda_api/configuration.rb, line 80
def min_new_connection_interval
  @min_new_connection_interval ||= (1.0 / max_new_connections_per_second)
end
min_request_interval() click to toggle source

The minimum amount of time in seconds that must elapse between

consecutive requests to the API. Determined by
{#max_requests_per_second}. Only enforced if {#use_request_throttling?}
 is `true`.

@return [Float]

# File lib/oanda_api/configuration.rb, line 106
def min_request_interval
  @min_request_interval ||= (1.0 / max_requests_per_second)
end
open_timeout() click to toggle source

The number of seconds the client waits for a new HTTP connection to be

established before raising a timeout exception.

@return [Numeric]

# File lib/oanda_api/configuration.rb, line 113
def open_timeout
  @open_timeout ||= OPEN_TIMEOUT
end
open_timeout=(value) click to toggle source

See {#open_timeout}. @param [Numeric] value @return [void]

# File lib/oanda_api/configuration.rb, line 120
def open_timeout=(value)
  fail ArgumentError, "must be an integer or float" unless value && (value.is_a?(Integer) || value.is_a?(Float))
  @open_timeout = value
end
read_timeout() click to toggle source

The number of seconds the client waits for a response from the API before

raising a timeout exception.

@return [Numeric]

# File lib/oanda_api/configuration.rb, line 128
def read_timeout
  @read_timeout ||= READ_TIMEOUT
end
read_timeout=(value) click to toggle source

See {#read_timeout}. @param [Numeric] value @return [void]

# File lib/oanda_api/configuration.rb, line 135
def read_timeout=(value)
  fail ArgumentError, "must be an integer or float" unless value && (value.is_a?(Integer) || value.is_a?(Float))
  @read_timeout = value
end
rest_api_version() click to toggle source

The Oanda REST API version used by the client. @return [String]

# File lib/oanda_api/configuration.rb, line 142
def rest_api_version
  @rest_api_version ||= REST_API_VERSION
end
rest_api_version=(value) click to toggle source

See {#rest_api_version}. @param [String] value @return [void]

# File lib/oanda_api/configuration.rb, line 149
def rest_api_version=(value)
  @rest_api_version = value
end
use_compression() click to toggle source

Specifies whether the API uses compressed responses. See the Oanda

Development Guide for more information about
{http://developer.oanda.com/rest-live/best-practices/#compression compression}.

@return [Boolean]

# File lib/oanda_api/configuration.rb, line 158
def use_compression
  @use_compression = USE_COMPRESSION if @use_compression.nil?
  @use_compression
end
Also aliased as: use_compression?
use_compression=(value) click to toggle source

See {#use_compression}. @param [Boolean] value @return [void]

# File lib/oanda_api/configuration.rb, line 168
def use_compression=(value)
  @use_compression = !!value
end
use_compression?()
Alias for: use_compression
use_request_throttling() click to toggle source

Throttles the rate of requests made to the API. See the Oanda Developers

Guide for information about
{http://developer.oanda.com/rest-live/best-practices/ connection limits}.
If enabled, requests will not exceed {#max_requests_per_second}. If the
rate of requests received by the client exceeds this limit, the client
delays the rate-exceeding request for the minimum amount of time needed
to satisfy the rate limit.

@return [Boolean]

# File lib/oanda_api/configuration.rb, line 181
def use_request_throttling
  @use_request_throttling = USE_REQUEST_THROTTLING if @use_request_throttling.nil?
  @use_request_throttling
end
Also aliased as: use_request_throttling?
use_request_throttling=(value) click to toggle source

See {#use_request_throttling}. @param [Boolean] value @return [void]

# File lib/oanda_api/configuration.rb, line 191
def use_request_throttling=(value)
  @use_request_throttling = !!value
  #
  # See OandaAPI::Throttling
  Net::HTTP.limit_connection_rate !!value
end
use_request_throttling?()