oanda_api 0.9.5 → 0.9.6

Sign up to get free protection for your applications and to get access to all the features.
Files changed (60) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +1 -0
  3. data/.travis.yml +15 -0
  4. data/CHANGELOG.md +24 -9
  5. data/Gemfile +2 -3
  6. data/README.md +11 -9
  7. data/lib/oanda_api.rb +1 -0
  8. data/lib/oanda_api/client/client.rb +13 -7
  9. data/lib/oanda_api/configuration.rb +57 -24
  10. data/lib/oanda_api/resource/order.rb +5 -6
  11. data/lib/oanda_api/resource/transaction.rb +3 -4
  12. data/lib/oanda_api/resource_collection.rb +4 -2
  13. data/lib/oanda_api/streaming/request.rb +6 -1
  14. data/lib/oanda_api/throttling/throttling.rb +105 -0
  15. data/lib/oanda_api/version.rb +1 -1
  16. data/oanda_api.gemspec +4 -4
  17. data/spec/fixtures/vcr_cassettes/accounts_get.yml +7 -5
  18. data/spec/fixtures/vcr_cassettes/accounts_id_get.yml +18 -14
  19. data/spec/fixtures/vcr_cassettes/calendar_events_period_get.yml +20 -14
  20. data/spec/fixtures/vcr_cassettes/calendar_instrument_and_period_get.yml +24 -21
  21. data/spec/fixtures/vcr_cassettes/calendar_period_get.yml +20 -14
  22. data/spec/fixtures/vcr_cassettes/candles_options_get.yml +12 -10
  23. data/spec/fixtures/vcr_cassettes/client_helper_accounts.yml +48 -5
  24. data/spec/fixtures/vcr_cassettes/instrument_EUR_USD.yml +11 -9
  25. data/spec/fixtures/vcr_cassettes/instrument_USD_JPY.yml +10 -8
  26. data/spec/fixtures/vcr_cassettes/instruments_get.yml +25 -19
  27. data/spec/fixtures/vcr_cassettes/instruments_options_get.yml +8 -6
  28. data/spec/fixtures/vcr_cassettes/order_id_close.yml +159 -313
  29. data/spec/fixtures/vcr_cassettes/order_id_get.yml +103 -21
  30. data/spec/fixtures/vcr_cassettes/order_options_create.yml +9 -7
  31. data/spec/fixtures/vcr_cassettes/order_options_update.yml +62 -20
  32. data/spec/fixtures/vcr_cassettes/orders_get.yml +46 -137
  33. data/spec/fixtures/vcr_cassettes/orders_options_get.yml +29 -50
  34. data/spec/fixtures/vcr_cassettes/positions_get.yml +19 -15
  35. data/spec/fixtures/vcr_cassettes/positions_instrument_close.yml +35 -27
  36. data/spec/fixtures/vcr_cassettes/positions_instrument_get.yml +17 -13
  37. data/spec/fixtures/vcr_cassettes/prices_options_get.yml +12 -10
  38. data/spec/fixtures/vcr_cassettes/spread_history_get.yml +17 -13
  39. data/spec/fixtures/vcr_cassettes/spreads_get.yml +17 -13
  40. data/spec/fixtures/vcr_cassettes/trade_id_close.yml +115 -52
  41. data/spec/fixtures/vcr_cassettes/trade_id_get.yml +278 -16
  42. data/spec/fixtures/vcr_cassettes/trade_options_modify.yml +58 -16
  43. data/spec/fixtures/vcr_cassettes/trades_filter_get.yml +44 -19
  44. data/spec/fixtures/vcr_cassettes/trades_get.yml +55 -16
  45. data/spec/fixtures/vcr_cassettes/transaction_id_get.yml +271 -149
  46. data/spec/fixtures/vcr_cassettes/transactions_options_get.yml +258 -133
  47. data/spec/fixtures/vcr_cassettes/with_throttling_and_max_requests_per_second.yml +28 -22
  48. data/spec/fixtures/vcr_cassettes/with_throttling_new_connections.yml +443 -0
  49. data/spec/fixtures/vcr_cassettes/with_throttling_with_multiple_threads.yml +57 -45
  50. data/spec/fixtures/vcr_cassettes/without_throttling.yml +91 -71
  51. data/spec/oanda_api/configuration_spec.rb +31 -0
  52. data/spec/oanda_api/examples/request_throttling_spec.rb +39 -4
  53. data/spec/oanda_api/examples/spread_history_spec.rb +3 -3
  54. data/spec/oanda_api/resource_collection_spec.rb +9 -0
  55. data/spec/oanda_api/streaming/client_spec.rb +5 -5
  56. data/spec/oanda_api/streaming/request_spec.rb +23 -8
  57. data/spec/spec_helper.rb +0 -3
  58. data/spec/support/client_helper.rb +6 -2
  59. metadata +13 -12
  60. data/spec/fixtures/vcr_cassettes/client_helper_account.yml +0 -45
