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
@@ -10,15 +10,15 @@ describe "OandaAPI::Resource::Labs::SpreadHistory" do
10
10
  expect(spread_history).to be_an OandaAPI::Resource::Labs::SpreadHistory
11
11
 
12
12
  expect(spread_history.averages.first.spread).to be_a Numeric
13
- expect(spread_history.averages.first.timestamp).to be_a Fixnum
13
+ expect(spread_history.averages.first.timestamp).to be_a Integer
14
14
  expect(spread_history.averages.first.time).to be_a Time
15
15
 
16
16
  expect(spread_history.maximums.first.spread).to be_a Numeric
17
- expect(spread_history.maximums.first.timestamp).to be_a Fixnum
17
+ expect(spread_history.maximums.first.timestamp).to be_a Integer
18
18
  expect(spread_history.maximums.first.time).to be_a Time
19
19
 
20
20
  expect(spread_history.minimums.first.spread).to be_a Numeric
21
- expect(spread_history.minimums.first.timestamp).to be_a Fixnum
21
+ expect(spread_history.minimums.first.timestamp).to be_a Integer
22
22
  expect(spread_history.minimums.first.time).to be_a Time
23
23
  end
24
24
  end
@@ -44,6 +44,15 @@ describe "OandaAPI::ResourceCollection" do
44
44
  expect(resource_collection.extra).to eq "I'm special"
45
45
  end
46
46
  end
47
+
48
+ describe "with location argument" do
49
+ let(:resource_collection) { OandaAPI::ResourceCollection.new({ candles: []}, resource_descriptor, location: "/some/resource/id" ) }
50
+
51
+ it "has a location accessor" do
52
+ expect(resource_collection.location).to eq "/some/resource/id"
53
+ end
54
+ end
55
+
47
56
  end
48
57
 
49
58
  context "without the collection attribute expected by the resource descriptor " do
@@ -79,15 +79,15 @@ describe "OandaAPI::Streaming::Client" do
79
79
  events_json = <<-END
80
80
  {"heartbeat":{"time":"2014-05-26T13:58:40Z"}}\r\n
81
81
  {"transaction":{"id":10001}}\r\n
82
- {"transaction":{"id":10002}}
82
+ {"transaction":{"id":10002}}\r\n
83
83
  END
84
84
 
85
85
  client = OandaAPI::Streaming::Client.new(:practice, "token")
86
86
  stub_request(:get, "https://stream-fxpractice.oanda.com/v1/events").to_return(body: events_json, status: 200)
87
-
87
+
88
88
  [{emit_heartbeats: true, heartbeats: 1, non_heartbeats: 2},
89
89
  {emit_heartbeats: false, heartbeats: 0, non_heartbeats: 2}].each do |test|
90
-
90
+
91
91
  client.emit_heartbeats = test[:emit_heartbeats]
92
92
  heartbeats = non_heartbeats = 0
93
93
  client.events.stream do |resource|
@@ -115,7 +115,7 @@ describe "OandaAPI::Streaming::Client" do
115
115
  events_json = <<-END
116
116
  {"heartbeat":{"time":"2014-05-26T13:58:40Z"}}\r\n
117
117
  {"transaction":{"id":10001}}\r\n
118
- {"transaction":{"id":10002}}
118
+ {"transaction":{"id":10002}}\r\n
119
119
  END
120
120
  stub_request(:get, "https://stream-fxpractice.oanda.com/v1/events").to_return(body: events_json, status: 200)
121
121
 
@@ -131,7 +131,7 @@ describe "OandaAPI::Streaming::Client" do
131
131
  describe "#stop!" do
132
132
  events_json = <<-END
133
133
  {"transaction":{"id": 1}}\r\n
134
- {"transaction":{"id": 2}}
134
+ {"transaction":{"id": 2}}\r\n
135
135
  END
136
136
 
137
137
  context "without using #stop!" do
@@ -57,7 +57,7 @@ describe "OandaAPI::Streaming::Request" do
57
57
  it "yields all resources returned in the response stream" do
58
58
  events_json = <<-END
59
59
  {"transaction":{"id": 1}}\r\n
60
- {"transaction":{"id": 2}}
60
+ {"transaction":{"id": 2}}\r\n
61
61
  END
62
62
  ids = []
63
63
  stub_request(:any, /\.com/).to_return(body: events_json, status: 200)
@@ -75,7 +75,7 @@ describe "OandaAPI::Streaming::Request" do
75
75
  {"transaction":{"id": 1}}\r\n
