oanda_api 0.9.2 → 0.9.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +12 -9
- data/README.md +3 -1
- data/lib/oanda_api.rb +1 -1
- data/lib/oanda_api/client/resource_descriptor.rb +25 -5
- data/lib/oanda_api/resource/transaction_history.rb +9 -0
- data/lib/oanda_api/streaming/json_parser.rb +5 -2
- data/lib/oanda_api/utils/utils.rb +7 -0
- data/lib/oanda_api/version.rb +1 -1
- data/oanda_api.gemspec +1 -1
- data/spec/oanda_api/client/resource_descriptor_spec.rb +12 -0
- data/spec/oanda_api/utils/utils_spec.rb +12 -0
- metadata +13 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a80562ee64a74c0c4ea6b5ef112ca9c94de2693a
|
4
|
+
data.tar.gz: d1f343f2f83e5a157b982bf7f99eaba8b8bfd070
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 60a73b0a93284b5a2d7444e01c95e486ed4cecd16657c85a3840dce2557f850a7e1d9137999996c8dd899a94f36938148bbbf0456b8c2e0ff75d0bc3a53195c2
|
7
|
+
data.tar.gz: a761bd94438f861a3da1b2546d361df47cef008d93cb025e2bffc947aa448e391985aac6b094e45769ba577830086ce4f555d3b8760adcd34062a2edc1d208fa
|
data/CHANGELOG.md
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
# Change Log
|
2
2
|
|
3
|
-
## 0.9.
|
3
|
+
## 0.9.3
|
4
4
|
|
5
|
-
|
6
|
-
|
7
|
-
* Fixed Yardoc formatting.
|
5
|
+
* Fixed support for retrieving [full account history](http://developer.oanda.com/rest-live/transaction-history/#getFullAccountHistory). Thanks [bewon](https://github.com/bewon).
|
6
|
+
* Fixed issue [#6](https://github.com/nukeproof/oanda_api/issues/6) to make streaming JSON parsers available correctly under *nix. Thanks [Eric](https://github.com/lifeBCE).
|
8
7
|
|
9
|
-
|
10
|
-
OandaAPI now supports Oanda's streaming API for consuming realtime ticks and account transactions. See the example in the README and have a look at the specs for `OandaAPI::Streaming::Client`.
|
8
|
+
## 0.9.2
|
11
9
|
|
10
|
+
* Specify version of HTTParty as 0.13.3 until HTTParty issue [#398](https://github.com/jnunemaker/httparty/issues/398) is resolved.
|
11
|
+
* Now support any whitespace as delimiting multiple JSON objects in streaming API with `OandaAPI::Streaming::Adapters::Generic`.
|
12
12
|
|
13
13
|
|
14
14
|
## 0.9.1
|
@@ -22,8 +22,11 @@ OandaAPI now supports Oanda's streaming API for consuming realtime ticks and acc
|
|
22
22
|
As with version 0.9.0, `OandaAPI::Streaming::Client` will use the JSON gem parser if it is the only JSON parser installed. However, the JSON gem does not support parsing streams of objects very robustly (i.e. it expects complete documents, or the stream to delimit multiple objects consistently). If you are using the streaming API, and install either the [yajl-ruby](https://github.com/brianmario/yajl-ruby) gem (for MRI and Rubinius ruby) or the [gson](https://github.com/avsej/gson.rb) gem (for jruby), then `OandaAPI::Streaming::Client` will use either of those streaming JSON gems for a gain in reliability.
|
23
23
|
|
24
24
|
|
25
|
+
## 0.9.0
|
25
26
|
|
26
|
-
|
27
|
+
* Add support for live [Streaming](http://developer.oanda.com/rest-live/streaming/).
|
28
|
+
* Add #to_json serialization to resource classes.
|
29
|
+
* Fixed Yardoc formatting.
|
27
30
|
|
28
|
-
|
29
|
-
|
31
|
+
###What's New?
|
32
|
+
OandaAPI now supports Oanda's streaming API for consuming realtime ticks and account transactions. See the example in the README and have a look at the specs for `OandaAPI::Streaming::Client`.
|
data/README.md
CHANGED
@@ -1,5 +1,7 @@
|
|
1
1
|
# OandaAPI
|
2
|
-
[![
|
2
|
+
[![Gem Version](https://badge.fury.io/rb/oanda_api.svg)](https://rubygems.org/gems/oanda_api)
|
3
|
+
[![Code Climate](https://codeclimate.com/github/nukeproof/oanda_api/badges/gpa.svg)](https://codeclimate.com/github/nukeproof/oanda_api)
|
4
|
+
[![Test Coverage](https://codeclimate.com/github/nukeproof/oanda_api/badges/coverage.svg)](https://codeclimate.com/github/nukeproof/oanda_api)
|
3
5
|
|
4
6
|
Access Oanda FX accounts, get market data, trade, build trading strategies using Ruby.
|
5
7
|
## Synopsis
|
data/lib/oanda_api.rb
CHANGED
@@ -3,7 +3,6 @@ require 'httparty'
|
|
3
3
|
require 'persistent_httparty'
|
4
4
|
require 'http/exceptions'
|
5
5
|
require 'time'
|
6
|
-
require 'erb' # Hack to fix issue with httparty 0.13.4 [issue 398](https://github.com/jnunemaker/httparty/issues/398)
|
7
6
|
|
8
7
|
require_relative 'oanda_api/configuration'
|
9
8
|
require_relative 'oanda_api/client/client'
|
@@ -26,5 +25,6 @@ require_relative 'oanda_api/resource/position'
|
|
26
25
|
require_relative 'oanda_api/resource/price'
|
27
26
|
require_relative 'oanda_api/resource/trade'
|
28
27
|
require_relative 'oanda_api/resource/transaction'
|
28
|
+
require_relative 'oanda_api/resource/transaction_history'
|
29
29
|
require_relative 'oanda_api/utils/utils'
|
30
30
|
require_relative 'oanda_api/version'
|
@@ -15,6 +15,15 @@ module OandaAPI
|
|
15
15
|
class ResourceDescriptor
|
16
16
|
attr_reader :collection_name, :path, :resource_klass
|
17
17
|
|
18
|
+
# Mapper for not "typical" resources.
|
19
|
+
# Key is a resource from the API path.
|
20
|
+
# Value is a hash that can contain "resource_name" from the code and/or
|
21
|
+
# "is_collection" (if true: will force treating response as a collection of resources,
|
22
|
+
# if false: will force treating response as a single resource).
|
23
|
+
RESOURCES_MAPPER = {
|
24
|
+
alltransactions: { resource_name: "transaction_history", is_collection: false }
|
25
|
+
}
|
26
|
+
|
18
27
|
# Analyzes the resource request and determines the type of resource
|
19
28
|
# expected from the API.
|
20
29
|
#
|
@@ -24,10 +33,7 @@ module OandaAPI
|
|
24
33
|
def initialize(path, method)
|
25
34
|
@path = path
|
26
35
|
path.match(/\/(?<resource_name>[a-z]*)\/?(?<resource_id>\w*?)$/) do |names|
|
27
|
-
|
28
|
-
self.resource_klass = resource_name
|
29
|
-
@is_collection = method == :get && resource_id.empty?
|
30
|
-
@collection_name = Utils.pluralize(resource_name).to_sym if is_collection?
|
36
|
+
initialize_from_resource_name(names[:resource_name], method, names[:resource_id])
|
31
37
|
end
|
32
38
|
end
|
33
39
|
|
@@ -43,10 +49,24 @@ module OandaAPI
|
|
43
49
|
# @param [String] resource_name
|
44
50
|
# @return [void]
|
45
51
|
def resource_klass=(resource_name)
|
46
|
-
klass_symbol = resource_name.
|
52
|
+
klass_symbol = OandaAPI::Utils.classify(resource_name).to_sym
|
47
53
|
fail ArgumentError, "Invalid resource" unless OandaAPI::Resource.constants.include?(klass_symbol)
|
48
54
|
@resource_klass = OandaAPI::Resource.const_get klass_symbol
|
49
55
|
end
|
56
|
+
|
57
|
+
# Will set instance attributes based on resource_name, method and resource_id.
|
58
|
+
#
|
59
|
+
# @param [String] resource_name name of the resource (from the path).
|
60
|
+
# @param [Symbol] method an http verb (see {OandaAPI::Client.map_method_to_http_verb}).
|
61
|
+
# @param [Symbol] resource_id id of the resource.
|
62
|
+
# @return [void]
|
63
|
+
def initialize_from_resource_name(resource_name, method, resource_id)
|
64
|
+
mapped_resource = RESOURCES_MAPPER.fetch(resource_name.to_sym,
|
65
|
+
{ resource_name: Utils.singularize(resource_name) })
|
66
|
+
self.resource_klass = mapped_resource.fetch :resource_name
|
67
|
+
@is_collection = mapped_resource.fetch :is_collection, method == :get && resource_id.empty?
|
68
|
+
@collection_name = Utils.pluralize(mapped_resource.fetch(:resource_name)).to_sym if is_collection?
|
69
|
+
end
|
50
70
|
end
|
51
71
|
end
|
52
72
|
end
|
@@ -0,0 +1,9 @@
|
|
1
|
+
module OandaAPI
|
2
|
+
module Resource
|
3
|
+
# Transactions History value object. Resource name in API: alltransactions.
|
4
|
+
# See the Oanda Developer Guide for information about {http://developer.oanda.com/rest-live/transaction-history/ Transactions history}.
|
5
|
+
class TransactionHistory < ResourceBase
|
6
|
+
|
7
|
+
end
|
8
|
+
end
|
9
|
+
end
|
@@ -5,13 +5,15 @@ module OandaAPI
|
|
5
5
|
#
|
6
6
|
# Used to deserialize a stream of JSON objects. Will load and use a streaming JSON parser
|
7
7
|
# if one is installed, otherwise defaults to use the JSON gem.
|
8
|
+
#
|
9
|
+
# Much of this module's code was borrowed from [multi_json](https://github.com/intridea/multi_json).
|
8
10
|
module JsonParser
|
9
11
|
extend self
|
10
12
|
|
11
13
|
# Map parser adapters to the gem library they require.
|
12
14
|
REQUIREMENT_MAP = {
|
13
|
-
gson: "
|
14
|
-
yajl: "
|
15
|
+
gson: "gson",
|
16
|
+
yajl: "yajl"
|
15
17
|
}
|
16
18
|
|
17
19
|
# Loads (if not already loaded) and returns the current adapter class.
|
@@ -86,6 +88,7 @@ module OandaAPI
|
|
86
88
|
begin
|
87
89
|
return sym if Kernel.const_get sym.to_s.capitalize
|
88
90
|
rescue ::NameError
|
91
|
+
nil
|
89
92
|
end
|
90
93
|
|
91
94
|
begin
|
@@ -10,6 +10,13 @@ module OandaAPI
|
|
10
10
|
s.to_s.gsub(/(?:_)([a-z\d]*)/i) { "#{$1.capitalize}" }.sub(/^(.)/) { $1.downcase }
|
11
11
|
end
|
12
12
|
|
13
|
+
# Converts a string from snake_case to upper camel case (class name like "MyClass").
|
14
|
+
# @param [String] s
|
15
|
+
# @return [String]
|
16
|
+
def self.classify(s)
|
17
|
+
s.split('_').collect(&:capitalize).join
|
18
|
+
end
|
19
|
+
|
13
20
|
# Naively plops an "s" at the end of a string.
|
14
21
|
# If the string is "" or nil, returns "".
|
15
22
|
# @param [String] s
|
data/lib/oanda_api/version.rb
CHANGED
data/oanda_api.gemspec
CHANGED
@@ -21,7 +21,7 @@ Gem::Specification.new do |s|
|
|
21
21
|
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
22
22
|
s.require_paths = ["lib"]
|
23
23
|
|
24
|
-
s.add_dependency "httparty", "0.13.
|
24
|
+
s.add_dependency "httparty", "~> 0.13", ">= 0.13.5"
|
25
25
|
s.add_dependency "persistent_httparty", "~> 0.1"
|
26
26
|
s.add_dependency "http-exceptions", "~> 0.0"
|
27
27
|
|
@@ -6,6 +6,18 @@ describe "OandaAPI::Client::ResourceDescriptor" do
|
|
6
6
|
it "sets path" do
|
7
7
|
expect(resource_descriptor.path).to eq("/accounts")
|
8
8
|
end
|
9
|
+
|
10
|
+
context 'when path resource is equal alltransactions' do
|
11
|
+
let(:resource_descriptor) { OandaAPI::Client::ResourceDescriptor.new "/account/123/alltransactions", :get }
|
12
|
+
|
13
|
+
it 'is sets TransactionHistory as resource_klass' do
|
14
|
+
expect(resource_descriptor.resource_klass).to eq(OandaAPI::Resource::TransactionHistory)
|
15
|
+
end
|
16
|
+
|
17
|
+
it 'is sets @is_collection to false' do
|
18
|
+
expect(resource_descriptor.is_collection?).to be false
|
19
|
+
end
|
20
|
+
end
|
9
21
|
end
|
10
22
|
|
11
23
|
context "when the path ends with a known resource" do
|
@@ -27,6 +27,18 @@ describe "OandaAPI::Utils" do
|
|
27
27
|
end
|
28
28
|
end
|
29
29
|
|
30
|
+
describe '.classify' do
|
31
|
+
it 'return capitalized one word text' do
|
32
|
+
expect(OandaAPI::Utils.classify('ruby')).to eq("Ruby")
|
33
|
+
end
|
34
|
+
it 'capitalizes first word and each word after _ sign' do
|
35
|
+
expect(OandaAPI::Utils.classify('this_is_ruby')).to eq("ThisIsRuby")
|
36
|
+
end
|
37
|
+
it 'downcase letters inside the word (except first letter)' do
|
38
|
+
expect(OandaAPI::Utils.classify('RUBY')).to eq("Ruby")
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
30
42
|
describe ".pluralize" do
|
31
43
|
it "naively adds an s to the end of strings" do
|
32
44
|
expect(OandaAPI::Utils.pluralize("thing")).to eq("things")
|
metadata
CHANGED
@@ -1,29 +1,35 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: oanda_api
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.9.
|
4
|
+
version: 0.9.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Dean Missikowski
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-07-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: httparty
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- -
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0.13'
|
20
|
+
- - ">="
|
18
21
|
- !ruby/object:Gem::Version
|
19
|
-
version: 0.13.
|
22
|
+
version: 0.13.5
|
20
23
|
type: :runtime
|
21
24
|
prerelease: false
|
22
25
|
version_requirements: !ruby/object:Gem::Requirement
|
23
26
|
requirements:
|
24
|
-
- -
|
27
|
+
- - "~>"
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '0.13'
|
30
|
+
- - ">="
|
25
31
|
- !ruby/object:Gem::Version
|
26
|
-
version: 0.13.
|
32
|
+
version: 0.13.5
|
27
33
|
- !ruby/object:Gem::Dependency
|
28
34
|
name: persistent_httparty
|
29
35
|
requirement: !ruby/object:Gem::Requirement
|
@@ -143,6 +149,7 @@ files:
|
|
143
149
|
- lib/oanda_api/resource/price.rb
|
144
150
|
- lib/oanda_api/resource/trade.rb
|
145
151
|
- lib/oanda_api/resource/transaction.rb
|
152
|
+
- lib/oanda_api/resource/transaction_history.rb
|
146
153
|
- lib/oanda_api/resource_base.rb
|
147
154
|
- lib/oanda_api/resource_collection.rb
|
148
155
|
- lib/oanda_api/streaming/adapter_error.rb
|