@@ -14,16 +14,16 @@ http_interactions:
14
14
  Connection:
15
15
  - keep-alive
16
16
  Keep-Alive:
17
- - 30
17
+ - '30'
18
18
  response:
19
19
  status:
20
20
  code: 200
21
21
  message: OK
22
22
  headers:
23
23
  Server:
24
- - openresty/1.7.0.1
24
+ - openresty/1.9.15.1
25
25
  Date:
26
- - Mon, 14 Mar 2016 16:28:49 GMT
26
+ - Mon, 08 Jan 2018 18:26:34 GMT
27
27
  Content-Type:
28
28
  - application/json
29
29
  Content-Length:
@@ -31,14 +31,16 @@ http_interactions:
31
31
  Connection:
32
32
  - keep-alive
33
33
  Etag:
34
- - '"7307c40c38b58f85d7f3145c3c71bd20c5445765"'
34
+ - '"f31dec3261edd9030df81dc0ba69fe5a9d4e2fc9"'
35
+ Access-Control-Allow-Origin:
36
+ - "*"
35
37
  body:
36
38
  encoding: UTF-8
37
39
  string: "{\n\t\"prices\" : [\n\t\t{\n\t\t\t\"instrument\" : \"EUR_USD\",\n\t\t\t\"time\"
38
- : \"2016-03-14T16:28:48.718496Z\",\n\t\t\t\"bid\" : 1.11104,\n\t\t\t\"ask\"
39
- : 1.11118\n\t\t}\n\t]\n}"
40
+ : \"2018-01-08T18:26:31.344805Z\",\n\t\t\t\"bid\" : 1.19674,\n\t\t\t\"ask\"
41
+ : 1.19686\n\t\t}\n\t]\n}"
40
42
  http_version:
41
- recorded_at: Mon, 14 Mar 2016 16:28:48 GMT
43
+ recorded_at: Mon, 08 Jan 2018 18:26:45 GMT
42
44
  - request:
43
45
  method: get
44
46
  uri: https://api-fxpractice.oanda.com/v1/prices?instruments=EUR_USD
@@ -53,16 +55,16 @@ http_interactions:
53
55
  Connection:
54
56
  - keep-alive
55
57
  Keep-Alive:
56
- - 30
58
+ - '30'
57
59
  response:
58
60
  status:
59
61
  code: 200
60
62
  message: OK
61
63
  headers:
62
64
  Server:
63
- - openresty/1.7.0.1
65
+ - openresty/1.9.15.1
64
66
  Date:
65
- - Mon, 14 Mar 2016 16:28:50 GMT
67
+ - Mon, 08 Jan 2018 18:26:34 GMT
66
68
  Content-Type:
67
69
  - application/json
68
70
  Content-Length:
@@ -70,14 +72,16 @@ http_interactions:
70
72
  Connection:
71
73
  - keep-alive
72
74
  Etag:
73
- - '"50c652cb079cb183ec34718d3760fd9f07cd9948"'
75
+ - '"f31dec3261edd9030df81dc0ba69fe5a9d4e2fc9"'
76
+ Access-Control-Allow-Origin:
77
+ - "*"
74
78
  body:
75
79
  encoding: UTF-8
76
80
  string: "{\n\t\"prices\" : [\n\t\t{\n\t\t\t\"instrument\" : \"EUR_USD\",\n\t\t\t\"time\"
77
- : \"2016-03-14T16:28:49.214000Z\",\n\t\t\t\"bid\" : 1.11104,\n\t\t\t\"ask\"
78
- : 1.11118\n\t\t}\n\t]\n}"
81
+ : \"2018-01-08T18:26:31.344805Z\",\n\t\t\t\"bid\" : 1.19674,\n\t\t\t\"ask\"
82
+ : 1.19686\n\t\t}\n\t]\n}"
79
83
  http_version:
80
- recorded_at: Mon, 14 Mar 2016 16:28:50 GMT
84
+ recorded_at: Mon, 08 Jan 2018 18:26:45 GMT
81
85
  - request:
82
86
  method: get
83
87
  uri: https://api-fxpractice.oanda.com/v1/prices?instruments=EUR_USD
@@ -92,16 +96,16 @@ http_interactions:
92
96
  Connection:
93
97
  - keep-alive
94
98
  Keep-Alive:
95
- - 30
99
+ - '30'
96
100
  response:
97
101
  status:
98
102
  code: 200
99
103
  message: OK
100
104
  headers:
101
105
  Server:
102
- - openresty/1.7.0.1
106
+ - openresty/1.9.15.1
103
107
  Date:
104
- - Mon, 14 Mar 2016 16:28:51 GMT
108
+ - Mon, 08 Jan 2018 18:26:34 GMT
105
109
  Content-Type:
106
110
  - application/json
107
111
  Content-Length:
@@ -109,14 +113,16 @@ http_interactions:
109
113
  Connection:
110
114
  - keep-alive
111
115
  Etag:
112
- - '"50c652cb079cb183ec34718d3760fd9f07cd9948"'
116
+ - '"f31dec3261edd9030df81dc0ba69fe5a9d4e2fc9"'
117
+ Access-Control-Allow-Origin:
118
+ - "*"
113
119
  body:
114
120
  encoding: UTF-8
115
121
  string: "{\n\t\"prices\" : [\n\t\t{\n\t\t\t\"instrument\" : \"EUR_USD\",\n\t\t\t\"time\"
116
- : \"2016-03-14T16:28:49.214000Z\",\n\t\t\t\"bid\" : 1.11104,\n\t\t\t\"ask\"
117
- : 1.11118\n\t\t}\n\t]\n}"
122
+ : \"2018-01-08T18:26:31.344805Z\",\n\t\t\t\"bid\" : 1.19674,\n\t\t\t\"ask\"
123
+ : 1.19686\n\t\t}\n\t]\n}"
118
124
  http_version:
119
- recorded_at: Mon, 14 Mar 2016 16:28:51 GMT
125
+ recorded_at: Mon, 08 Jan 2018 18:26:45 GMT
120
126
  - request:
121
127
  method: get
122
128
  uri: https://api-fxpractice.oanda.com/v1/prices?instruments=EUR_USD
@@ -131,16 +137,16 @@ http_interactions:
131
137
  Connection:
132
138
  - keep-alive
133
139
  Keep-Alive:
134
- - 30
140
+ - '30'
135
141
  response:
136
142
  status:
137
143
  code: 200
138
144
  message: OK
139
145
  headers:
140
146
  Server:
141
- - openresty/1.7.0.1
147
+ - openresty/1.9.15.1
142
148
  Date:
143
- - Mon, 14 Mar 2016 16:28:52 GMT
149
+ - Mon, 08 Jan 2018 18:26:34 GMT
144
150
  Content-Type:
145
151
  - application/json
146
152
  Content-Length:
@@ -148,14 +154,16 @@ http_interactions:
148
154
  Connection:
149
155
  - keep-alive
150
156
  Etag:
151
- - '"50c652cb079cb183ec34718d3760fd9f07cd9948"'
157
+ - '"f31dec3261edd9030df81dc0ba69fe5a9d4e2fc9"'
158
+ Access-Control-Allow-Origin:
159
+ - "*"
152
160
  body:
153
161
  encoding: UTF-8
154
162
  string: "{\n\t\"prices\" : [\n\t\t{\n\t\t\t\"instrument\" : \"EUR_USD\",\n\t\t\t\"time\"
155
- : \"2016-03-14T16:28:49.214000Z\",\n\t\t\t\"bid\" : 1.11104,\n\t\t\t\"ask\"
156
- : 1.11118\n\t\t}\n\t]\n}"
163
+ : \"2018-01-08T18:26:31.344805Z\",\n\t\t\t\"bid\" : 1.19674,\n\t\t\t\"ask\"
164
+ : 1.19686\n\t\t}\n\t]\n}"
157
165
  http_version:
158
- recorded_at: Mon, 14 Mar 2016 16:28:52 GMT
166
+ recorded_at: Mon, 08 Jan 2018 18:26:45 GMT
159
167
  - request:
160
168
  method: get