76
76
  {"heartbeat":{"id" : 0}}\r\n
77
77
  {"transaction":{"id": 2}}\r\n
78
- {"heartbeat":{"id" : 0}}
78
+ {"heartbeat":{"id" : 0}}\r\n
79
79
  END
80
80
  ids = []
81
81
  stub_request(:any, /\.com/).to_return(body: events_json, status: 200)
@@ -92,7 +92,7 @@ describe "OandaAPI::Streaming::Request" do
92
92
  {"transaction":{"id": 1}}\r\n
93
93
  {"heartbeat":{"id" : 20}}\r\n
94
94
  {"transaction":{"id": 2}}\r\n
95
- {"heartbeat":{"id" : 30}}
95
+ {"heartbeat":{"id" : 30}}\r\n
96
96
  END
97
97
  transactions = []
98
98
  heartbeats = 0
@@ -115,7 +115,7 @@ describe "OandaAPI::Streaming::Request" do
115
115
  events_json = <<-END
116
116
  {"transaction":{"id": 1}}\r\n
117
117
  {"disconnect":{"code":60,"message":"Access Token connection limit exceeded"}}\r\n
118
- {"transaction":{"id": 2}}
118
+ {"transaction":{"id": 2}}\r\n
119
119
  END
120
120
 
121
121
  stub_request(:any, /\.com/).to_return(body: events_json, status: 200)
@@ -130,7 +130,7 @@ describe "OandaAPI::Streaming::Request" do
130
130
  events_json = <<-END
131
131
  {"transaction":{"id": 1}}\r\n
132
132
  {"sponge-bob":{"is": "awesome"}}\r\n
133
- {"transaction":{"id": 2}}
133
+ {"transaction":{"id": 2}}\r\n
134
134
  END
135
135
 
136
136
  stub_request(:any, /\.com/).to_return(body: events_json, status: 200)
@@ -144,7 +144,7 @@ describe "OandaAPI::Streaming::Request" do
144
144
  events_json = <<-END
145
145
  {"transaction":{"id": 1}}\r\n
146
146
  {"transaction":{"id": 2}}\r\n
147
- {"transaction":{"id": 3}}
147
+ {"transaction":{"id": 3}}\r\n
148
148
  END
149
149
  stub_request(:any, /\.com/).to_return(body: events_json, status: 200)
150
150
  ids = []
@@ -160,7 +160,7 @@ describe "OandaAPI::Streaming::Request" do
160
160
  events_json = <<-END
161
161
  {"heartbeat":{"id": 1}}\r\n
162
162
  {"heartbeat":{"id": 2}}\r\n
163
- {"heartbeat":{"id": 3}}
163
+ {"heartbeat":{"id": 3}}\r\n
164
164
  END
165
165
  stub_request(:any, /\.com/).to_return(body: events_json, status: 200)
166
166
  heartbeats = 0
@@ -175,7 +175,7 @@ describe "OandaAPI::Streaming::Request" do
175
175
 
176
176
  context "when the stream contains multiple undelimited objects" do
177
177
  events_json = <<-END
178
- {"tick":{"bid": 1}}{"tick":{"bid": 2}}\r\n{"tick":{"bid": 3}}
178
+ {"tick":{"bid": 1}}{"tick":{"bid": 2}}{"tick":{"bid": 3}}\r\n
179
179
  END
180
180
 
181
181
  it "yields all of the objects" do
@@ -196,5 +196,20 @@ describe "OandaAPI::Streaming::Request" do
196
196
  expect(ticks).to contain_exactly(1, 2, 3)
197
197
  end
198
198
  end
199
+
200
+ context "when the stream contains incomplete chunks" do
201
+ it "yields all of the objects grouping them", focus: true do
202
+ events_json = <<-END
203
+ {"tick":{"bid": 1}}\r\n{"ti\r\nck":{"bid": 2}}\r\n{"tick":{"b\r\nid": 3}}\r\n
204
+ END
205
+
206
+ stub_request(:any, /\.com/).to_return(body: events_json, status: 200)
207
+ ticks = []
208
+ streaming_request.stream do |resource|
209
+ ticks << resource.bid
210
+ end
211
+ expect(ticks).to contain_exactly(1, 2, 3)
212
+ end
213
+ end
199
214
  end
200
215
  end
@@ -1,9 +1,6 @@
1
1
  lib = File.expand_path("../../lib", __FILE__)
2
2
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
3
 
