oanda_api_v20 2.1.1 → 2.2.0
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.
- checksums.yaml +5 -5
- data/.ruby-version +1 -1
- data/CHANGELOG.md +6 -0
- data/README.md +8 -0
- data/lib/oanda_api_v20/api.rb +12 -0
- data/lib/oanda_api_v20/pricing.rb +0 -14
- data/lib/oanda_api_v20/transactions.rb +12 -0
- data/lib/oanda_api_v20/version.rb +1 -1
- data/oanda_api_v20.gemspec +1 -1
- data/spec/oanda_api_v20/api_spec.rb +23 -0
- metadata +5 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: be0ef34e9d27b283681c25c8f281c5ec264f9b36b63b39715df9bc69de0209a9
|
4
|
+
data.tar.gz: ba7a3cd6ec27e820e58565fedc2ec6b7e723f954ae1381ef79548d4ca88469af
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 39f4320e897a343a542e19155c36a6b80698ab7b57bc8d5e40da608ab6ec6845ba12cf9d1a79ef29c24a28850616ddf12760929fc15f78df7b9ff7aa5ea41eb3
|
7
|
+
data.tar.gz: e791adff74088c1f6da6a23454f30d13fe226828a9683d609b9ff910819a34008722a4badb6b0d7b29fb0b59b95064f5eb44844b2474a6004877c46d1f0f8dec
|
data/.ruby-version
CHANGED
@@ -1 +1 @@
|
|
1
|
-
2.
|
1
|
+
2.7.2
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,11 @@
|
|
1
1
|
# Change Log
|
2
2
|
|
3
|
+
## 2.2.0
|
4
|
+
#### 2021-08-27
|
5
|
+
|
6
|
+
* New transactions_stream endpoint. Big thanks to @plabaj.
|
7
|
+
* Upgraded development dependency version for rake to fix potential security vulnerability.
|
8
|
+
|
3
9
|
## 2.1.1
|
4
10
|
#### 2019-10-05
|
5
11
|
* Fix to pricing_stream method. This fixes the currency pair rate being reused over and over no matter the value read in the HTTP chunk. Big thanks to @joseluis-fw & @salrepe.
|
data/README.md
CHANGED
@@ -297,6 +297,14 @@ options = {
|
|
297
297
|
client.account('account_id').transactions_since_id(options).show
|
298
298
|
```
|
299
299
|
|
300
|
+
```ruby
|
301
|
+
client = OandaApiV20.new(access_token: 'my_access_token', stream: true)
|
302
|
+
|
303
|
+
client.account('account_id').transactions_stream.show do |json|
|
304
|
+
puts json if json['type'] != 'HEARTBEAT'
|
305
|
+
end
|
306
|
+
```
|
307
|
+
|
300
308
|
### Pricing
|
301
309
|
|
302
310
|
See the [Oanda Documentation](http://developer.oanda.com/rest-live-v20/pricing-ep/) for all available options on pricing.
|
data/lib/oanda_api_v20/api.rb
CHANGED
@@ -92,5 +92,17 @@ module OandaApiV20
|
|
92
92
|
self.http_verb = nil
|
93
93
|
end
|
94
94
|
end
|
95
|
+
|
96
|
+
def parse(buffer, fragment, &block)
|
97
|
+
buffer.split("\n").each do |message|
|
98
|
+
cleaned_message = message.strip
|
99
|
+
next if cleaned_message.empty?
|
100
|
+
yield JSON.parse(cleaned_message)
|
101
|
+
end
|
102
|
+
rescue JSON::ParserError => e
|
103
|
+
raise OandaApiV20::ParseError, "#{e.message} in '#{fragment}'"
|
104
|
+
ensure
|
105
|
+
buffer.clear
|
106
|
+
end
|
95
107
|
end
|
96
108
|
end
|
@@ -17,19 +17,5 @@ module OandaApiV20
|
|
17
17
|
end
|
18
18
|
end
|
19
19
|
end
|
20
|
-
|
21
|
-
private
|
22
|
-
|
23
|
-
def parse(buffer, fragment, &block)
|
24
|
-
buffer.split("\n").each do |message|
|
25
|
-
cleaned_message = message.strip
|
26
|
-
next if cleaned_message.empty?
|
27
|
-
yield JSON.parse(cleaned_message)
|
28
|
-
end
|
29
|
-
rescue JSON::ParserError => e
|
30
|
-
raise OandaApiV20::ParseError, "#{e.message} in '#{fragment}'"
|
31
|
-
ensure
|
32
|
-
buffer.clear
|
33
|
-
end
|
34
20
|
end
|
35
21
|
end
|
@@ -20,5 +20,17 @@ module OandaApiV20
|
|
20
20
|
def transactions_since_id(options)
|
21
21
|
Client.send(http_verb, "#{base_uri}/accounts/#{account_id}/transactions/sinceid", headers: headers, query: options)
|
22
22
|
end
|
23
|
+
|
24
|
+
# GET /v3/accounts/:account_id/transactions/stream
|
25
|
+
def transactions_stream(options = {}, &block)
|
26
|
+
buffer = String.new
|
27
|
+
|
28
|
+
Client.send(http_verb, "#{base_uri}/accounts/#{account_id}/transactions/stream", headers: headers, query: options, stream_body: true) do |fragment|
|
29
|
+
if !fragment.empty?
|
30
|
+
buffer << fragment
|
31
|
+
parse(buffer, fragment, &block) if fragment.match(/\n\Z/)
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
23
35
|
end
|
24
36
|
end
|
data/oanda_api_v20.gemspec
CHANGED
@@ -23,7 +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
|
+
s.add_development_dependency 'rake', '~> 13.0'
|
27
27
|
|
28
28
|
s.files = `git ls-files`.split("\n")
|
29
29
|
s.test_files = s.files.grep(%r{^(test|spec|features)/})
|
@@ -323,6 +323,28 @@ describe OandaApiV20::Api do
|
|
323
323
|
api.transactions_since_id(options).show
|
324
324
|
expect(a_request(:get, 'https://api-fxtrade.oanda.com/v3/accounts/100-100-100/transactions/sinceid').with(query: options)).to have_been_made.once
|
325
325
|
end
|
326
|
+
|
327
|
+
it 'retrieving all transactions stream' do
|
328
|
+
body = <<~EOF
|
329
|
+
{"id":"6","accountID":"100-100-100","userID":12345678,"batchID":"4","requestID":"11111111111111111","time":"2021-08-20T11:56:39.037505525Z","type":"TAKE_PROFIT_ORDER","tradeID":"5","timeInForce":"GTC","triggerCondition":"DEFAULT","price":"0.71388","reason":"ON_FILL"}\n{"id":"7","accountID":"100-100-100","userID":12345678,"batchID":"4","requestID":"11111111111111112","time":"2021-08-20T11:56:39.037505525Z","type":"STOP_LOSS_ORDER","tradeID":"5","timeInForce":"GTC","triggerCondition":"DEFAULT","triggerMode":"TOP_OF_BOOK","price":"0.71258","distance":"0.00030","reason":"ON_FILL"}\n\r\n
|
330
|
+
EOF
|
331
|
+
|
332
|
+
headers = {
|
333
|
+
'Transfer-Encoding' => 'chunked',
|
334
|
+
'Content-Type' => 'application/octet-stream'
|
335
|
+
}
|
336
|
+
|
337
|
+
stub_request(:get, 'https://stream-fxtrade.oanda.com/v3/accounts/100-100-100/transactions/stream').to_return(status: 200, body: body, headers: headers)
|
338
|
+
|
339
|
+
messages = []
|
340
|
+
|
341
|
+
stream_api.transactions_stream.show do |message|
|
342
|
+
messages << message
|
343
|
+
end
|
344
|
+
|
345
|
+
expect(a_request(:get, 'https://stream-fxtrade.oanda.com/v3/accounts/100-100-100/transactions/stream')).to have_been_made.once
|
346
|
+
expect(messages.count).to eq(2)
|
347
|
+
end
|
326
348
|
end
|
327
349
|
|
328
350
|
context 'pricing for' do
|
@@ -453,6 +475,7 @@ EOF
|
|
453
475
|
:trade, :trades, :open_trades,
|
454
476
|
:position, :positions, :open_positions,
|
455
477
|
:transaction, :transactions, :transactions_id_range, :transactions_since_id,
|
478
|
+
:transactions_stream,
|
456
479
|
:pricing,
|
457
480
|
:pricing_stream,
|
458
481
|
:candles
|
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: 2.
|
4
|
+
version: 2.2.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:
|
11
|
+
date: 2021-08-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: httparty
|
@@ -100,14 +100,14 @@ dependencies:
|
|
100
100
|
requirements:
|
101
101
|
- - "~>"
|
102
102
|
- !ruby/object:Gem::Version
|
103
|
-
version: '
|
103
|
+
version: '13.0'
|
104
104
|
type: :development
|
105
105
|
prerelease: false
|
106
106
|
version_requirements: !ruby/object:Gem::Requirement
|
107
107
|
requirements:
|
108
108
|
- - "~>"
|
109
109
|
- !ruby/object:Gem::Version
|
110
|
-
version: '
|
110
|
+
version: '13.0'
|
111
111
|
description: Ruby client that supports the Oanda REST API V20 methods.
|
112
112
|
email: kobus@translate3d.com
|
113
113
|
executables: []
|
@@ -161,8 +161,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
161
161
|
- !ruby/object:Gem::Version
|
162
162
|
version: '0'
|
163
163
|
requirements: []
|
164
|
-
|
165
|
-
rubygems_version: 2.5.1
|
164
|
+
rubygems_version: 3.1.4
|
166
165
|
signing_key:
|
167
166
|
specification_version: 4
|
168
167
|
summary: Ruby Oanda REST API V20
|