quadrigacx 0.8.2 → 0.9.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 34289e6667fbe12fe3309842415f0c5ebbe4e3f5
4
- data.tar.gz: a39c7459d075f3532d6f153bf4d4d36f0f744a9e
3
+ metadata.gz: ededb3c30e830783a32bd82dcde5f52b103af055
4
+ data.tar.gz: 00f503b7428beaabae9644957ed55a4efd0c5ab0
5
5
  SHA512:
6
- metadata.gz: 6619d03340a4bfacdf9e5a06ba2b391e999c245f39ff825cec9d9d002c2b1d8b7f8912d0ac7b14a218832c5e4afa1ec142c1e272141496e8f700bc1637cae114
7
- data.tar.gz: 366091c14a7d5cbff6d459097d7e405883283d5a96112bea4252b13f8e67f0d540d4194248d984733abb52e6c473eaca8cb6b8923127c23b291332ff14e10b3d
6
+ metadata.gz: 519489d2486a0483c4d2858f855deee6134aace4b69fab684fba07b2ef048f20266af3e3c9c860b3a7a67deec17d28f80f9f4102413bf3f2bc70f40208b4a69e
7
+ data.tar.gz: f9180c16614b594c451d67e5ba21d925c48b96e2dcf87dfb7cac350e0989fa9ae41fa98fc2198bee3d17bbfcefb23ee3114aa046708a76672ceb65eee2049b12
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- quadrigacx (0.8.0)
4
+ quadrigacx (0.8.2)
5
5
  hashie (~> 3.3)
6
6
  json (~> 1.8)
7
7
  rest-client (~> 1.7)
@@ -10,6 +10,9 @@ GEM
10
10
  remote: https://rubygems.org/
11
11
  specs:
12
12
  addressable (2.3.6)
13
+ byebug (5.0.0)
14
+ columnize (= 0.9.0)
15
+ columnize (0.9.0)
13
16
  crack (0.4.2)
14
17
  safe_yaml (~> 1.0.0)
15
18
  diff-lcs (1.2.5)
@@ -17,12 +20,12 @@ GEM
17
20
  unf (>= 0.0.5, < 1.0.0)
18
21
  dotenv (1.0.2)
19
22
  gem-release (0.7.3)
20
- hashie (3.4.1)
23
+ hashie (3.4.2)
21
24
  http-cookie (1.0.2)
22
25
  domain_name (~> 0.5)
23
- json (1.8.2)
24
- mime-types (2.5)
25
- netrc (0.10.2)
26
+ json (1.8.3)
27
+ mime-types (2.6.1)
28
+ netrc (0.10.3)
26
29
  rest-client (1.8.0)
27
30
  http-cookie (>= 1.0.2, < 2.0)
28
31
  mime-types (>= 1.16, < 3.0)
@@ -52,6 +55,7 @@ PLATFORMS
52
55
  ruby
53
56
 
54
57
  DEPENDENCIES
58
+ byebug (~> 5.0)
55
59
  dotenv (~> 1.0)
56
60
  gem-release (~> 0.7)
57
61
  quadrigacx!
@@ -19,7 +19,6 @@ module QuadrigaCX
19
19
  raise ArgumentError, "Options hash required"
20
20
  end
21
21
 
22
- @use_hmac = true
23
22
  @client_id = options[:client_id]
24
23
  @api_key = options[:api_key]
25
24
  @api_secret = options[:api_secret]
@@ -1,6 +1,9 @@
1
1
  module QuadrigaCX
2
- class Error < StandardError; end
3
- class ConfigurationError < Error; end
4
- class Unauthorized < Error; end
5
- class NotFound < Error; end
2
+ class Error < StandardError; end
3
+ class ConfigurationError < Error; end
4
+ class Unauthorized < Error; end
5
+ class NotFound < Error; end
6
+ class ExceedsAvailableBalance < Error; end
7
+ class BelowMinimumOrderValue < Error; end
8
+ class AboveMaximumOrderValue < Error; end
6
9
  end
@@ -13,22 +13,23 @@ module QuadrigaCX
13
13
  protected
14
14
 
15
15
  def request *args
16
- resp = @use_hmac ? self.hmac_request(*args) : self.oauth_request(*args)
16
+ resp = hmac_request(*args)
17
+ json = JSON.parse(resp) rescue (return fix_json(resp))
18
+ json.kind_of?(Array) ? json.map { |i| to_hashie(i) } : to_hashie(json)
19
+ end
20
+
21
+ private
17
22
 
23
+ def fix_json response
18
24
  begin
19
- json = JSON.parse(resp.body)
25
+ JSON.parse(response)
20
26
 
21
27
  # The `/cancel_order` route returns `"true"` instead of valid JSON.
