Class: OandaAPI::Configuration
- Inherits:
-
Object
- Object
- OandaAPI::Configuration
- Defined in:
- lib/oanda_api/configuration.rb
Overview
Configures client API settings.
Constant Summary collapse
- DATETIME_FORMAT =
:rfc3339
- LABS_API_VERSION =
"labs/v1"
- MAX_NEW_CONNECTIONS_PER_SECOND =
2
- MAX_REQUESTS_PER_SECOND =
15
- OPEN_TIMEOUT =
10
- READ_TIMEOUT =
10
- REST_API_VERSION =
"v1"
- USE_COMPRESSION =
false
- USE_REQUEST_THROTTLING =
false
- CONNECTION_POOL_SIZE =
2
Instance Method Summary collapse
-
#connection_pool_size ⇒ Numeric
Maximum size of the persistent connection pool.
-
#connection_pool_size=(value) ⇒ Numeric
Define the maximum size of the persistent connection pool.
-
#datetime_format ⇒ Symbol
The format in which dates will be returned by the API (
:rfc3339
or:unix
). -
#datetime_format=(value) ⇒ void
See #datetime_format.
-
#headers ⇒ Hash
Headers that are set on every request as a result of configuration settings.
-
#labs_api_version ⇒ String
The Oanda Labs API version used by the client.
-
#labs_api_version=(value) ⇒ void
See #labs_api_version.
-
#max_new_connections_per_second ⇒ Numeric
The maximum number of new connections per second allowed to be made to the API.
- #max_new_connections_per_second=(value) ⇒ void
-
#max_requests_per_second ⇒ Numeric
The maximum number of requests per second allowed to be made through the API.
- #max_requests_per_second=(value) ⇒ void
-
#min_new_connection_interval ⇒ Float
The minimum amount of time in seconds that must elapse between new connection attempts to the API.
-
#min_request_interval ⇒ Float
The minimum amount of time in seconds that must elapse between consecutive requests to the API.
-
#open_timeout ⇒ Numeric
The number of seconds the client waits for a new HTTP connection to be established before raising a timeout exception.
-
#open_timeout=(value) ⇒ void
See #open_timeout.
-
#read_timeout ⇒ Numeric
The number of seconds the client waits for a response from the API before raising a timeout exception.
-
#read_timeout=(value) ⇒ void
See #read_timeout.
-
#rest_api_version ⇒ String
The Oanda REST API version used by the client.
-
#rest_api_version=(value) ⇒ void
See #rest_api_version.
-
#use_compression ⇒ Boolean
(also: #use_compression?)
Specifies whether the API uses compressed responses.
-
#use_compression=(value) ⇒ void
See #use_compression.
-
#use_request_throttling ⇒ Boolean
(also: #use_request_throttling?)
Throttles the rate of requests made to the API.
- #use_request_throttling=(value) ⇒ void
Instance Method Details
#connection_pool_size ⇒ Numeric
Maximum size of the persistent connection pool.
19 20 21 |
# File 'lib/oanda_api/configuration.rb', line 19 def connection_pool_size @connection_pool_size ||= CONNECTION_POOL_SIZE end |
#connection_pool_size=(value) ⇒ Numeric
Define the maximum size of the persistent connection pool.
25 26 27 28 |
# 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 ⇒ Symbol
The format in which dates will be returned by the API (:rfc3339
or :unix
).
See the Oanda Development Guide for more details about DateTime formats.
33 34 35 |
# File 'lib/oanda_api/configuration.rb', line 33 def datetime_format @datetime_format ||= DATETIME_FORMAT end |
#datetime_format=(value) ⇒ void
This method returns an undefined value.
See #datetime_format.
40 41 42 43 |
# 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 ⇒ Hash
Returns headers that are set on every request as a result of configuration settings.
201 202 203 204 205 206 |
# 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 ⇒ String
The Oanda Labs API version used by the client.
47 48 49 |
# File 'lib/oanda_api/configuration.rb', line 47 def labs_api_version @labs_api_version ||= LABS_API_VERSION end |
#labs_api_version=(value) ⇒ void
This method returns an undefined value.
See #labs_api_version.
54 55 56 |
# File 'lib/oanda_api/configuration.rb', line 54 def labs_api_version=(value) @labs_api_version = value end |
#max_new_connections_per_second ⇒ Numeric
The maximum number of new connections per second allowed to be made
to the API. Only enforced if #use_request_throttling? is true
.
62 63 64 |
# 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) ⇒ void
This method returns an undefined value.
69 70 71 72 73 |
# 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 ⇒ Numeric
The maximum number of requests per second allowed to be made through the
API. Only enforced if #use_request_throttling? is true
.
88 89 90 |
# 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) ⇒ void
This method returns an undefined value.
95 96 97 98 99 |
# 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 ⇒ Float
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
.
80 81 82 |
# 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 ⇒ Float
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
.
106 107 108 |
# File 'lib/oanda_api/configuration.rb', line 106 def min_request_interval @min_request_interval ||= (1.0 / max_requests_per_second) end |
#open_timeout ⇒ Numeric
The number of seconds the client waits for a new HTTP connection to be established before raising a timeout exception.
113 114 115 |
# File 'lib/oanda_api/configuration.rb', line 113 def open_timeout @open_timeout ||= OPEN_TIMEOUT end |
#open_timeout=(value) ⇒ void
This method returns an undefined value.
See #open_timeout.
120 121 122 123 |
# 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 ⇒ Numeric
The number of seconds the client waits for a response from the API before raising a timeout exception.
128 129 130 |
# File 'lib/oanda_api/configuration.rb', line 128 def read_timeout @read_timeout ||= READ_TIMEOUT end |
#read_timeout=(value) ⇒ void
This method returns an undefined value.
See #read_timeout.
135 136 137 138 |
# 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 ⇒ String
The Oanda REST API version used by the client.
142 143 144 |
# File 'lib/oanda_api/configuration.rb', line 142 def rest_api_version @rest_api_version ||= REST_API_VERSION end |
#rest_api_version=(value) ⇒ void
This method returns an undefined value.
See #rest_api_version.
149 150 151 |
# File 'lib/oanda_api/configuration.rb', line 149 def rest_api_version=(value) @rest_api_version = value end |
#use_compression ⇒ Boolean Also known as: use_compression?
Specifies whether the API uses compressed responses. See the Oanda Development Guide for more information about compression.
158 159 160 161 |
# File 'lib/oanda_api/configuration.rb', line 158 def use_compression @use_compression = USE_COMPRESSION if @use_compression.nil? @use_compression end |
#use_compression=(value) ⇒ void
This method returns an undefined value.
See #use_compression.
168 169 170 |
# File 'lib/oanda_api/configuration.rb', line 168 def use_compression=(value) @use_compression = !!value end |
#use_request_throttling ⇒ Boolean Also known as: use_request_throttling?
Throttles the rate of requests made to the API. See the Oanda Developers Guide for information about 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.
181 182 183 184 |
# 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 |
#use_request_throttling=(value) ⇒ void
This method returns an undefined value.
191 192 193 194 195 196 |
# 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 |