4
- require 'codeclimate-test-reporter'
5
- CodeClimate::TestReporter.start
6
-
7
4
  require 'simplecov'
8
5
  SimpleCov.start
9
6
 
@@ -2,8 +2,12 @@ require 'support/vcr'
2
2
 
3
3
  module ClientHelper
4
4
  # Returns a practice API client
5
- def self.client
6
- @client ||= OandaAPI::Client::TokenClient.new :practice, test_account_token
5
+ def self.client(force_new: false)
6
+ if force_new
7
+ OandaAPI::Client::TokenClient.new(:practice, test_account_token)
8
+ else
9
+ @client ||= OandaAPI::Client::TokenClient.new :practice, test_account_token
10
+ end
7
11
  end
8
12
 
9
13
  def self.test_account_token
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: oanda_api
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.5
4
+ version: 0.9.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dean Missikowski
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-03-29 00:00:00.000000000 Z
11
+ date: 2018-02-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: httparty
@@ -78,42 +78,42 @@ dependencies:
78
78
  requirements:
79
79
  - - "~>"
80
80
  - !ruby/object:Gem::Version
81
- version: '3.0'
81
+ version: '4.0'
82
82
  type: :development
83
83
  prerelease: false
84
84
  version_requirements: !ruby/object:Gem::Requirement
85
85
  requirements:
86
86
  - - "~>"
87
87
  - !ruby/object:Gem::Version
88
- version: '3.0'
88
+ version: '4.0'
89
89
  - !ruby/object:Gem::Dependency
90
90
  name: webmock
91
91
  requirement: !ruby/object:Gem::Requirement
92
92
  requirements:
93
93
  - - "~>"
94
94
  - !ruby/object:Gem::Version
95
- version: '1.24'
95
+ version: 3.2.1
96
96
  type: :development
97
97
  prerelease: false
98
98
  version_requirements: !ruby/object:Gem::Requirement
99
99
  requirements:
100
100
  - - "~>"
101
101
  - !ruby/object:Gem::Version
102
- version: '1.24'
102
+ version: 3.2.1
103
103
  - !ruby/object:Gem::Dependency
104
104
  name: yard
105
105
  requirement: !ruby/object:Gem::Requirement
106
106
  requirements:
107
107
  - - "~>"
108
108
  - !ruby/object:Gem::Version
109
- version: '0.8'
109
+ version: '0.9'
110
110
  type: :development
111
111
  prerelease: false
112
112
  version_requirements: !ruby/object:Gem::Requirement
113
113
  requirements:
114
114
  - - "~>"
115
115
  - !ruby/object:Gem::Version
116
- version: '0.8'
116
+ version: '0.9'
117
117
  description: " A simple ruby client that supports all of the Oanda REST API methods.
118
118
  Uses Oanda recommended best practices including persistent connections, compression,
119
119
  request rate throttling, SSL certificate verification."
@@ -124,6 +124,7 @@ extra_rdoc_files: []
124
124
  files:
125
125
  - ".gitignore"
126
126
  - ".rspec"
127
+ - ".travis.yml"
127
128
  - ".yardopts"
128
129
  - CHANGELOG.md
129
130
  - Gemfile
@@ -161,6 +162,7 @@ files:
161
162
  - lib/oanda_api/streaming/client.rb
162
163
  - lib/oanda_api/streaming/json_parser.rb
163
164
  - lib/oanda_api/streaming/request.rb
165
+ - lib/oanda_api/throttling/throttling.rb
164
166
  - lib/oanda_api/utils/utils.rb
165
167
  - lib/oanda_api/version.rb
166
168
  - oanda_api.gemspec
@@ -170,7 +172,6 @@ files:
170
172
  - spec/fixtures/vcr_cassettes/calendar_instrument_and_period_get.yml
171
173
  - spec/fixtures/vcr_cassettes/calendar_period_get.yml
172
174
  - spec/fixtures/vcr_cassettes/candles_options_get.yml
173
- - spec/fixtures/vcr_cassettes/client_helper_account.yml
174
175
  - spec/fixtures/vcr_cassettes/client_helper_accounts.yml
175
176
  - spec/fixtures/vcr_cassettes/instrument_EUR_USD.yml
176
177
  - spec/fixtures/vcr_cassettes/instrument_USD_JPY.yml
@@ -196,6 +197,7 @@ files:
196
197
  - spec/fixtures/vcr_cassettes/transaction_id_get.yml
197
198
  - spec/fixtures/vcr_cassettes/transactions_options_get.yml