22
28
  rescue JSON::ParserError
23
- return true if resp.body.strip == '"true"'
24
- return false if resp.body.strip == '"false"'
25
-
26
- match = resp.body.match(/"(.*)"/)
27
-
28
- return match ? match[1] : resp.body
29
+ return true if response.strip == '"true"'
30
+ return false if response.strip == '"false"'
31
+ response[/"(.*)"/, 1] || response
29
32
  end
30
-
31
- json.kind_of?(Array) ? json.map { |i| to_hashie(i) } : to_hashie(json)
32
33
  end
33
34
 
34
35
  def hmac_request http_method, path, body={}
@@ -65,24 +66,22 @@ module QuadrigaCX
65
66
  )
66
67
  end
67
68
 
68
- # Perform an OAuth API request. The client must be initialized
69
- # with a valid OAuth access token to make requests with this method
70
- #
71
- # path - Request path
72
- # body - Parameters for requests - GET and POST
73
- #
74
- # TODO(maros): Implement this when QuadrigaCX supports it.
75
- def oauth_request http_method, path, body={}
69
+ def raise_error hash
70
+ errorClass =
71
+ case hash.error.code
72
+ when 21 then ExceedsAvailableBalance
73
+ when 22 then BelowMinimumOrderValue
74
+ when 23 then AboveMaximumOrderValue
75
+ else Error
76
+ end
77
+
78
+ raise errorClass.new(hash.error) if hash.error
79
+ raise errorClass.new(hash.errors.join(',')) if hash.errors
76
80
  end
77
81
 
78
- private
79
-
80
82
  def to_hashie json
81
83
  hash = Hashie::Mash.new(json)
82
-
83
- raise Error.new(hash.error) if hash.error
84
- raise Error.new(hash.errors.join(',')) if hash.errors
85
-
84
+ raise_error(hash) if hash.error
86
85
  hash
87
86
  end
88
87
  end
@@ -1,5 +1,5 @@
1
1
  module QuadrigaCX
2
2
  unless defined?(QuadrigaCX::VERSION)
3
- VERSION = '0.8.2'
3
+ VERSION = '0.9.0'
4
4
  end
5
5
  end
data/lib/quadrigacx.rb CHANGED
@@ -16,7 +16,6 @@ module QuadrigaCX
16
16
  raise ArgumentError, "Options hash required"
17
17
  end
18
18
 
19
- @@options[:use_hmac] = true
20
19
  @@options[:client_id] = options[:client_id]
21
20
  @@options[:api_key] = options[:api_key]
22
21
  @@options[:api_secret] = options[:api_secret]
data/quadrigacx.gemspec CHANGED
@@ -11,6 +11,7 @@ Gem::Specification.new do |s|
11
11
  s.homepage = "http://mhluska.com/"
12
12
  s.license = "MIT"
13
13
 
14
+ s.add_development_dependency 'byebug', '~> 5.0'
14
15
  s.add_development_dependency 'rspec', '~> 3.1'
15
16
  s.add_development_dependency 'webmock', '~> 1.20'
16
17
  s.add_development_dependency 'vcr', '~> 2.9'
data/spec/client_spec.rb CHANGED
@@ -98,6 +98,24 @@ describe QuadrigaCX::Client do
98
98
  expect(order.id).not_to be_nil
99
99
  end
100
100
  end
101
+
102
+ it 'throws an error when exceeding balance' do
103
+ VCR.use_cassette('limit_buy_above_maximum_order_value') do
104
+ expect { client.limit_buy(price: 1_000_000, amount: 1) }.to raise_error(QuadrigaCX::AboveMaximumOrderValue)
105
+ end
106
+ end
107
+
108
+ it 'throws an error when the amount is too small' do
109
+ VCR.use_cassette('limit_buy_below_minimum_order_value') do
110
+ expect { client.limit_buy(price: 100, amount: 0.00000001) }.to raise_error(QuadrigaCX::BelowMinimumOrderValue)
111
+ end
112
+ end
113
+
114
+ it 'throws an error when exceeding available balance' do
115
+ VCR.use_cassette('limit_buy_exceeds_available_balance') do
116
+ expect { client.limit_buy(price: 4999, amount: 1) }.to raise_error(QuadrigaCX::ExceedsAvailableBalance)
117
+ end
118
+ end
101
119
  end
102
120
 
103
121
  describe '#limit_sell' do
