oanda_api 0.9.4 → 0.9.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (92) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +67 -6
  3. data/README.md +31 -3
  4. data/lib/oanda_api.rb +3 -1
  5. data/lib/oanda_api/client/client.rb +17 -12
  6. data/lib/oanda_api/client/namespace_proxy.rb +2 -2
  7. data/lib/oanda_api/client/resource_descriptor.rb +25 -9
  8. data/lib/oanda_api/client/username_client.rb +7 -0
  9. data/lib/oanda_api/configuration.rb +14 -0
  10. data/lib/oanda_api/resource/account.rb +22 -3
  11. data/lib/oanda_api/resource/candle.rb +1 -1
  12. data/lib/oanda_api/resource/labs/calendar_event.rb +25 -0
  13. data/lib/oanda_api/resource/labs/spread_history.rb +61 -0
  14. data/lib/oanda_api/resource/order.rb +4 -4
  15. data/lib/oanda_api/resource/transaction_history.rb +0 -1
  16. data/lib/oanda_api/resource_base.rb +64 -2
  17. data/lib/oanda_api/resource_collection.rb +6 -0
  18. data/lib/oanda_api/streaming/client.rb +1 -0
  19. data/lib/oanda_api/version.rb +1 -1
  20. data/oanda_api.gemspec +2 -2
  21. data/spec/fixtures/vcr_cassettes/accounts_get.yml +13 -79
  22. data/spec/fixtures/vcr_cassettes/accounts_id_get.yml +23 -125
  23. data/spec/fixtures/vcr_cassettes/calendar_events_period_get.yml +54 -0
  24. data/spec/fixtures/vcr_cassettes/calendar_instrument_and_period_get.yml +61 -0
  25. data/spec/fixtures/vcr_cassettes/calendar_period_get.yml +54 -0
  26. data/spec/fixtures/vcr_cassettes/candles_options_get.yml +9 -45
  27. data/spec/fixtures/vcr_cassettes/client_helper_account.yml +45 -0
  28. data/spec/fixtures/vcr_cassettes/client_helper_accounts.yml +45 -0
  29. data/spec/fixtures/vcr_cassettes/instrument_EUR_USD.yml +42 -0
  30. data/spec/fixtures/vcr_cassettes/instrument_USD_JPY.yml +42 -0
  31. data/spec/fixtures/vcr_cassettes/instruments_get.yml +37 -303
  32. data/spec/fixtures/vcr_cassettes/instruments_options_get.yml +6 -43
  33. data/spec/fixtures/vcr_cassettes/order_id_close.yml +448 -0
  34. data/spec/fixtures/vcr_cassettes/order_id_get.yml +84 -0
  35. data/spec/fixtures/vcr_cassettes/order_options_create.yml +42 -0
  36. data/spec/fixtures/vcr_cassettes/order_options_update.yml +82 -0
  37. data/spec/fixtures/vcr_cassettes/orders_get.yml +205 -0
  38. data/spec/fixtures/vcr_cassettes/orders_options_get.yml +120 -0
  39. data/spec/fixtures/vcr_cassettes/positions_get.yml +82 -0
  40. data/spec/fixtures/vcr_cassettes/positions_instrument_close.yml +154 -0
  41. data/spec/fixtures/vcr_cassettes/{account_id_order_options_create.yml → positions_instrument_get.yml} +24 -18
  42. data/spec/fixtures/vcr_cassettes/prices_options_get.yml +11 -48
  43. data/spec/fixtures/vcr_cassettes/spread_history_get.yml +53 -0
  44. data/spec/fixtures/vcr_cassettes/spreads_get.yml +53 -0
  45. data/spec/fixtures/vcr_cassettes/trade_id_close.yml +277 -0
  46. data/spec/fixtures/vcr_cassettes/trade_id_get.yml +82 -0
  47. data/spec/fixtures/vcr_cassettes/trade_options_modify.yml +80 -0
  48. data/spec/fixtures/vcr_cassettes/trades_filter_get.yml +90 -0
  49. data/spec/fixtures/vcr_cassettes/trades_get.yml +171 -0
  50. data/spec/fixtures/vcr_cassettes/transaction_id_get.yml +248 -0
  51. data/spec/fixtures/vcr_cassettes/transactions_options_get.yml +202 -0
  52. data/spec/fixtures/vcr_cassettes/with_throttling_and_max_requests_per_second.yml +25 -19
  53. data/spec/fixtures/vcr_cassettes/with_throttling_with_multiple_threads.yml +51 -39
  54. data/spec/fixtures/vcr_cassettes/without_throttling.yml +81 -61
  55. data/spec/oanda_api/client/client_spec.rb +23 -10
  56. data/spec/oanda_api/client/namespace_proxy_spec.rb +1 -1
  57. data/spec/oanda_api/client/resource_descriptor_spec.rb +45 -14
  58. data/spec/oanda_api/configuration_spec.rb +13 -0
  59. data/spec/oanda_api/examples/accounts_spec.rb +0 -7
  60. data/spec/oanda_api/examples/calendar_spec.rb +27 -0
  61. data/spec/oanda_api/examples/orders_spec.rb +12 -12
  62. data/spec/oanda_api/examples/positions_spec.rb +3 -3
  63. data/spec/oanda_api/examples/rates_spec.rb +4 -2
  64. data/spec/oanda_api/examples/spread_history_spec.rb +32 -0
  65. data/spec/oanda_api/examples/trades_spec.rb +5 -5
  66. data/spec/oanda_api/examples/transactions_spec.rb +2 -2
  67. data/spec/oanda_api/resource_base_spec.rb +48 -8
  68. data/spec/oanda_api/streaming/client_spec.rb +30 -2
  69. data/spec/spec_helper.rb +1 -1
  70. data/spec/support/client_helper.rb +45 -11
  71. data/spec/support/vcr.rb +1 -0
  72. metadata +63 -49
  73. data/spec/fixtures/vcr_cassettes/account_id_order_id_close.yml +0 -264
  74. data/spec/fixtures/vcr_cassettes/account_id_order_id_get.yml +0 -114
  75. data/spec/fixtures/vcr_cassettes/account_id_order_options_update.yml +0 -112
  76. data/spec/fixtures/vcr_cassettes/account_id_orders_get.yml +0 -118
  77. data/spec/fixtures/vcr_cassettes/account_id_orders_options_get.yml +0 -123
  78. data/spec/fixtures/vcr_cassettes/account_id_positions_get.yml +0 -112
  79. data/spec/fixtures/vcr_cassettes/account_id_positions_instrument_close.yml +0 -214
  80. data/spec/fixtures/vcr_cassettes/account_id_positions_instrument_get.yml +0 -110
  81. data/spec/fixtures/vcr_cassettes/account_id_trade_id_close.yml +0 -252
  82. data/spec/fixtures/vcr_cassettes/account_id_trade_id_get.yml +0 -112
  83. data/spec/fixtures/vcr_cassettes/account_id_trade_options_modify.yml +0 -110
  84. data/spec/fixtures/vcr_cassettes/account_id_trades_filter_get.yml +0 -118
  85. data/spec/fixtures/vcr_cassettes/account_id_trades_get.yml +0 -118
  86. data/spec/fixtures/vcr_cassettes/account_id_transaction_id_get.yml +0 -283
  87. data/spec/fixtures/vcr_cassettes/account_id_transactions_options_get.yml +0 -205
  88. data/spec/fixtures/vcr_cassettes/accounts_create.yml +0 -75
  89. data/spec/fixtures/vcr_cassettes/sandbox_client.yml +0 -116
  90. data/spec/fixtures/vcr_cassettes/sandbox_client_account.yml +0 -111
  91. data/spec/fixtures/vcr_cassettes/sandbox_instrument_EUR_USD.yml +0 -77
  92. data/spec/oanda_api/client/username_client_spec.rb +0 -31
