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
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
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
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
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
@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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
See {#use_compression}. @param [Boolean] value @return [void]
# File lib/oanda_api/configuration.rb, line 168 def use_compression=(value) @use_compression = !!value end
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
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