@@ -0,0 +1,56 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: post
5
+ uri: https://api.quadrigacx.com/v2/buy
6
+ body:
7
+ encoding: UTF-8
8
+ string: '{"price":1000000,"amount":1,"key":"kOnVDjfPPh","nonce":"1436134811802","signature":"08e90f76f7f5d2d5deda2bd2254d2ace2a60fde5c8c9fb21f90e93394268351d"}'
9
+ headers:
10
+ Accept:
11
+ - application/json
12
+ Accept-Encoding:
13
+ - gzip, deflate
14
+ Content-Type:
15
+ - application/json
16
+ Content-Length:
17
+ - '150'
18
+ User-Agent:
19
+ - Ruby
20
+ response:
21
+ status:
22
+ code: 200
23
+ message: OK
24
+ headers:
25
+ Server:
26
+ - cloudflare-nginx
27
+ Date:
28
+ - Sun, 05 Jul 2015 22:20:14 GMT
29
+ Content-Type:
30
+ - application/json
31
+ Content-Length:
32
+ - '111'
33
+ Connection:
34
+ - keep-alive
35
+ Set-Cookie:
36
+ - __cfduid=d32dff9e85d8cfd61f02b3ce7236432441436134814; expires=Mon, 04-Jul-16
37
+ 22:20:14 GMT; path=/; domain=.quadrigacx.com; HttpOnly
38
+ - ci_session=a65b3c51701e5c4897d5cdf591000bb4; expires=Mon, 06-Jul-2015 22:20:14
39
+ GMT; Max-Age=86400; path=/
40
+ Content-Encoding:
41
+ - gzip
42
+ Vary:
43
+ - Accept-Encoding
44
+ X-Powered-By:
45
+ - PHP/5.5.9-1ubuntu4.9
46
+ Cf-Ray:
47
+ - 201674bbbfc92192-EWR
48
+ body:
49
+ encoding: ASCII-8BIT
50
+ string: !binary |-
51
+ H4sIAAAAAAAAA6tWSi0qyi9SsqpWSs5PSVWyMjLWUcpNLS5OTAdylDzzkvOL
52
+ ilKTSxQKijKTUxVUDHUMDAxAWM/AwNnRRSGzWCExKb8sVaEkI1UhN7EiM7c0
53
+ VyE/TUHFFKFIqbYWALUjnkdnAAAA
54
+ http_version:
55
+ recorded_at: Sun, 05 Jul 2015 22:20:14 GMT
56
+ recorded_with: VCR 2.9.3
@@ -0,0 +1,55 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: post
5
+ uri: https://api.quadrigacx.com/v2/buy
6
+ body:
7
+ encoding: UTF-8
8
+ string: '{"price":100,"amount":1.0e-08,"key":"kOnVDjfPPh","nonce":"1436134814405","signature":"021c293df298e506a10a662d18deb6aa81f0be90ff9d770a3abc44bdf045415f"}'
9
+ headers:
10
+ Accept:
11
+ - application/json
12
+ Accept-Encoding:
13
+ - gzip, deflate
14
+ Content-Type:
15
+ - application/json
16
+ Content-Length:
17
+ - '152'
18
+ User-Agent:
19
+ - Ruby
20
+ response:
21
+ status:
22
+ code: 200
23
+ message: OK
24
+ headers:
25
+ Server:
26
+ - cloudflare-nginx
27
+ Date:
28
+ - Sun, 05 Jul 2015 22:20:14 GMT
29
+ Content-Type:
30
+ - application/json
31
+ Content-Length:
32
+ - '75'
33
+ Connection:
34
+ - keep-alive
35
+ Set-Cookie:
36
+ - __cfduid=d35efbfc1bfd0e98c5f4642689836fea91436134814; expires=Mon, 04-Jul-16
37
+ 22:20:14 GMT; path=/; domain=.quadrigacx.com; HttpOnly
38
+ - ci_session=5b530dab54071514991afb20690f4a78; expires=Mon, 06-Jul-2015 22:20:14
39
+ GMT; Max-Age=86400; path=/
40
+ Content-Encoding:
41
+ - gzip
42
+ Vary:
43
+ - Accept-Encoding
44
+ X-Powered-By:
45
+ - PHP/5.5.9-1ubuntu4.9
46
+ Cf-Ray:
47
+ - 201674bf2f2d21e0-EWR
48
+ body:
49
+ encoding: ASCII-8BIT
50
+ string: !binary |-
51
+ H4sIAAAAAAAAA6tWSi0qyi9SsqpWSs5PSVWyMjLSUcpNLS5OTAdylDzzkvOL
52
+ ilKTSxQSc/NL80oUDPUMXHUtlGprAeoB5yg5AAAA
53
+ http_version:
54
+ recorded_at: Sun, 05 Jul 2015 22:20:14 GMT
55
+ recorded_with: VCR 2.9.3
@@ -0,0 +1,56 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: post
5
+ uri: https://api.quadrigacx.com/v2/buy
6
+ body:
7
+ encoding: UTF-8
8
+ string: '{"price":4999,"amount":1,"key":"kOnVDjfPPh","nonce":"1436134814778","signature":"246305d318a717ac373310b7175910f973b4fe39ba52eadc0c3db8841d740f6e"}'
9
+ headers:
10
+ Accept:
11
+ - application/json
12
+ Accept-Encoding:
13
+ - gzip, deflate
14
+ Content-Type:
15
+ - application/json
16
+ Content-Length:
17
+ - '147'
18
+ User-Agent:
19
+ - Ruby
20
+ response:
21
+ status:
22
+ code: 200
23
+ message: OK
24
+ headers:
25
+ Server:
26
+ - cloudflare-nginx
27
+ Date:
28
+ - Sun, 05 Jul 2015 22:20:15 GMT
29
+ Content-Type:
30
+ - application/json
31
+ Content-Length:
32
+ - '103'
33
+ Connection:
34
+ - keep-alive
35
+ Set-Cookie:
36
+ - __cfduid=d5bb9c9c4d1d088e64cfafc3043de58701436134814; expires=Mon, 04-Jul-16
37
+ 22:20:14 GMT; path=/; domain=.quadrigacx.com; HttpOnly
38
+ - ci_session=19acf8226619ccc168dc931e16994281; expires=Mon, 06-Jul-2015 22:20:15
39
+ GMT; Max-Age=86400; path=/
40
+ Content-Encoding:
41
+ - gzip
42
+ Vary:
43
+ - Accept-Encoding
44
+ X-Powered-By:
45
+ - PHP/5.5.9-1ubuntu4.9
46
+ Cf-Ray:
47
+ - 201674c16332219e-EWR
48
+ body:
49
+ encoding: ASCII-8BIT
50
+ string: !binary |-
51
+ H4sIAAAAAAAAAxXIwQpAQBAG4FeZJkcJuezexMVjjPEntWzNSkr77jh+38Mw
52
+ i8b+YY0L2LdNyTtSkvUDT4dGM+hJnoqudM5VdT30I+FWYEkkl2xB5gD6d5Yg
53
+ h4JzfgFV7vSrWAAAAA==
54
+ http_version:
55
+ recorded_at: Sun, 05 Jul 2015 22:20:15 GMT
56
+ recorded_with: VCR 2.9.3
metadata CHANGED
@@ -1,15 +1,29 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: quadrigacx
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.8.2
4
+ version: 0.9.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Maros Hluska
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-05-24 00:00:00.000000000 Z
11
+ date: 2015-07-05 00:00:00.000000000 Z
12
12
  dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: byebug
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '5.0'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '5.0'
13
27
  - !ruby/object:Gem::Dependency