198
199
  - spec/fixtures/vcr_cassettes/with_throttling_and_max_requests_per_second.yml
200
+ - spec/fixtures/vcr_cassettes/with_throttling_new_connections.yml
199
201
  - spec/fixtures/vcr_cassettes/with_throttling_with_multiple_threads.yml
200
202
  - spec/fixtures/vcr_cassettes/without_throttling.yml
201
203
  - spec/oanda_api/client/client_spec.rb
@@ -246,7 +248,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
246
248
  version: '0'
247
249
  requirements: []
248
250
  rubyforge_project:
249
- rubygems_version: 2.5.1
251
+ rubygems_version: 2.6.14
250
252
  signing_key:
251
253
  specification_version: 4
252
254
  summary: A ruby client for the Oanda REST API.
@@ -257,7 +259,6 @@ test_files:
257
259
  - spec/fixtures/vcr_cassettes/calendar_instrument_and_period_get.yml
258
260
  - spec/fixtures/vcr_cassettes/calendar_period_get.yml
259
261
  - spec/fixtures/vcr_cassettes/candles_options_get.yml
260
- - spec/fixtures/vcr_cassettes/client_helper_account.yml
261
262
  - spec/fixtures/vcr_cassettes/client_helper_accounts.yml
262
263
  - spec/fixtures/vcr_cassettes/instrument_EUR_USD.yml
263
264
  - spec/fixtures/vcr_cassettes/instrument_USD_JPY.yml
@@ -283,6 +284,7 @@ test_files:
283
284
  - spec/fixtures/vcr_cassettes/transaction_id_get.yml
284
285
  - spec/fixtures/vcr_cassettes/transactions_options_get.yml
285
286
  - spec/fixtures/vcr_cassettes/with_throttling_and_max_requests_per_second.yml
287
+ - spec/fixtures/vcr_cassettes/with_throttling_new_connections.yml
286
288
  - spec/fixtures/vcr_cassettes/with_throttling_with_multiple_threads.yml
287
289
  - spec/fixtures/vcr_cassettes/without_throttling.yml
288
290
  - spec/oanda_api/client/client_spec.rb
@@ -313,4 +315,3 @@ test_files:
313
315
  - spec/spec_helper.rb
314
316
  - spec/support/client_helper.rb
315
317
  - spec/support/vcr.rb
316
- has_rdoc:
@@ -1,45 +0,0 @@
1
- ---
2
- http_interactions:
3
- - request:
4
- method: get
5
- uri: https://api-fxpractice.oanda.com/v1/accounts
6
- body:
7
- encoding: US-ASCII
8
- string: ''
9
- headers:
10
- X-Accept-Datetime-Format:
11
- - RFC3339
12
- Authorization:
13
- - Bearer <OANDA_TESTING_API_TOKEN>
14
- Connection:
15
- - keep-alive
16
- Keep-Alive:
17
- - 30
18
- response:
19
- status:
20
- code: 200
21
- message: OK
22
- headers:
23
- Server:
24
- - openresty/1.7.0.1
25
- Date:
26
- - Mon, 14 Mar 2016 18:52:24 GMT
27
- Content-Type:
28
- - application/json
29
- Content-Length:
30
- - '366'
31
- Connection:
32
- - keep-alive
33
- Etag:
34
- - '"efb224b14d5e6c03ab1a19a9983274e09d124b20"'
35
- body:
36
- encoding: UTF-8
37
- string: "{\n\t\"accounts\" : [\n\t\t{\n\t\t\t\"accountId\" : 1871900,\n\t\t\t\"accountName\"
38
- : \"Primary\",\n\t\t\t\"accountCurrency\" : \"USD\",\n\t\t\t\"marginRate\"
39
- : 0.05\n\t\t},\n\t\t{\n\t\t\t\"accountId\" : 1401515,\n\t\t\t\"accountName\"
40
- : \"USD\",\n\t\t\t\"accountCurrency\" : \"USD\",\n\t\t\t\"marginRate\" : 0.1\n\t\t},\n\t\t{\n\t\t\t\"accountId\"
41
- : 5094848,\n\t\t\t\"accountName\" : \"WTI\",\n\t\t\t\"accountCurrency\" :
42
- \"CAD\",\n\t\t\t\"marginRate\" : 0.05\n\t\t}\n\t]\n}"
43
- http_version:
44
- recorded_at: Mon, 14 Mar 2016 18:52:25 GMT
45
- recorded_with: VCR 2.9.3