oanda_api_v20 1.0.0 → 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.ruby-version +1 -0
- data/.travis.yml +3 -0
- data/CHANGELOG.md +4 -0
- data/README.md +28 -18
- data/Rakefile +6 -0
- data/lib/oanda_api_v20/accounts.rb +4 -2
- data/lib/oanda_api_v20/positions.rb +1 -0
- data/lib/oanda_api_v20/version.rb +1 -1
- data/oanda_api_v20.gemspec +1 -0
- data/spec/oanda_api_v20/api_spec.rb +304 -0
- data/spec/oanda_api_v20/client_spec.rb +66 -27
- metadata +21 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9fea2b5abda5730c36fa1d535c0de33c82f96c3d
|
4
|
+
data.tar.gz: ea80f60cd1263e3eb80e12d3715a052d9b08ab17
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ea0776c3df49196324f703632f6090b39fe4d203f3931872b927e086292aa9719abaf5f4ce64db56d7890cc611fe07f81eabdbc85b832a64c1b01dc34b2d6eab
|
7
|
+
data.tar.gz: 9e9a3fa546f6d3a6f47283b3cbeb2c18f8c096fb1a2d6d3992a77bcbd12ff4c5f68f5faaf4106b9fc5364c50998f507e7e51bf223a3de304c3b9449223d5e559
|
data/.ruby-version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
2.3.1
|
data/.travis.yml
ADDED
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
# OandaApiV20
|
2
2
|
|
3
3
|
[![Gem Version](https://badge.fury.io/rb/oanda_api_v20.svg)](https://rubygems.org/gems/oanda_api_v20)
|
4
|
+
[![Build Status](https://travis-ci.org/kobusjoubert/oanda_api_v20.svg?branch=master)](https://travis-ci.org/kobusjoubert/oanda_api_v20)
|
4
5
|
|
5
6
|
Ruby client that supports the Oanda REST API V20 methods.
|
6
7
|
|
@@ -54,6 +55,10 @@ client.account('account_id').summary.show
|
|
54
55
|
client.account('account_id').instruments.show
|
55
56
|
```
|
56
57
|
|
58
|
+
```ruby
|
59
|
+
client.account('account_id').instruments('EUR_USD,EUR_CAD').show
|
60
|
+
```
|
61
|
+
|
57
62
|
```ruby
|
58
63
|
client.account('account_id').changes.show
|
59
64
|
```
|
@@ -110,6 +115,18 @@ client.account('account_id').order(id, options).update
|
|
110
115
|
```ruby
|
111
116
|
id = client.account('account_id').orders.show['orders'][0]['id']
|
112
117
|
|
118
|
+
options = {
|
119
|
+
'clientExtensions' => {
|
120
|
+
'comment' => 'New comment for my limit order'
|
121
|
+
}
|
122
|
+
}
|
123
|
+
|
124
|
+
client.account('account_id').order(id, options).update
|
125
|
+
```
|
126
|
+
|
127
|
+
```ruby
|
128
|
+
id = client.account('account_id').orders.show['orders'][0]['id']
|
129
|
+
|
113
130
|
client.account('account_id').order(id).cancel
|
114
131
|
```
|
115
132
|
|
@@ -137,10 +154,13 @@ client.account('account_id').trade(id).show
|
|
137
154
|
id = client.account('account_id').open_trades.show['trades'][0]['id']
|
138
155
|
|
139
156
|
options = {
|
140
|
-
'
|
141
|
-
'
|
142
|
-
'
|
143
|
-
|
157
|
+
'takeProfit' => {
|
158
|
+
'timeInForce' => 'GTC',
|
159
|
+
'price' => '0.5'
|
160
|
+
},
|
161
|
+
'stopLoss' => {
|
162
|
+
'timeInForce' => 'GTC',
|
163
|
+
'price' => '2.5'
|
144
164
|
}
|
145
165
|
}
|
146
166
|
|
@@ -151,13 +171,10 @@ client.account('account_id').trade(id, options).update
|
|
151
171
|
id = client.account('account_id').open_trades.show['trades'][0]['id']
|
152
172
|
|
153
173
|
options = {
|
154
|
-
'
|
155
|
-
'
|
156
|
-
'
|
157
|
-
|
158
|
-
'stopLoss' => {
|
159
|
-
'timeInForce' => 'GTC',
|
160
|
-
'price' => '2.5'
|
174
|
+
'clientExtensions' => {
|
175
|
+
'comment' => 'This is a USD/CAD trade',
|
176
|
+
'tag' => 'trade tag',
|
177
|
+
'id' => 'my_usd_cad_trade'
|
161
178
|
}
|
162
179
|
}
|
163
180
|
|
@@ -263,10 +280,3 @@ A `OandaApiV20::RequestError` will be raised when a request to the Oanda API fai
|
|
263
280
|
3. Commit your changes (`git commit -am 'Add some feature'`)
|
264
281
|
4. Push to the branch (`git push origin my-new-feature`)
|
265
282
|
5. Create new Pull Request
|
266
|
-
|
267
|
-
## TODO
|
268
|
-
|
269
|
-
There are still a lot to be added to this gem:
|
270
|
-
|
271
|
-
- Unit tests using RSpec.
|
272
|
-
- ...
|
data/Rakefile
ADDED
@@ -17,8 +17,10 @@ module OandaApiV20
|
|
17
17
|
end
|
18
18
|
|
19
19
|
# GET /v3/accounts/:account_id/instruments
|
20
|
-
def instruments
|
21
|
-
|
20
|
+
def instruments(instruments = nil)
|
21
|
+
arguments = { headers: headers }
|
22
|
+
arguments.merge!(query: { instruments: instruments }) if instruments
|
23
|
+
Client.send(http_verb, "#{base_uri}/accounts/#{account_id}/instruments", arguments)
|
22
24
|
end
|
23
25
|
|
24
26
|
# GET /v3/accounts/:account_id/changes
|
data/oanda_api_v20.gemspec
CHANGED
@@ -23,6 +23,7 @@ Gem::Specification.new do |s|
|
|
23
23
|
s.add_development_dependency 'rspec', '~> 3.4'
|
24
24
|
s.add_development_dependency 'webmock', '~> 2.1'
|
25
25
|
s.add_development_dependency 'timecop', '~> 0.8'
|
26
|
+
s.add_development_dependency 'rake'
|
26
27
|
|
27
28
|
s.files = `git ls-files`.split("\n")
|
28
29
|
s.test_files = s.files.grep(%r{^(test|spec|features)/})
|
@@ -0,0 +1,304 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe OandaApiV20::Api do
|
4
|
+
describe '#initialize' do
|
5
|
+
it 'sets the http_verb attribute when supplied' do
|
6
|
+
api = OandaApiV20::Api.new(http_verb: :post)
|
7
|
+
expect(api.http_verb).to eq(:post)
|
8
|
+
end
|
9
|
+
|
10
|
+
it 'sets the base_uri attribute when supplied' do
|
11
|
+
url = 'https://api-fxpractice.oanda.com/v3'
|
12
|
+
api = OandaApiV20::Api.new(base_uri: url)
|
13
|
+
expect(api.base_uri).to eq(url)
|
14
|
+
end
|
15
|
+
|
16
|
+
it 'sets the headers attribute when supplied' do
|
17
|
+
headers = { 'Content-Type' => 'application/json', 'Connection' => 'keep-alive', 'Keep-Alive' => '30' }
|
18
|
+
api = OandaApiV20::Api.new(headers: headers)
|
19
|
+
expect(api.headers).to eq(headers)
|
20
|
+
end
|
21
|
+
|
22
|
+
it 'sets the account_id attribute when supplied' do
|
23
|
+
account_id = '100-100-100'
|
24
|
+
api = OandaApiV20::Api.new(account_id: account_id)
|
25
|
+
expect(api.account_id).to eq(account_id)
|
26
|
+
end
|
27
|
+
|
28
|
+
it 'sets the last_transaction_id attribute when supplied' do
|
29
|
+
last_transaction_id = '1'
|
30
|
+
api = OandaApiV20::Api.new(last_transaction_id: last_transaction_id)
|
31
|
+
expect(api.last_transaction_id).to eq(last_transaction_id)
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
describe '#public_methods' do
|
36
|
+
let!(:api) { OandaApiV20::Api.new }
|
37
|
+
let(:public_methods) { [
|
38
|
+
:account, :accounts, :summary, :instruments, :changes, :configuration,
|
39
|
+
:order, :orders, :pending_orders,
|
40
|
+
:trade, :trades, :open_trades,
|
41
|
+
:position, :positions, :open_positions,
|
42
|
+
:transaction, :transactions, :transactions_id_range, :transactions_since_id,
|
43
|
+
:pricing
|
44
|
+
] }
|
45
|
+
|
46
|
+
it 'responds to all public methods' do
|
47
|
+
public_methods.each do |public_method|
|
48
|
+
expect(api.respond_to?(public_method)).to be_truthy
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
describe 'constructs the correct API URL under' do
|
54
|
+
let!(:api) { OandaApiV20::Api.new(base_uri: 'https://api-fxtrade.oanda.com/v3', account_id: '100-100-100', headers: {}) }
|
55
|
+
|
56
|
+
before(:each) do
|
57
|
+
stub_request(:any, /https:\/\/api-fxtrade\.oanda\.com\/v3.*/)
|
58
|
+
api.http_verb = :get
|
59
|
+
end
|
60
|
+
|
61
|
+
context 'accounts for' do
|
62
|
+
it 'retrieving an account' do
|
63
|
+
api.account('100-100-100')
|
64
|
+
expect(a_request(:get, 'https://api-fxtrade.oanda.com/v3/accounts/100-100-100')).to have_been_made.once
|
65
|
+
end
|
66
|
+
|
67
|
+
it 'retrieving all accounts' do
|
68
|
+
api.accounts
|
69
|
+
expect(a_request(:get, 'https://api-fxtrade.oanda.com/v3/accounts')).to have_been_made.once
|
70
|
+
end
|
71
|
+
|
72
|
+
it 'retrieving a summary' do
|
73
|
+
api.summary
|
74
|
+
expect(a_request(:get, 'https://api-fxtrade.oanda.com/v3/accounts/100-100-100/summary')).to have_been_made.once
|
75
|
+
end
|
76
|
+
|
77
|
+
it 'retrieving all instruments' do
|
78
|
+
api.instruments
|
79
|
+
expect(a_request(:get, 'https://api-fxtrade.oanda.com/v3/accounts/100-100-100/instruments')).to have_been_made.once
|
80
|
+
end
|
81
|
+
|
82
|
+
it 'retrieving an instrument' do
|
83
|
+
api.instruments('EUR_USD')
|
84
|
+
options = { 'instruments' => 'EUR_USD' }
|
85
|
+
expect(a_request(:get, 'https://api-fxtrade.oanda.com/v3/accounts/100-100-100/instruments').with(query: options)).to have_been_made.once
|
86
|
+
end
|
87
|
+
|
88
|
+
it 'retrieving all changes' do
|
89
|
+
api.last_transaction_id = '1'
|
90
|
+
api.changes
|
91
|
+
expect(a_request(:get, 'https://api-fxtrade.oanda.com/v3/accounts/100-100-100/changes').with(query: { 'sinceTransactionID' => '1' })).to have_been_made.once
|
92
|
+
end
|
93
|
+
|
94
|
+
it 'updating a configuration' do
|
95
|
+
api.http_verb = :patch
|
96
|
+
options = { 'alias' => 'Timmy!' }
|
97
|
+
api.configuration(options)
|
98
|
+
expect(a_request(:patch, 'https://api-fxtrade.oanda.com/v3/accounts/100-100-100/configuration').with(body: options.to_json))
|
99
|
+
end
|
100
|
+
end
|
101
|
+
|
102
|
+
context 'orders for' do
|
103
|
+
it 'retrieving an order' do
|
104
|
+
api.order('1')
|
105
|
+
expect(a_request(:get, 'https://api-fxtrade.oanda.com/v3/accounts/100-100-100/orders/1')).to have_been_made.once
|
106
|
+
end
|
107
|
+
|
108
|
+
it 'creating an order' do
|
109
|
+
api.http_verb = :post
|
110
|
+
options = {
|
111
|
+
'order' => {
|
112
|
+
'units' => '100',
|
113
|
+
'instrument' => 'EUR_CAD',
|
114
|
+
'timeInForce' => 'FOK',
|
115
|
+
'type' => 'MARKET',
|
116
|
+
'positionFill' => 'DEFAULT'
|
117
|
+
}
|
118
|
+
}
|
119
|
+
api.order(options)
|
120
|
+
expect(a_request(:post, 'https://api-fxtrade.oanda.com/v3/accounts/100-100-100/orders').with(body: options.to_json)).to have_been_made.once
|
121
|
+
end
|
122
|
+
|
123
|
+
it 'updating an order' do
|
124
|
+
api.http_verb = :put
|
125
|
+
options = {
|
126
|
+
'order' => {
|
127
|
+
'timeInForce' => 'GTC',
|
128
|
+
'price' => '1.7000',
|
129
|
+
'type' => 'TAKE_PROFIT',
|
130
|
+
'tradeID' => '1'
|
131
|
+
}
|
132
|
+
}
|
133
|
+
api.order('1', options)
|
134
|
+
expect(a_request(:put, 'https://api-fxtrade.oanda.com/v3/accounts/100-100-100/orders/1').with(body: options.to_json)).to have_been_made.once
|
135
|
+
end
|
136
|
+
|
137
|
+
it 'updating an order client extensions' do
|
138
|
+
api.http_verb = :put
|
139
|
+
options = {
|
140
|
+
'clientExtensions' => {
|
141
|
+
'comment' => 'New comment for my limit order'
|
142
|
+
}
|
143
|
+
}
|
144
|
+
api.order('1', options)
|
145
|
+
expect(a_request(:put, 'https://api-fxtrade.oanda.com/v3/accounts/100-100-100/orders/1/clientExtensions').with(body: options.to_json)).to have_been_made.once
|
146
|
+
end
|
147
|
+
|
148
|
+
it 'cancelling an order' do
|
149
|
+
api.http_verb = :put
|
150
|
+
api.order('1')
|
151
|
+
expect(a_request(:put, 'https://api-fxtrade.oanda.com/v3/accounts/100-100-100/orders/1/cancel')).to have_been_made.once
|
152
|
+
end
|
153
|
+
|
154
|
+
it 'retrieving all orders' do
|
155
|
+
api.orders
|
156
|
+
expect(a_request(:get, 'https://api-fxtrade.oanda.com/v3/accounts/100-100-100/orders')).to have_been_made.once
|
157
|
+
end
|
158
|
+
|
159
|
+
it 'retrieving all pending orders' do
|
160
|
+
api.pending_orders
|
161
|
+
expect(a_request(:get, 'https://api-fxtrade.oanda.com/v3/accounts/100-100-100/pendingOrders')).to have_been_made.once
|
162
|
+
end
|
163
|
+
end
|
164
|
+
|
165
|
+
context 'trades for' do
|
166
|
+
it 'retrieving a trade' do
|
167
|
+
api.trade('1')
|
168
|
+
expect(a_request(:get, 'https://api-fxtrade.oanda.com/v3/accounts/100-100-100/trades/1')).to have_been_made.once
|
169
|
+
end
|
170
|
+
|
171
|
+
it 'updating a trade' do
|
172
|
+
api.http_verb = :put
|
173
|
+
options = {
|
174
|
+
'takeProfit' => {
|
175
|
+
'timeInForce' => 'GTC',
|
176
|
+
'price' => '0.5'
|
177
|
+
},
|
178
|
+
'stopLoss' => {
|
179
|
+
'timeInForce' => 'GTC',
|
180
|
+
'price' => '2.5'
|
181
|
+
}
|
182
|
+
}
|
183
|
+
api.trade('1', options)
|
184
|
+
expect(a_request(:put, 'https://api-fxtrade.oanda.com/v3/accounts/100-100-100/trades/1/orders').with(body: options.to_json)).to have_been_made.once
|
185
|
+
end
|
186
|
+
|
187
|
+
it 'updating a trade client extensions' do
|
188
|
+
api.http_verb = :put
|
189
|
+
options = {
|
190
|
+
'clientExtensions' => {
|
191
|
+
'comment' => 'This is a USD/CAD trade',
|
192
|
+
'tag' => 'trade tag',
|
193
|
+
'id' => 'my_usd_cad_trade'
|
194
|
+
}
|
195
|
+
}
|
196
|
+
api.trade('1', options)
|
197
|
+
expect(a_request(:put, 'https://api-fxtrade.oanda.com/v3/accounts/100-100-100/trades/1/clientExtensions').with(body: options.to_json)).to have_been_made.once
|
198
|
+
end
|
199
|
+
|
200
|
+
it 'closing a trade' do
|
201
|
+
api.http_verb = :put
|
202
|
+
api.trade('1')
|
203
|
+
expect(a_request(:put, 'https://api-fxtrade.oanda.com/v3/accounts/100-100-100/trades/1/close')).to have_been_made.once
|
204
|
+
end
|
205
|
+
|
206
|
+
it 'closing a trade partially' do
|
207
|
+
api.http_verb = :put
|
208
|
+
options = { 'units' => '10' }
|
209
|
+
api.trade('1', options)
|
210
|
+
expect(a_request(:put, 'https://api-fxtrade.oanda.com/v3/accounts/100-100-100/trades/1/close')).to have_been_made.once
|
211
|
+
end
|
212
|
+
|
213
|
+
it 'retrieving all trades' do
|
214
|
+
options = { 'instrument' => 'USD_CAD' }
|
215
|
+
api.trades(options)
|
216
|
+
expect(a_request(:get, 'https://api-fxtrade.oanda.com/v3/accounts/100-100-100/trades').with(query: options)).to have_been_made.once
|
217
|
+
end
|
218
|
+
|
219
|
+
it 'retrieving all open trades' do
|
220
|
+
api.open_trades
|
221
|
+
expect(a_request(:get, 'https://api-fxtrade.oanda.com/v3/accounts/100-100-100/openTrades')).to have_been_made.once
|
222
|
+
end
|
223
|
+
end
|
224
|
+
|
225
|
+
context 'positions for' do
|
226
|
+
it 'retrieving a position' do
|
227
|
+
api.position('EUR_USD')
|
228
|
+
expect(a_request(:get, 'https://api-fxtrade.oanda.com/v3/accounts/100-100-100/positions/EUR_USD')).to have_been_made.once
|
229
|
+
end
|
230
|
+
|
231
|
+
it 'retrieving all positions' do
|
232
|
+
api.positions
|
233
|
+
expect(a_request(:get, 'https://api-fxtrade.oanda.com/v3/accounts/100-100-100/positions')).to have_been_made.once
|
234
|
+
end
|
235
|
+
|
236
|
+
it 'retrieving all open positions' do
|
237
|
+
api.open_positions
|
238
|
+
expect(a_request(:get, 'https://api-fxtrade.oanda.com/v3/accounts/100-100-100/openPositions')).to have_been_made.once
|
239
|
+
end
|
240
|
+
|
241
|
+
it 'closing a position' do
|
242
|
+
api.http_verb = :put
|
243
|
+
options = { 'longUnits' => 'ALL' }
|
244
|
+
api.position('EUR_CAD', options)
|
245
|
+
expect(a_request(:put, 'https://api-fxtrade.oanda.com/v3/accounts/100-100-100/positions/EUR_CAD/close').with(body: options.to_json)).to have_been_made.once
|
246
|
+
end
|
247
|
+
|
248
|
+
it 'closing a position partially' do
|
249
|
+
api.http_verb = :put
|
250
|
+
options = { 'longUnits' => '99' }
|
251
|
+
api.position('EUR_CAD', options)
|
252
|
+
expect(a_request(:put, 'https://api-fxtrade.oanda.com/v3/accounts/100-100-100/positions/EUR_CAD/close').with(body: options.to_json)).to have_been_made.once
|
253
|
+
end
|
254
|
+
end
|
255
|
+
|
256
|
+
context 'transactions for' do
|
257
|
+
it 'retrieving a transaction' do
|
258
|
+
api.transaction('1')
|
259
|
+
expect(a_request(:get, 'https://api-fxtrade.oanda.com/v3/accounts/100-100-100/transactions/1')).to have_been_made.once
|
260
|
+
end
|
261
|
+
|
262
|
+
it 'retrieving all transactions' do
|
263
|
+
api.transactions
|
264
|
+
expect(a_request(:get, 'https://api-fxtrade.oanda.com/v3/accounts/100-100-100/transactions')).to have_been_made.once
|
265
|
+
end
|
266
|
+
|
267
|
+
it 'retrieving all transactions in date range' do
|
268
|
+
options = {
|
269
|
+
'from' => '2016-08-01T02:00:00Z',
|
270
|
+
'to' => '2016-08-15T02:00:00Z'
|
271
|
+
}
|
272
|
+
api.transactions(options)
|
273
|
+
expect(a_request(:get, 'https://api-fxtrade.oanda.com/v3/accounts/100-100-100/transactions').with(query: options)).to have_been_made.once
|
274
|
+
end
|
275
|
+
|
276
|
+
it 'retrieving all transactions in an id range' do
|
277
|
+
options = {
|
278
|
+
'from' => '6409',
|
279
|
+
'to' => '6412'
|
280
|
+
}
|
281
|
+
api.transactions_id_range(options)
|
282
|
+
expect(a_request(:get, 'https://api-fxtrade.oanda.com/v3/accounts/100-100-100/transactions/idrange').with(query: options)).to have_been_made.once
|
283
|
+
end
|
284
|
+
|
285
|
+
it 'retrieving all transactions since an id' do
|
286
|
+
options = {
|
287
|
+
'id' => '6411'
|
288
|
+
}
|
289
|
+
api.transactions_since_id(options)
|
290
|
+
expect(a_request(:get, 'https://api-fxtrade.oanda.com/v3/accounts/100-100-100/transactions/sinceid').with(query: options)).to have_been_made.once
|
291
|
+
end
|
292
|
+
end
|
293
|
+
|
294
|
+
context 'pricing for' do
|
295
|
+
it 'retrieving all pricing' do
|
296
|
+
options = {
|
297
|
+
'instruments' => 'EUR_USD,USD_CAD'
|
298
|
+
}
|
299
|
+
api.pricing(options)
|
300
|
+
expect(a_request(:get, 'https://api-fxtrade.oanda.com/v3/accounts/100-100-100/pricing').with(query: options)).to have_been_made.once
|
301
|
+
end
|
302
|
+
end
|
303
|
+
end
|
304
|
+
end
|
@@ -7,24 +7,29 @@ describe OandaApiV20::Client do
|
|
7
7
|
expect(c.access_token).to eq('my_access_token')
|
8
8
|
end
|
9
9
|
|
10
|
-
it 'sets the
|
10
|
+
it 'sets the base_uri to practice when the practice option was supplied and set to true' do
|
11
11
|
c = OandaApiV20::Client.new(practice: true)
|
12
12
|
expect(c.base_uri).to eq('https://api-fxpractice.oanda.com/v3')
|
13
13
|
end
|
14
14
|
|
15
|
-
it 'sets the
|
15
|
+
it 'sets the base_uri to live when the practice option was supplied and set to false' do
|
16
16
|
c = OandaApiV20::Client.new(practice: false)
|
17
17
|
expect(c.base_uri).to eq('https://api-fxtrade.oanda.com/v3')
|
18
18
|
end
|
19
19
|
|
20
|
-
it 'sets the
|
20
|
+
it 'sets the base_uri to live when the practice option was not supplied' do
|
21
21
|
c = OandaApiV20::Client.new
|
22
22
|
expect(c.base_uri).to eq('https://api-fxtrade.oanda.com/v3')
|
23
23
|
end
|
24
|
+
|
25
|
+
it 'set the headers attribute to a hash' do
|
26
|
+
c = OandaApiV20::Client.new
|
27
|
+
expect(c.send(:headers)).to be_an_instance_of(Hash)
|
28
|
+
end
|
24
29
|
end
|
25
30
|
|
26
31
|
describe '#method_missing' do
|
27
|
-
let(:c) { OandaApiV20::Client.new(access_token: 'my_access_token') }
|
32
|
+
let!(:c) { OandaApiV20::Client.new(access_token: 'my_access_token') }
|
28
33
|
|
29
34
|
context 'when an OandaApiV20::Api method has been called' do
|
30
35
|
it 'saves the method called' do
|
@@ -51,6 +56,7 @@ describe OandaApiV20::Client do
|
|
51
56
|
context 'when an action method has been called' do
|
52
57
|
let(:response_account) { '{"account":{"id":"100-100-100","NAV":"100000.0000","balance":"100000.0000","lastTransactionID":"99","orders":[],"positions":[],"trades":[],"pendingOrderCount":0},"lastTransactionID":"99"}' }
|
53
58
|
let!(:request_account) { stub_request(:get, 'https://api-fxtrade.oanda.com/v3/accounts/100-100-100').to_return(status: 200, body: response_account, headers: {}) }
|
59
|
+
|
54
60
|
let(:response_accounts) { '{"accounts":[{"id":"100-100-100","tags":[]}]}' }
|
55
61
|
let!(:request_accounts) { stub_request(:get, 'https://api-fxtrade.oanda.com/v3/accounts').to_return(status: 200, body: response_accounts, headers: {}) }
|
56
62
|
|
@@ -58,37 +64,70 @@ describe OandaApiV20::Client do
|
|
58
64
|
allow(c).to receive(:sleep)
|
59
65
|
end
|
60
66
|
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
67
|
+
describe 'network' do
|
68
|
+
it 'makes a request to Oanda API' do
|
69
|
+
c.accounts.show
|
70
|
+
expect(request_accounts).to have_been_requested
|
71
|
+
expect(request_accounts).to have_been_requested.at_most_once
|
72
|
+
end
|
65
73
|
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
74
|
+
it 'returns the response from Oanda API' do
|
75
|
+
expect(c.accounts.show).to eq(JSON.parse(response_accounts))
|
76
|
+
expect(c.account('100-100-100').show).to eq(JSON.parse(response_account))
|
77
|
+
end
|
70
78
|
end
|
71
79
|
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
80
|
+
describe 'attributes' do
|
81
|
+
it 'sets the equivalent HTTP verb' do
|
82
|
+
c.accounts.show
|
83
|
+
expect(c.send(:http_verb)).to eq(:get)
|
84
|
+
end
|
85
|
+
|
86
|
+
it 'sets the current account ID' do
|
87
|
+
c.account('100-100-100').show
|
88
|
+
expect(c.send(:account_id)).to eq('100-100-100')
|
89
|
+
end
|
76
90
|
|
77
|
-
|
78
|
-
|
79
|
-
|
91
|
+
it 'sets the last transaction ID when returned' do
|
92
|
+
c.account('100-100-100').show
|
93
|
+
expect(c.send(:last_transaction_id)).to eq('99')
|
94
|
+
end
|
95
|
+
|
96
|
+
it 'sets the last request made at time' do
|
97
|
+
expect(c.send(:last_api_request_at).last).to be_nil
|
98
|
+
c.accounts.show
|
99
|
+
expect(c.send(:last_api_request_at).last).to_not be_nil
|
100
|
+
expect(Time.parse(c.send(:last_api_request_at).last.to_s)).to be_an_instance_of(Time)
|
101
|
+
end
|
80
102
|
end
|
81
103
|
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
104
|
+
describe 'headers' do
|
105
|
+
it 'sets authentication header' do
|
106
|
+
c.accounts.show
|
107
|
+
expect(a_request(:get, 'https://api-fxtrade.oanda.com/v3/accounts').with(headers: { 'Authorization' => 'Bearer my_access_token' })).to have_been_made.once
|
108
|
+
end
|
109
|
+
|
110
|
+
it 'sets content type header to json' do
|
111
|
+
c.accounts.show
|
112
|
+
expect(a_request(:get, 'https://api-fxtrade.oanda.com/v3/accounts').with(headers: { 'Content-Type' => 'application/json' })).to have_been_made.once
|
113
|
+
end
|
114
|
+
|
115
|
+
it 'sets date time format header to RFC3339' do
|
116
|
+
c.accounts.show
|
117
|
+
expect(a_request(:get, 'https://api-fxtrade.oanda.com/v3/accounts').with(headers: { 'X-Accept-Datetime-Format' => 'RFC3339' })).to have_been_made.once
|
118
|
+
end
|
119
|
+
|
120
|
+
it 'sets persisten connection header' do
|
121
|
+
c.accounts.show
|
122
|
+
expect(a_request(:get, 'https://api-fxtrade.oanda.com/v3/accounts').with(headers: { 'Connection' => 'keep-alive' })).to have_been_made.once
|
123
|
+
end
|
87
124
|
end
|
88
125
|
|
89
|
-
|
90
|
-
|
91
|
-
|
126
|
+
describe 'exceptions' do
|
127
|
+
it 'raises an OandaApiV20::RequestError exception when receiving anything other than a 2xx response from Oanda API' do
|
128
|
+
stub_request(:get, 'https://api-fxtrade.oanda.com/v3/accounts/100-100-109').to_return(status: 401, body: '', headers: {})
|
129
|
+
expect{ c.account('100-100-109').show }.to raise_error(OandaApiV20::RequestError)
|
130
|
+
end
|
92
131
|
end
|
93
132
|
|
94
133
|
describe 'governing request rate' do
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: oanda_api_v20
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Kobus Joubert
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-
|
11
|
+
date: 2016-11-24 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: httparty
|
@@ -94,6 +94,20 @@ dependencies:
|
|
94
94
|
- - "~>"
|
95
95
|
- !ruby/object:Gem::Version
|
96
96
|
version: '0.8'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: rake
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - ">="
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - ">="
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0'
|
97
111
|
description: Ruby client that supports the Oanda REST API V20 methods.
|
98
112
|
email: kobus@translate3d.com
|
99
113
|
executables: []
|
@@ -102,10 +116,13 @@ extra_rdoc_files: []
|
|
102
116
|
files:
|
103
117
|
- ".gitignore"
|
104
118
|
- ".rspec"
|
119
|
+
- ".ruby-version"
|
120
|
+
- ".travis.yml"
|
105
121
|
- CHANGELOG.md
|
106
122
|
- Gemfile
|
107
123
|
- LICENSE
|
108
124
|
- README.md
|
125
|
+
- Rakefile
|
109
126
|
- lib/oanda_api_v20.rb
|
110
127
|
- lib/oanda_api_v20/accounts.rb
|
111
128
|
- lib/oanda_api_v20/api.rb
|
@@ -119,6 +136,7 @@ files:
|
|
119
136
|
- lib/oanda_api_v20/transactions.rb
|
120
137
|
- lib/oanda_api_v20/version.rb
|
121
138
|
- oanda_api_v20.gemspec
|
139
|
+
- spec/oanda_api_v20/api_spec.rb
|
122
140
|
- spec/oanda_api_v20/client_spec.rb
|
123
141
|
- spec/oanda_api_v20/oanda_api_v20_spec.rb
|
124
142
|
- spec/spec_helper.rb
|
@@ -147,6 +165,7 @@ signing_key:
|
|
147
165
|
specification_version: 4
|
148
166
|
summary: Ruby Oanda REST API V20
|
149
167
|
test_files:
|
168
|
+
- spec/oanda_api_v20/api_spec.rb
|
150
169
|
- spec/oanda_api_v20/client_spec.rb
|
151
170
|
- spec/oanda_api_v20/oanda_api_v20_spec.rb
|
152
171
|
- spec/spec_helper.rb
|