161
169
  uri: https://api-fxpractice.oanda.com/v1/prices?instruments=EUR_USD
@@ -170,16 +178,16 @@ http_interactions:
170
178
  Connection:
171
179
  - keep-alive
172
180
  Keep-Alive:
173
- - 30
181
+ - '30'
174
182
  response:
175
183
  status:
176
184
  code: 200
177
185
  message: OK
178
186
  headers:
179
187
  Server:
180
- - openresty/1.7.0.1
188
+ - openresty/1.9.15.1
181
189
  Date:
182
- - Mon, 14 Mar 2016 16:28:53 GMT
190
+ - Mon, 08 Jan 2018 18:26:34 GMT
183
191
  Content-Type:
184
192
  - application/json
185
193
  Content-Length:
@@ -187,14 +195,16 @@ http_interactions:
187
195
  Connection:
188
196
  - keep-alive
189
197
  Etag:
190
- - '"50c652cb079cb183ec34718d3760fd9f07cd9948"'
198
+ - '"f31dec3261edd9030df81dc0ba69fe5a9d4e2fc9"'
199
+ Access-Control-Allow-Origin:
200
+ - "*"
191
201
  body:
192
202
  encoding: UTF-8
193
203
  string: "{\n\t\"prices\" : [\n\t\t{\n\t\t\t\"instrument\" : \"EUR_USD\",\n\t\t\t\"time\"
194
- : \"2016-03-14T16:28:49.214000Z\",\n\t\t\t\"bid\" : 1.11104,\n\t\t\t\"ask\"
195
- : 1.11118\n\t\t}\n\t]\n}"
204
+ : \"2018-01-08T18:26:31.344805Z\",\n\t\t\t\"bid\" : 1.19674,\n\t\t\t\"ask\"
205
+ : 1.19686\n\t\t}\n\t]\n}"
196
206
  http_version:
197
- recorded_at: Mon, 14 Mar 2016 16:28:53 GMT
207
+ recorded_at: Mon, 08 Jan 2018 18:26:45 GMT
198
208
  - request:
199
209
  method: get
200
210
  uri: https://api-fxpractice.oanda.com/v1/prices?instruments=EUR_USD
@@ -209,16 +219,16 @@ http_interactions:
209
219
  Connection:
210
220
  - keep-alive
211
221
  Keep-Alive:
212
- - 30
222
+ - '30'
213
223
  response:
214
224
  status:
215
225
  code: 200
216
226
  message: OK
217
227
  headers:
218
228
  Server:
219
- - openresty/1.7.0.1
229
+ - openresty/1.9.15.1
220
230
  Date:
221
- - Mon, 14 Mar 2016 16:28:54 GMT
231
+ - Mon, 08 Jan 2018 18:26:34 GMT
222
232
  Content-Type:
223
233
  - application/json
224
234
  Content-Length:
@@ -226,14 +236,16 @@ http_interactions:
226
236
  Connection:
227
237
  - keep-alive
228
238
  Etag:
229
- - '"50c652cb079cb183ec34718d3760fd9f07cd9948"'
239
+ - '"f31dec3261edd9030df81dc0ba69fe5a9d4e2fc9"'
240
+ Access-Control-Allow-Origin:
241
+ - "*"
230
242
  body:
231
243
  encoding: UTF-8
232
244
  string: "{\n\t\"prices\" : [\n\t\t{\n\t\t\t\"instrument\" : \"EUR_USD\",\n\t\t\t\"time\"
233
- : \"2016-03-14T16:28:49.214000Z\",\n\t\t\t\"bid\" : 1.11104,\n\t\t\t\"ask\"
234
- : 1.11118\n\t\t}\n\t]\n}"
245
+ : \"2018-01-08T18:26:31.344805Z\",\n\t\t\t\"bid\" : 1.19674,\n\t\t\t\"ask\"
246
+ : 1.19686\n\t\t}\n\t]\n}"
235
247
  http_version:
236
- recorded_at: Mon, 14 Mar 2016 16:28:54 GMT
248
+ recorded_at: Mon, 08 Jan 2018 18:26:45 GMT
237
249
  - request:
238
250
  method: get
239
251
  uri: https://api-fxpractice.oanda.com/v1/prices?instruments=EUR_USD
@@ -248,16 +260,16 @@ http_interactions:
248
260
  Connection:
249
261
  - keep-alive
250
262
  Keep-Alive:
251
- - 30
263
+ - '30'
252
264
  response:
253
265
  status:
254
266
  code: 200
255
267
  message: OK
256
268
  headers:
257
269
  Server:
258
- - openresty/1.7.0.1
270
+ - openresty/1.9.15.1
259
271
  Date:
260
- - Mon, 14 Mar 2016 16:28:55 GMT
272
+ - Mon, 08 Jan 2018 18:26:34 GMT
261
273
  Content-Type:
262
274
  - application/json
263
275
  Content-Length:
@@ -265,14 +277,16 @@ http_interactions:
265
277
  Connection:
266
278
  - keep-alive
267
279
  Etag:
268
- - '"50c652cb079cb183ec34718d3760fd9f07cd9948"'
280
+ - '"f31dec3261edd9030df81dc0ba69fe5a9d4e2fc9"'
281
+ Access-Control-Allow-Origin:
282
+ - "*"
269
283
  body:
270
284
  encoding: UTF-8
271
285
  string: "{\n\t\"prices\" : [\n\t\t{\n\t\t\t\"instrument\" : \"EUR_USD\",\n\t\t\t\"time\"
272
- : \"2016-03-14T16:28:49.214000Z\",\n\t\t\t\"bid\" : 1.11104,\n\t\t\t\"ask\"
273
- : 1.11118\n\t\t}\n\t]\n}"
286
+ : \"2018-01-08T18:26:31.344805Z\",\n\t\t\t\"bid\" : 1.19674,\n\t\t\t\"ask\"
287
+ : 1.19686\n\t\t}\n\t]\n}"
274
288
  http_version:
275
- recorded_at: Mon, 14 Mar 2016 16:28:55 GMT
289
+ recorded_at: Mon, 08 Jan 2018 18:26:45 GMT
276
290
  - request:
277
291
  method: get
278
292
  uri: https://api-fxpractice.oanda.com/v1/prices?instruments=EUR_USD
@@ -287,16 +301,16 @@ http_interactions:
287
301
  Connection:
288
302
  - keep-alive
289
303
  Keep-Alive:
290
- - 30
304
+ - '30'
291
305
  response:
292
306
  status:
293
307
  code: 200
294
308
  message: OK
295
309
  headers:
296
310
  Server:
297
- - openresty/1.7.0.1
311
+ - openresty/1.9.15.1
298
312
  Date:
299
- - Mon, 14 Mar 2016 16:28:56 GMT
313
+ - Mon, 08 Jan 2018 18:26:34 GMT
300
314
  Content-Type:
301
315
  - application/json
302
316
  Content-Length:
@@ -304,14 +318,16 @@ http_interactions:
304
318
  Connection:
305
319
  - keep-alive
306
320
  Etag:
307
- - '"50c652cb079cb183ec34718d3760fd9f07cd9948"'
321
+ - '"f31dec3261edd9030df81dc0ba69fe5a9d4e2fc9"'
322
+ Access-Control-Allow-Origin:
323
+ - "*"
308
324
  body:
309
325
  encoding: UTF-8
310
326
  string: "{\n\t\"prices\" : [\n\t\t{\n\t\t\t\"instrument\" : \"EUR_USD\",\n\t\t\t\"time\"
311
- : \"2016-03-14T16:28:49.214000Z\",\n\t\t\t\"bid\" : 1.11104,\n\t\t\t\"ask\"
312
- : 1.11118\n\t\t}\n\t]\n}"
327
+ : \"2018-01-08T18:26:31.344805Z\",\n\t\t\t\"bid\" : 1.19674,\n\t\t\t\"ask\"
328
+ : 1.19686\n\t\t}\n\t]\n}"
313
329
  http_version:
314
- recorded_at: Mon, 14 Mar 2016 16:28:56 GMT
330
+ recorded_at: Mon, 08 Jan 2018 18:26:45 GMT
315
331
  - request:
316
332
  method: get
317
333
  uri: https://api-fxpractice.oanda.com/v1/prices?instruments=EUR_USD
@@ -326,16 +342,16 @@ http_interactions:
326
342
  Connection:
327
343
  - keep-alive
328
344
  Keep-Alive:
329
- - 30
345
+ - '30'
330
346
  response:
331
347
  status:
332
348
  code: 200
333
349
  message: OK
334
350
  headers:
335
351
  Server:
336
- - openresty/1.7.0.1
352
+ - openresty/1.9.15.1
337
353
  Date:
338
- - Mon, 14 Mar 2016 16:28:58 GMT
354
+ - Mon, 08 Jan 2018 18:26:34 GMT
339
355
  Content-Type:
340
356
  - application/json
341
357
  Content-Length:
@@ -343,14 +359,16 @@ http_interactions:
343
359
  Connection:
344
360
  - keep-alive
345
361
  Etag:
346
- - '"50c652cb079cb183ec34718d3760fd9f07cd9948"'
362
+ - '"f31dec3261edd9030df81dc0ba69fe5a9d4e2fc9"'
363
+ Access-Control-Allow-Origin:
364
+ - "*"
347
365
  body:
348
366
  encoding: UTF-8
349
367
  string: "{\n\t\"prices\" : [\n\t\t{\n\t\t\t\"instrument\" : \"EUR_USD\",\n\t\t\t\"time\"
350
- : \"2016-03-14T16:28:49.214000Z\",\n\t\t\t\"bid\" : 1.11104,\n\t\t\t\"ask\"
351
- : 1.11118\n\t\t}\n\t]\n}"
368
+ : \"2018-01-08T18:26:31.344805Z\",\n\t\t\t\"bid\" : 1.19674,\n\t\t\t\"ask\"
369
+ : 1.19686\n\t\t}\n\t]\n}"
352
370
  http_version:
353
- recorded_at: Mon, 14 Mar 2016 16:28:57 GMT
371
+ recorded_at: Mon, 08 Jan 2018 18:26:45 GMT
354
372
  - request:
355
373
  method: get
356
374
  uri: https://api-fxpractice.oanda.com/v1/prices?instruments=EUR_USD
@@ -365,16 +383,16 @@ http_interactions:
365
383
  Connection:
366
384
  - keep-alive
367
385
  Keep-Alive:
368
- - 30
386
+ - '30'
369
387
  response:
370
388
  status:
371
389
  code: 200
372
390
  message: OK
373
391
  headers:
374
392
  Server:
375
- - openresty/1.7.0.1
393
+ - openresty/1.9.15.1
376
394
  Date:
377
- - Mon, 14 Mar 2016 16:28:59 GMT
395
+ - Mon, 08 Jan 2018 18:26:35 GMT
378
396
  Content-Type:
379
397
  - application/json
380
398
  Content-Length:
@@ -382,12 +400,14 @@ http_interactions:
382
400
  Connection:
383
401
  - keep-alive
384
402
  Etag:
385
- - '"50c652cb079cb183ec34718d3760fd9f07cd9948"'
403
+ - '"f31dec3261edd9030df81dc0ba69fe5a9d4e2fc9"'
404
+ Access-Control-Allow-Origin:
405
+ - "*"
386
406
  body:
387
407
  encoding: UTF-8
388
408
  string: "{\n\t\"prices\" : [\n\t\t{\n\t\t\t\"instrument\" : \"EUR_USD\",\n\t\t\t\"time\"
389
- : \"2016-03-14T16:28:49.214000Z\",\n\t\t\t\"bid\" : 1.11104,\n\t\t\t\"ask\"
390
- : 1.11118\n\t\t}\n\t]\n}"
409
+ : \"2018-01-08T18:26:31.344805Z\",\n\t\t\t\"bid\" : 1.19674,\n\t\t\t\"ask\"
410
+ : 1.19686\n\t\t}\n\t]\n}"
391
411
  http_version:
392
- recorded_at: Mon, 14 Mar 2016 16:28:58 GMT
393
- recorded_with: VCR 3.0.1
412
+ recorded_at: Mon, 08 Jan 2018 18:26:45 GMT
413
+ recorded_with: VCR 4.0.0
@@ -72,6 +72,7 @@ describe "OandaAPI::Configuration" do
72
72
  end
73
73
  end
74
74
 
75
+ #---
75
76
  describe "#max_requests_per_second" do
76
77
  it "returns the default max requests per second" do
77
78
  expect(config.max_requests_per_second).to eq OandaAPI::Configuration::MAX_REQUESTS_PER_SECOND
@@ -101,6 +102,36 @@ describe "OandaAPI::Configuration" do
101
102
  expect(config.min_request_interval).to eq(0.5)
102
103
  end
103
104
  end