@@ -2,13 +2,15 @@
2
2
  http_interactions:
3
3
  - request:
4
4
  method: get
5
- uri: http://api-sandbox.oanda.com/v1/prices?instruments=EUR_USD&username=dwaymotim
5
+ uri: https://api-fxpractice.oanda.com/v1/prices?instruments=EUR_USD
6
6
  body:
7
7
  encoding: US-ASCII
8
8
  string: ''
9
9
  headers:
10
10
  X-Accept-Datetime-Format:
11
11
  - RFC3339
12
+ Authorization:
13
+ - Bearer <OANDA_TESTING_API_TOKEN>
12
14
  Connection:
13
15
  - keep-alive
14
16
  Keep-Alive:
@@ -21,7 +23,7 @@ http_interactions:
21
23
  Server:
22
24
  - openresty/1.7.0.1
23
25
  Date:
24
- - Fri, 11 Sep 2015 20:41:30 GMT
26
+ - Mon, 14 Mar 2016 16:28:49 GMT
25
27
  Content-Type:
26
28
  - application/json
27
29
  Content-Length:
@@ -29,23 +31,25 @@ http_interactions:
29
31
  Connection:
30
32
  - keep-alive
31
33
  Etag:
32
- - '"f481d760a871b4f679207cd0715bd4be8271f399"'
34
+ - '"7307c40c38b58f85d7f3145c3c71bd20c5445765"'
33
35
  body:
34
36
  encoding: UTF-8
35
37
  string: "{\n\t\"prices\" : [\n\t\t{\n\t\t\t\"instrument\" : \"EUR_USD\",\n\t\t\t\"time\"
36
- : \"2015-09-11T20:41:29.948985Z\",\n\t\t\t\"bid\" : 1.24115,\n\t\t\t\"ask\"
37
- : 1.24128\n\t\t}\n\t]\n}"
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}"
38
40
  http_version:
39
- recorded_at: Fri, 11 Sep 2015 20:41:30 GMT
41
+ recorded_at: Mon, 14 Mar 2016 16:28:48 GMT
40
42
  - request:
41
43
  method: get
42
- uri: http://api-sandbox.oanda.com/v1/prices?instruments=EUR_USD&username=dwaymotim
44
+ uri: https://api-fxpractice.oanda.com/v1/prices?instruments=EUR_USD
43
45
  body:
44
46
  encoding: US-ASCII
45
47
  string: ''
46
48
  headers:
47
49
  X-Accept-Datetime-Format:
48
50
  - RFC3339
51
+ Authorization:
52
+ - Bearer <OANDA_TESTING_API_TOKEN>
49
53
  Connection:
50
54
  - keep-alive
51
55
  Keep-Alive:
@@ -58,7 +62,7 @@ http_interactions:
58
62
  Server:
59
63
  - openresty/1.7.0.1
60
64
  Date:
61
- - Fri, 11 Sep 2015 20:41:30 GMT
65
+ - Mon, 14 Mar 2016 16:28:50 GMT
62
66
  Content-Type:
63
67
  - application/json
64
68
  Content-Length:
@@ -66,23 +70,25 @@ http_interactions:
66
70
  Connection:
67
71
  - keep-alive
68
72
  Etag:
69
- - '"f481d760a871b4f679207cd0715bd4be8271f399"'
73
+ - '"50c652cb079cb183ec34718d3760fd9f07cd9948"'
70
74
  body:
71
75
  encoding: UTF-8
72
76
  string: "{\n\t\"prices\" : [\n\t\t{\n\t\t\t\"instrument\" : \"EUR_USD\",\n\t\t\t\"time\"
73
- : \"2015-09-11T20:41:29.948985Z\",\n\t\t\t\"bid\" : 1.24115,\n\t\t\t\"ask\"
74
- : 1.24128\n\t\t}\n\t]\n}"
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}"
75
79
  http_version:
76
- recorded_at: Fri, 11 Sep 2015 20:41:30 GMT
80
+ recorded_at: Mon, 14 Mar 2016 16:28:50 GMT
77
81
  - request:
78
82
  method: get
79
- uri: http://api-sandbox.oanda.com/v1/prices?instruments=EUR_USD&username=dwaymotim
83
+ uri: https://api-fxpractice.oanda.com/v1/prices?instruments=EUR_USD
80
84
  body:
81
85
  encoding: US-ASCII
82
86
  string: ''
83
87
  headers:
84
88
  X-Accept-Datetime-Format:
85
89
  - RFC3339
90
+ Authorization:
91
+ - Bearer <OANDA_TESTING_API_TOKEN>
86
92
  Connection:
87
93
  - keep-alive
88
94
  Keep-Alive:
@@ -95,7 +101,7 @@ http_interactions:
95
101
  Server:
96
102
  - openresty/1.7.0.1
97
103
  Date:
98
- - Fri, 11 Sep 2015 20:41:30 GMT
104
+ - Mon, 14 Mar 2016 16:28:51 GMT
99
105
  Content-Type:
100
106
  - application/json
101
107
  Content-Length:
@@ -103,23 +109,25 @@ http_interactions:
103
109
  Connection:
104
110
  - keep-alive
105
111
  Etag:
106
- - '"f481d760a871b4f679207cd0715bd4be8271f399"'
112
+ - '"50c652cb079cb183ec34718d3760fd9f07cd9948"'
107
113
  body:
108
114
  encoding: UTF-8
109
115
  string: "{\n\t\"prices\" : [\n\t\t{\n\t\t\t\"instrument\" : \"EUR_USD\",\n\t\t\t\"time\"
110
- : \"2015-09-11T20:41:29.948985Z\",\n\t\t\t\"bid\" : 1.24115,\n\t\t\t\"ask\"
111
- : 1.24128\n\t\t}\n\t]\n}"
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}"
112
118
  http_version:
113
- recorded_at: Fri, 11 Sep 2015 20:41:30 GMT
119
+ recorded_at: Mon, 14 Mar 2016 16:28:51 GMT
114
120
  - request:
115
121
  method: get
116
- uri: http://api-sandbox.oanda.com/v1/prices?instruments=EUR_USD&username=dwaymotim
122
+ uri: https://api-fxpractice.oanda.com/v1/prices?instruments=EUR_USD
117
123
  body:
118
124
  encoding: US-ASCII
119
125
  string: ''
120
126
  headers:
121
127
  X-Accept-Datetime-Format:
122
128
  - RFC3339
129
+ Authorization:
130
+ - Bearer <OANDA_TESTING_API_TOKEN>
123
131
  Connection:
124
132
  - keep-alive
125
133
  Keep-Alive:
@@ -132,7 +140,7 @@ http_interactions:
132
140
  Server:
133
141
  - openresty/1.7.0.1
134
142
  Date:
135
- - Fri, 11 Sep 2015 20:41:30 GMT
143
+ - Mon, 14 Mar 2016 16:28:52 GMT
136
144
  Content-Type:
137
145
  - application/json
138
146
  Content-Length:
@@ -140,23 +148,25 @@ http_interactions:
140
148
  Connection:
141
149
  - keep-alive
142
150
  Etag:
143
- - '"f481d760a871b4f679207cd0715bd4be8271f399"'
151
+ - '"50c652cb079cb183ec34718d3760fd9f07cd9948"'
144
152
  body:
145
153
  encoding: UTF-8
146
154
  string: "{\n\t\"prices\" : [\n\t\t{\n\t\t\t\"instrument\" : \"EUR_USD\",\n\t\t\t\"time\"
147
- : \"2015-09-11T20:41:29.948985Z\",\n\t\t\t\"bid\" : 1.24115,\n\t\t\t\"ask\"
148
- : 1.24128\n\t\t}\n\t]\n}"
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}"
149
157
  http_version:
150
- recorded_at: Fri, 11 Sep 2015 20:41:30 GMT
158
+ recorded_at: Mon, 14 Mar 2016 16:28:52 GMT
151
159
  - request:
152
160
  method: get
153
- uri: http://api-sandbox.oanda.com/v1/prices?instruments=EUR_USD&username=dwaymotim
161
+ uri: https://api-fxpractice.oanda.com/v1/prices?instruments=EUR_USD
154
162
  body:
155
163
  encoding: US-ASCII
156
164
  string: ''
157
165
  headers:
158
166
  X-Accept-Datetime-Format:
159
167
  - RFC3339
168
+ Authorization:
169
+ - Bearer <OANDA_TESTING_API_TOKEN>
160
170
  Connection:
161
171
  - keep-alive
162
172
  Keep-Alive:
@@ -169,7 +179,7 @@ http_interactions:
169
179
  Server:
170
180
  - openresty/1.7.0.1
171
181
  Date:
172
- - Fri, 11 Sep 2015 20:41:30 GMT
182
+ - Mon, 14 Mar 2016 16:28:53 GMT
173
183
  Content-Type:
174
184
  - application/json
175
185
  Content-Length:
@@ -177,23 +187,25 @@ http_interactions:
177
187
  Connection:
178
188
  - keep-alive
179
189
  Etag:
180
- - '"f481d760a871b4f679207cd0715bd4be8271f399"'
190
+ - '"50c652cb079cb183ec34718d3760fd9f07cd9948"'
181
191
  body:
182
192
  encoding: UTF-8
183
193
  string: "{\n\t\"prices\" : [\n\t\t{\n\t\t\t\"instrument\" : \"EUR_USD\",\n\t\t\t\"time\"
184
- : \"2015-09-11T20:41:29.948985Z\",\n\t\t\t\"bid\" : 1.24115,\n\t\t\t\"ask\"
185
- : 1.24128\n\t\t}\n\t]\n}"
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}"
186
196
  http_version:
187
- recorded_at: Fri, 11 Sep 2015 20:41:30 GMT
197
+ recorded_at: Mon, 14 Mar 2016 16:28:53 GMT
188
198
  - request:
189
199
  method: get
190
- uri: http://api-sandbox.oanda.com/v1/prices?instruments=EUR_USD&username=dwaymotim
200
+ uri: https://api-fxpractice.oanda.com/v1/prices?instruments=EUR_USD
191
201
  body:
192
202
  encoding: US-ASCII
193
203
  string: ''
194
204
  headers:
195
205
  X-Accept-Datetime-Format:
196
206
  - RFC3339
207
+ Authorization:
208
+ - Bearer <OANDA_TESTING_API_TOKEN>
197
209
  Connection:
198
210
  - keep-alive
199
211
  Keep-Alive:
@@ -206,7 +218,7 @@ http_interactions:
206
218
  Server:
207
219
  - openresty/1.7.0.1
208
220
  Date:
209
- - Fri, 11 Sep 2015 20:41:30 GMT
221
+ - Mon, 14 Mar 2016 16:28:54 GMT
210
222
  Content-Type:
211
223
  - application/json
212
224
  Content-Length:
@@ -214,23 +226,25 @@ http_interactions:
214
226
  Connection:
215
227
  - keep-alive
216
228
  Etag:
217
- - '"f481d760a871b4f679207cd0715bd4be8271f399"'
229
+ - '"50c652cb079cb183ec34718d3760fd9f07cd9948"'
218
230
  body:
219
231
  encoding: UTF-8
220
232
  string: "{\n\t\"prices\" : [\n\t\t{\n\t\t\t\"instrument\" : \"EUR_USD\",\n\t\t\t\"time\"
221
- : \"2015-09-11T20:41:29.948985Z\",\n\t\t\t\"bid\" : 1.24115,\n\t\t\t\"ask\"
222
- : 1.24128\n\t\t}\n\t]\n}"
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}"
223
235
  http_version:
224
- recorded_at: Fri, 11 Sep 2015 20:41:30 GMT
236
+ recorded_at: Mon, 14 Mar 2016 16:28:54 GMT
225
237
  - request:
226
238
  method: get
227
- uri: http://api-sandbox.oanda.com/v1/prices?instruments=EUR_USD&username=dwaymotim
239
+ uri: https://api-fxpractice.oanda.com/v1/prices?instruments=EUR_USD
228
240
  body:
229
241
  encoding: US-ASCII
230
242
  string: ''
231
243
  headers:
232
244
  X-Accept-Datetime-Format:
233
245
  - RFC3339
246
+ Authorization:
247
+ - Bearer <OANDA_TESTING_API_TOKEN>
234
248
  Connection:
235
249
  - keep-alive
236
250
  Keep-Alive:
@@ -243,7 +257,7 @@ http_interactions:
243
257
  Server:
244
258
  - openresty/1.7.0.1
245
259
  Date:
246
- - Fri, 11 Sep 2015 20:41:30 GMT
260
+ - Mon, 14 Mar 2016 16:28:55 GMT
247
261
  Content-Type:
248
262
  - application/json
249
263
  Content-Length:
@@ -251,23 +265,25 @@ http_interactions:
251
265
  Connection:
252
266
  - keep-alive
253
267
  Etag:
254
- - '"f481d760a871b4f679207cd0715bd4be8271f399"'
268
+ - '"50c652cb079cb183ec34718d3760fd9f07cd9948"'
255
269
  body:
256
270
  encoding: UTF-8
257
271
  string: "{\n\t\"prices\" : [\n\t\t{\n\t\t\t\"instrument\" : \"EUR_USD\",\n\t\t\t\"time\"
258
- : \"2015-09-11T20:41:29.948985Z\",\n\t\t\t\"bid\" : 1.24115,\n\t\t\t\"ask\"
259
- : 1.24128\n\t\t}\n\t]\n}"
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}"
260
274
  http_version:
261
- recorded_at: Fri, 11 Sep 2015 20:41:30 GMT
275
+ recorded_at: Mon, 14 Mar 2016 16:28:55 GMT
262
276
  - request:
263
277
  method: get
264
- uri: http://api-sandbox.oanda.com/v1/prices?instruments=EUR_USD&username=dwaymotim
278
+ uri: https://api-fxpractice.oanda.com/v1/prices?instruments=EUR_USD
265
279
  body:
266
280
  encoding: US-ASCII
267
281
  string: ''
268
282
  headers:
269
283
  X-Accept-Datetime-Format:
270
284
  - RFC3339
285
+ Authorization:
286
+ - Bearer <OANDA_TESTING_API_TOKEN>
271
287
  Connection:
272
288
  - keep-alive
273
289
  Keep-Alive:
@@ -280,7 +296,7 @@ http_interactions:
280
296
  Server:
281
297
  - openresty/1.7.0.1
282
298
  Date:
283
- - Fri, 11 Sep 2015 20:41:30 GMT
299
+ - Mon, 14 Mar 2016 16:28:56 GMT
284
300
  Content-Type:
285
301
  - application/json
286
302
  Content-Length:
@@ -288,23 +304,25 @@ http_interactions:
288
304
  Connection:
289
305
  - keep-alive
290
306
  Etag:
291
- - '"f481d760a871b4f679207cd0715bd4be8271f399"'
307
+ - '"50c652cb079cb183ec34718d3760fd9f07cd9948"'
292
308
  body:
293
309
  encoding: UTF-8
294
310
  string: "{\n\t\"prices\" : [\n\t\t{\n\t\t\t\"instrument\" : \"EUR_USD\",\n\t\t\t\"time\"
295
- : \"2015-09-11T20:41:29.948985Z\",\n\t\t\t\"bid\" : 1.24115,\n\t\t\t\"ask\"
296
- : 1.24128\n\t\t}\n\t]\n}"
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}"
297
313
  http_version:
298
- recorded_at: Fri, 11 Sep 2015 20:41:30 GMT
314
+ recorded_at: Mon, 14 Mar 2016 16:28:56 GMT
299
315
  - request:
300
316
  method: get
301
- uri: http://api-sandbox.oanda.com/v1/prices?instruments=EUR_USD&username=dwaymotim
317
+ uri: https://api-fxpractice.oanda.com/v1/prices?instruments=EUR_USD
302
318
  body:
303
319
  encoding: US-ASCII
304
320
  string: ''
305
321
  headers:
306
322
  X-Accept-Datetime-Format:
307
323
  - RFC3339
324
+ Authorization:
325
+ - Bearer <OANDA_TESTING_API_TOKEN>
308
326
  Connection:
309
327
  - keep-alive
310
328
  Keep-Alive:
@@ -317,7 +335,7 @@ http_interactions:
317
335
  Server:
318
336
  - openresty/1.7.0.1
319
337
  Date:
320
- - Fri, 11 Sep 2015 20:41:30 GMT
338
+ - Mon, 14 Mar 2016 16:28:58 GMT
321
339
  Content-Type:
322
340
  - application/json
323
341
  Content-Length:
@@ -325,23 +343,25 @@ http_interactions:
325
343
  Connection:
326
344
  - keep-alive
327
345
  Etag:
328
- - '"f481d760a871b4f679207cd0715bd4be8271f399"'
346
+ - '"50c652cb079cb183ec34718d3760fd9f07cd9948"'
329
347
  body:
330
348
  encoding: UTF-8
331
349
  string: "{\n\t\"prices\" : [\n\t\t{\n\t\t\t\"instrument\" : \"EUR_USD\",\n\t\t\t\"time\"
332
- : \"2015-09-11T20:41:29.948985Z\",\n\t\t\t\"bid\" : 1.24115,\n\t\t\t\"ask\"
333
- : 1.24128\n\t\t}\n\t]\n}"
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}"
334
352
  http_version:
335
- recorded_at: Fri, 11 Sep 2015 20:41:30 GMT
353
+ recorded_at: Mon, 14 Mar 2016 16:28:57 GMT
336
354
  - request:
337
355
  method: get
338
- uri: http://api-sandbox.oanda.com/v1/prices?instruments=EUR_USD&username=dwaymotim
356
+ uri: https://api-fxpractice.oanda.com/v1/prices?instruments=EUR_USD
339
357
  body:
340
358
  encoding: US-ASCII
341
359
  string: ''
342
360
  headers:
343
361
  X-Accept-Datetime-Format:
344
362
  - RFC3339
363
+ Authorization:
364
+ - Bearer <OANDA_TESTING_API_TOKEN>
345
365
  Connection:
346
366
  - keep-alive
347
367
  Keep-Alive:
@@ -354,7 +374,7 @@ http_interactions:
354
374
  Server:
355
375
  - openresty/1.7.0.1
356
376
  Date:
357
- - Fri, 11 Sep 2015 20:41:30 GMT
377
+ - Mon, 14 Mar 2016 16:28:59 GMT
358
378
  Content-Type:
359
379
  - application/json
360
380
  Content-Length:
@@ -362,12 +382,12 @@ http_interactions:
362
382
  Connection:
363
383
  - keep-alive
364
384
  Etag:
365
- - '"f481d760a871b4f679207cd0715bd4be8271f399"'
385
+ - '"50c652cb079cb183ec34718d3760fd9f07cd9948"'
366
386
  body:
367
387
  encoding: UTF-8
368
388
  string: "{\n\t\"prices\" : [\n\t\t{\n\t\t\t\"instrument\" : \"EUR_USD\",\n\t\t\t\"time\"
369
- : \"2015-09-11T20:41:29.948985Z\",\n\t\t\t\"bid\" : 1.24115,\n\t\t\t\"ask\"
370
- : 1.24128\n\t\t}\n\t]\n}"
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}"
371
391
  http_version:
372
- recorded_at: Fri, 11 Sep 2015 20:41:30 GMT
373
- recorded_with: VCR 2.9.3
392
+ recorded_at: Mon, 14 Mar 2016 16:28:58 GMT
393
+ recorded_with: VCR 3.0.1
@@ -1,6 +1,7 @@
1
1
  require 'spec_helper'
2
2
  require 'uri'
3
3
  require 'webmock/rspec'
4
+ require 'support/client_helper'
4
5
 
5
6
  describe "OandaAPI::Client" do
6
7
  describe ".query_string_normalizer" do
@@ -66,16 +67,28 @@ describe "OandaAPI::Client" do
66
67
  end
67
68
  expect(OandaAPI::Client.last_throttled_at).to be > before_throttled_at
68
69
  end
70
+ it "tracks the time the last request was issued" do
71
+ OandaAPI.configuration.use_request_throttling = true
72
+ before_throttled_at = Time.now
73
+ (OandaAPI.configuration.max_requests_per_second + 2).times do
74
+ OandaAPI::Client.throttle_request_rate
75
+ end
76
+ expect(OandaAPI::Client.last_request_at).to be > before_throttled_at
77
+
78
+ end
79
+
69
80
  end
70
81
  end