14
28
  name: rspec
15
29
  requirement: !ruby/object:Gem::Requirement
@@ -147,7 +161,10 @@ files:
147
161
  - spec/fixtures/vcr_cassettes/balance.yml
148
162
  - spec/fixtures/vcr_cassettes/cancel.yml
149
163
  - spec/fixtures/vcr_cassettes/limit_buy.yml
164
+ - spec/fixtures/vcr_cassettes/limit_buy_above_maximum_order_value.yml
165
+ - spec/fixtures/vcr_cassettes/limit_buy_below_minimum_order_value.yml
150
166
  - spec/fixtures/vcr_cassettes/limit_buy_cancel_order.yml
167
+ - spec/fixtures/vcr_cassettes/limit_buy_exceeds_available_balance.yml
151
168
  - spec/fixtures/vcr_cassettes/limit_sell_cancel_order.yml
152
169
  - spec/fixtures/vcr_cassettes/market_buy.yml
153
170
  - spec/fixtures/vcr_cassettes/open_orders.yml
@@ -192,7 +209,10 @@ test_files:
192
209
  - spec/fixtures/vcr_cassettes/balance.yml
193
210
  - spec/fixtures/vcr_cassettes/cancel.yml
194
211
  - spec/fixtures/vcr_cassettes/limit_buy.yml
212
+ - spec/fixtures/vcr_cassettes/limit_buy_above_maximum_order_value.yml
213
+ - spec/fixtures/vcr_cassettes/limit_buy_below_minimum_order_value.yml
195
214
  - spec/fixtures/vcr_cassettes/limit_buy_cancel_order.yml
215
+ - spec/fixtures/vcr_cassettes/limit_buy_exceeds_available_balance.yml
196
216
  - spec/fixtures/vcr_cassettes/limit_sell_cancel_order.yml
197
217
  - spec/fixtures/vcr_cassettes/market_buy.yml
198
218
  - spec/fixtures/vcr_cassettes/open_orders.yml