105
+
106
+ describe "#max_new_connections_per_second" do
107
+ it "returns the default max new connections per second" do
108
+ expect(config.max_new_connections_per_second).to eq OandaAPI::Configuration::MAX_NEW_CONNECTIONS_PER_SECOND
109
+ end
110
+ end
111
+
112
+ describe "#max_new_connections_per_second=" do
113
+ it "overrides the default max new connections per second" do
114
+ config.max_new_connections_per_second = 5
115
+ expect(config.max_new_connections_per_second).to eq 5
116
+ end
117
+
118
+ it "must be numeric" do
119
+ expect { config.max_new_connections_per_second = "X" }.to raise_error(ArgumentError)
120
+ end
121
+
122
+ it "must be > 0" do
123
+ [-10, 0].each do |val|
124
+ expect { config.max_new_connections_per_second = val }.to raise_error(ArgumentError)
125
+ end
126
+ end
127
+ end
128
+
129
+ describe "#min_new_connection_interval" do
130
+ it "is the inverse of #max_new_connections_per_second" do
131
+ config.max_new_connections_per_second = 2
132
+ expect(config.min_new_connection_interval).to eq(0.5)
133
+ end
134
+ end
104
135
 
105
136
  describe "#open_timeout" do
106
137
  it "returns the default open timeout" do
@@ -5,11 +5,13 @@ describe "OandaAPI::Client" do
5
5
  let(:client) { ClientHelper.client }
6
6
 
7
7
  around do |example|
8
- reset_configuration(:use_request_throttling, :max_requests_per_second) { example.call }
8
+ reset_configuration(:use_request_throttling,
9
+ :max_requests_per_second,
10
+ :max_new_connections_per_second) { example.call }
9
11
  end
10
12
 
11
13
  context "when NOT using request throttling" do
12
- it "it does NOT limit the request rate of multiple sequential requests", :vcr do
14
+ it "does NOT limit the request rate of multiple sequential requests", :vcr do
13
15
  OandaAPI.configuration.use_request_throttling = false
14
16
  VCR.use_cassette("without_throttling") do
15
17
  start_time = Time.now
@@ -24,11 +26,44 @@ describe "OandaAPI::Client" do
24
26
  expect(Time.now - start_time).to be > 0.0 && be < 1.0
25
27
  end
26
28
  end
29
+
30
+ #
31
+ # 08 Jan, 2018 - it seems connection rate limiting is not enforced consistently by Oanda
32
+ # so, removing this test for now.
33
+ #
34
+ # it "does NOT limit the rate of NEW connections", :vcr do
35
+ # OandaAPI.configuration.use_request_throttling = false
36
+ # VCR.use_cassette("without_throttling_new_connections") do
37
+ # message = ""
38
+ # begin
39
+ # 1.upto(10) do
40
+ # client = ClientHelper.client force_new: true
41
+ # client.prices(instruments: "EUR_USD").get
42
+ # end
43
+ # rescue OandaAPI::RequestError => e
44
+ # message = e.message
45
+ # end
46
+ # expect(message).to match(/Rate limit violation of newly established connections/)
47
+ # end
48
+ # end
27
49
  end
28
50
 
29
51
  context "when using request throttling" do
52
+ it "limits the rate of NEW connections", :vcr do
53
+ OandaAPI.configuration.use_request_throttling = true
54
+ VCR.use_cassette("with_throttling_new_connections") do
55
+ successful_connections = 0
56
+ 1.upto(10) do
57
+ client = ClientHelper.client force_new: true
58
+ client.accounts.get
59
+ successful_connections += 1
60
+ end
61
+ expect(successful_connections).to eq 10
62
+ end
63
+ end
64
+
30
65
  context "with a positive value set for max_requests_per_second" do
31
- it "it limits multiple sequential requests to the rate specified in the requests_per_second setting " do
66
+ it "limits multiple sequential requests to the rate specified in the requests_per_second setting " do
32
67
  OandaAPI.configuration.use_request_throttling = true
33
68
  OandaAPI.configuration.max_requests_per_second = 2
34
69
 
@@ -47,7 +82,7 @@ describe "OandaAPI::Client" do
47
82
  end
48
83
 
49
84
  context "when multiple threads make synchronized requests to the same client instance" do
50
- it "it throttles the combined requests made by all threads" do
85
+ it "throttles the combined requests made by all threads" do
51
86
  OandaAPI.configuration.use_request_throttling = true
52
87
  OandaAPI.configuration.max_requests_per_second = 3
53
88