71
82
 
72
83
  describe "#api_uri" do
73
84
  let(:client) { Struct.new(:domain) { include OandaAPI::Client }.new }
85
+ let(:resource_descriptor) {OandaAPI::Client::ResourceDescriptor.new "/accounts", :get}
86
+
74
87
  it "is domain specific" do
75
88
  uris = {}
76
89
  OandaAPI::DOMAINS.each do |domain|
77
90
  client.domain = domain
78
- uris[client.api_uri("/path")] = domain
91
+ uris[client.api_uri(resource_descriptor)] = domain
79
92
  end
80
93
  expect(uris.size).to eq(3)
81
94
  end
@@ -83,7 +96,7 @@ describe "OandaAPI::Client" do
83
96
  it "is an absolute URI" do
84
97
  OandaAPI::DOMAINS.each do |domain|
85
98
  client.domain = domain
86
- uri = URI.parse client.api_uri("/path")
99
+ uri = URI.parse client.api_uri(resource_descriptor)
87
100
  expect(uri.absolute?).to be true
88
101
  end
89
102
  end
@@ -93,7 +106,7 @@ describe "OandaAPI::Client" do
93
106
  let(:client) { (Class.new { include OandaAPI::Client }).new }
94
107
 
95
108
  it "is called by the constructor of an including class" do
96
- OandaAPI::Client.default_options[:connection_adapter] = nil
109
+ OandaAPI::Client.default_options[:connection_adapter] = nil
97
110
  expect(OandaAPI::Client.default_options[:connection_adapter]).to be_nil
98
111
 
99
112
  klass = Class.new { include OandaAPI::Client }
@@ -104,30 +117,30 @@ describe "OandaAPI::Client" do
104
117
  expect(OandaAPI::Client.default_options[:connection_adapter_options][:keep_alive]).to eq 20
105
118
  end
106
119
 
107
- it "loads a persistent connection adapter" do
108
- OandaAPI::Client.default_options[:connection_adapter] = nil
120
+ it "loads a persistent connection adapter" do
121
+ OandaAPI::Client.default_options[:connection_adapter] = nil
109
122
  expect(OandaAPI::Client.default_options[:connection_adapter]).to be_nil
110
123
  client.load_persistent_connection_adapter keep_alive: 30
111
124
  expect(OandaAPI::Client.default_options[:connection_adapter]).to be_a HTTParty::Persistent::ConnectionAdapter
112
125
  end
113
126
 
114
- it "overrides a persistent connection adapter settings" do
127
+ it "overrides a persistent connection adapter settings" do
115
128
  client.load_persistent_connection_adapter pool_size: OandaAPI.configuration.connection_pool_size + 1
116
129
  expect(OandaAPI::Client.default_options[:connection_adapter_options][:pool_size]).to eq OandaAPI.configuration.connection_pool_size + 1
117
130
  end
118
131
  end
119
-
132
+
120
133
  describe "#execute_request" do
121
- let(:client) { OandaAPI::Client::UsernameClient.new "spongebob" }
134
+ let(:client) { ClientHelper.client }
122
135
 
123
136
  it "returns a response for a successful request" do
124
- stub_request(:get, "http://api-sandbox.oanda.com/v1/accounts?username=spongebob")
137
+ stub_request(:get, "https://api-fxpractice.oanda.com/v1/accounts")
125
138
  .to_return(status: 200, body: "{\"accounts\" : []}", headers: { "content-type" => "application/json" })
126
139
  expect(client.execute_request(:get, "/accounts")).to be_an OandaAPI::ResourceCollection
127
140
  end
128
141
 
129
142
  it "raises OandaAPI::RequestError for an invalid request" do
130
- stub_request(:get, "http://api-sandbox.oanda.com/v1/accounts/a_bad_request?username=spongebob")
143
+ stub_request(:get, "https://api-fxpractice.oanda.com/v1/accounts/a_bad_request")
131
144
  .to_return(status: [404, "Something bad happened (but we still love you)."])
132
145
  expect { client.execute_request :get, "/accounts/a_bad_request" }.to raise_error(OandaAPI::RequestError)
133
146
  end