Class: OandaAPI::Configuration

Inherits:
Object
  • Object
show all
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

Instance Method Details

#connection_pool_sizeNumeric

Maximum size of the persistent connection pool.

Returns:

  • (Numeric)


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.

Returns:

  • (Numeric)


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_formatSymbol

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.

Returns:

  • (Symbol)


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.

Parameters:

  • value (Symbol)


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

#headersHash

Returns headers that are set on every request as a result of configuration settings.

Returns:

  • (Hash)

    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_versionString

The Oanda Labs API version used by the client.

Returns:

  • (String)


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.

Parameters:

  • value (String)


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_secondNumeric

The maximum number of new connections per second allowed to be made to the API. Only enforced if #use_request_throttling? is true.

Returns:

  • (Numeric)


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.

See #max_new_connections_per_second.

Parameters:

  • value (Numeric)


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_secondNumeric

The maximum number of requests per second allowed to be made through the API. Only enforced if #use_request_throttling? is true.

Returns:

  • (Numeric)


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.

See #max_requests_per_second.

Parameters:

  • value (Numeric)


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_intervalFloat

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.

Returns:

  • (Float)


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_intervalFloat

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.

Returns:

  • (Float)


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_timeoutNumeric

The number of seconds the client waits for a new HTTP connection to be established before raising a timeout exception.

Returns:

  • (Numeric)


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.

Parameters:

  • value (Numeric)


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_timeoutNumeric

The number of seconds the client waits for a response from the API before raising a timeout exception.

Returns:

  • (Numeric)


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.

Parameters:

  • value (Numeric)


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_versionString

The Oanda REST API version used by the client.

Returns:

  • (String)


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.

Parameters:

  • value (String)


149
150
151
# File 'lib/oanda_api/configuration.rb', line 149

def rest_api_version=(value)
  @rest_api_version = value
end

#use_compressionBoolean Also known as: use_compression?

Specifies whether the API uses compressed responses. See the Oanda Development Guide for more information about compression.

Returns:

  • (Boolean)


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.

Parameters:

  • value (Boolean)


168
169
170
# File 'lib/oanda_api/configuration.rb', line 168

def use_compression=(value)
  @use_compression = !!value
end

#use_request_throttlingBoolean 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.

Returns:

  • (Boolean)


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.

See #use_request_throttling.

Parameters:

  • value (Boolean)


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