bitstamp_client 1.1.0 → 1.2.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 3b8a4f622fc63947b187391a2f3cf52db990a1f793dd5cc6d832670afbbb9153
4
- data.tar.gz: 6f22c74ebdb91f9afa9f36fddb144a752ed439451b0f9aea6886006bd0705fd5
3
+ metadata.gz: 842c6304d1c9511f636ddcc56119b3d82e53f73587310a3ffcc919ce3a80313f
4
+ data.tar.gz: 760ff1f7f28357f5e58d99b1e23ba76baf655ac4da00e7ac788fa238ecdbaa60
5
5
  SHA512:
6
- metadata.gz: 3e7f33f7f4fd5d1bd9ef0454111577eef0886d094164df6321ea560402b7c7f791b7f83917284ffaad89e709d7f6c6f14727cc5678ea6b68a33db86f80e9124c
7
- data.tar.gz: 8576a8c6f58623a34119806c2015eb208422396751f6620c0e2da8fe56e7e9fc9dda8e622e120733a1ce19f7d010acb518be18b442dfb3591022b8531f93c406
6
+ metadata.gz: 9526285249e1bfa7577ab7271d7be11904dae64c12b7afc5a4321a68c18984704d9648a03b89955579a0813ee98ba1dc917f911894a64a59bcc1ec775ed6043e
7
+ data.tar.gz: 16bcb843c59bbe8aa0e73346ae03b8ee30ca7a50b99e1f9da90947ef4cb98d71c55b7c8e2316edf424af4fa5ecaa814661782a85c0be59ccb12c2c691f468fe8
data/.env ADDED
@@ -0,0 +1,3 @@
1
+ KEY=changeme
2
+ SECRET=changeme
3
+ CUSTOMER_ID=1234
@@ -0,0 +1,30 @@
1
+ name: Ruby
2
+
3
+ on:
4
+ push:
5
+ branches: [ master ]
6
+ pull_request:
7
+ branches: [ master ]
8
+
9
+ jobs:
10
+ test:
11
+
12
+ runs-on: ubuntu-latest
13
+ strategy:
14
+ matrix:
15
+ ruby-version: ['2.6', '2.7', '3.0']
16
+
17
+ steps:
18
+ - uses: actions/checkout@v2
19
+ - name: Set up Ruby
20
+ # To automatically get bug fixes and new Ruby versions for ruby/setup-ruby,
21
+ # change this to (see https://github.com/ruby/setup-ruby#versioning):
22
+ # uses: ruby/setup-ruby@v1
23
+ uses: ruby/setup-ruby@473e4d8fe5dd94ee328fdfca9f8c9c7afc9dae5e
24
+ with:
25
+ ruby-version: ${{ matrix.ruby-version }}
26
+ bundler-cache: true # runs 'bundle install' and caches installed gems automatically
27
+ - name: Install dependencies
28
+ run: bundle install
29
+ - name: Run tests
30
+ run: bundle exec rspec spec
data/.gitignore CHANGED
@@ -11,3 +11,5 @@
11
11
 
12
12
  # rspec failure tracking
13
13
  .rspec_status
14
+
15
+ .env.local
@@ -1 +1 @@
1
- ruby-2.5.3
1
+ 2.7.2
@@ -4,6 +4,29 @@ All notable changes to this project will be documented in this file.
4
4
  The format is based on [Keep a Changelog](http://keepachangelog.com/)
5
5
  and this project adheres to [Semantic Versioning](http://semver.org/).
6
6
 
7
+ ## [1.2.4] - 2021-02-01
8
+ ### Fixed
9
+ - Compatibility with Ruby 2.7+ (where `BigDecimal.new` has been removed)
10
+
11
+ ## [1.2.3] - 2021-01-06
12
+ ### Changed
13
+ - `BalanceResponse#success?` first checks if `parsed_body` is present
14
+
15
+ ## [1.2.2] - 2021-01-05
16
+ ### Changed
17
+ - `BalanceResponse` now returns fields, only if `parsed_body` is present
18
+ - Update bundler and ruby versions
19
+ - Moved away from `config.yml` variables to `ENV` variables
20
+ - Added initial Github action for running tests
21
+
22
+ ## [1.2.1] - 2019-02-15
23
+ ### Fixed
24
+ - OrderBook: do not blow up with `JSON::ParserError` when response isn't JSON
25
+
26
+ ## [1.2.0] - 2019-01-09
27
+ ### Added
28
+ - Add `balance` API call to get balances
29
+
7
30
  ## [1.1.0] - 2019-01-07
8
31
  ### Fixed
9
32
  - Factories updated to FactoryBot
data/README.md CHANGED
@@ -1,8 +1,6 @@
1
1
  # BitstampClient
2
2
 
3
- Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/bitstamp_client`. To experiment with that code, run `bin/console` for an interactive prompt.
4
-
5
- TODO: Delete this and the text above, and describe your gem
3
+ API wrapper for Bitstamp.
6
4
 
7
5
  ## Installation
8
6
 
@@ -23,6 +21,7 @@ Or install it yourself as:
23
21
  ## Usage
24
22
 
25
23
  ```ruby
24
+ # Orderbook
26
25
  client = BitstampClient.new
27
26
  response = client.order_book("btcusd")
28
27
  response.success? # true
@@ -32,11 +31,21 @@ order_book.bids # Array of Order instances
32
31
  order_book.asks # Array of Order instances
33
32
  ```
34
33
 
34
+ ```ruby
35
+ # Balance
36
+ client = BitstampClient.new
37
+ response = client.balance(nonce: ...)
38
+ response.success? # true
39
+
40
+ response.usd_balance # BigDecimal
41
+ response.btc_reserved # BigDecimal
42
+ ```
43
+
35
44
  For more, see the files in `spec/acceptance`.
36
45
 
37
46
  ## Development
38
47
 
39
- - Setup `spec/config.yml` (see `spec/config.yml.sample`). Since Bitstamp does not have a test API, you'll need to put real credentials for the tests here. Best to create a subaccount that has a limited set of funds.
48
+ - Make a copy of `.env` and name it `.env.local`
40
49
  - Make changes
41
50
  - `rspec spec` to run the specs
42
51
 
@@ -34,12 +34,13 @@ Gem::Specification.new do |spec|
34
34
  spec.add_dependency "api_client_base", "~> 1.0"
35
35
  spec.add_dependency "typhoeus", "~> 1.0"
36
36
 
37
- spec.add_development_dependency "bundler", "~> 1.14"
37
+ spec.add_development_dependency "bundler", "~> 2.2"
38
+ spec.add_development_dependency "dotenv", "~> 2.7"
39
+ spec.add_development_dependency "factory_bot"
38
40
  spec.add_development_dependency "rake", "~> 10.0"
39
41
  spec.add_development_dependency "rspec", "~> 3.5"
40
42
  spec.add_development_dependency "rspec-its", "~> 1.2"
41
43
  spec.add_development_dependency "vcr", "~> 3.0"
42
- spec.add_development_dependency "webmock", "~> 2.3"
43
44
  spec.add_development_dependency "virtus-matchers", ">= 0.4.0"
44
- spec.add_development_dependency "factory_bot"
45
+ spec.add_development_dependency "webmock", "~> 2.3"
45
46
  end
@@ -8,10 +8,12 @@ require "bitstamp_client/models/market_order"
8
8
  require "bitstamp_client/models/order"
9
9
  require "bitstamp_client/models/order_book"
10
10
  require "bitstamp_client/requests/base_request"
11
+ require "bitstamp_client/requests/balance_request"
11
12
  require "bitstamp_client/requests/exchange_rate_request"
12
13
  require "bitstamp_client/requests/order_book_request"
13
14
  require "bitstamp_client/requests/place_market_order_request"
14
15
  require "bitstamp_client/responses/base_response"
16
+ require "bitstamp_client/responses/balance_response"
15
17
  require "bitstamp_client/responses/exchange_rate_response"
16
18
  require "bitstamp_client/responses/order_book_response"
17
19
  require "bitstamp_client/responses/place_market_order_response"
@@ -9,6 +9,7 @@ module BitstampClient
9
9
  api_action :order_book, args: [:currency_pair]
10
10
  api_action :exchange_rate, args: [:currency_pair]
11
11
  api_action :place_market_order
12
+ api_action :balance
12
13
 
13
14
  private
14
15
 
@@ -0,0 +1,35 @@
1
+ module BitstampClient
2
+ class BalanceRequest < BaseRequest
3
+
4
+ attribute :nonce, Integer
5
+ attribute :signature, String, default: :default_signature
6
+
7
+ private
8
+
9
+ def body
10
+ {
11
+ key: key,
12
+ signature: signature,
13
+ nonce: nonce,
14
+ }
15
+ end
16
+
17
+ def path
18
+ "/api/v2/balance/"
19
+ end
20
+
21
+ def action
22
+ :post
23
+ end
24
+
25
+ def headers
26
+ { 'Content-Type' => 'application/x-www-form-urlencoded' }
27
+ end
28
+
29
+ def default_signature
30
+ GenSignature.
31
+ (key: key, secret: secret, nonce: nonce, customer_id: customer_id)
32
+ end
33
+
34
+ end
35
+ end
@@ -0,0 +1,57 @@
1
+ module BitstampClient
2
+ class BalanceResponse < BaseResponse
3
+
4
+ KNOWN_FIELDS = %i[
5
+ usd_balance
6
+ btc_balance
7
+ eur_balance
8
+ xrp_balance
9
+ usd_reserved
10
+ btc_reserved
11
+ eur_reserved
12
+ xrp_reserved
13
+ usd_available
14
+ btc_available
15
+ eur_available
16
+ xrp_available
17
+ btcusd_fee
18
+ btceur_fee
19
+ eurusd_fee
20
+ xrpusd_fee
21
+ xrpeur_fee
22
+ xrpbtc_fee
23
+ fee
24
+ ].freeze
25
+
26
+ KNOWN_FIELDS.each do |field|
27
+ attribute field, BigDecimal, default: :"default_#{field}"
28
+
29
+ define_method :"default_#{field}" do
30
+ parsed_body[field.to_s] if parsed_body.present?
31
+ end
32
+ end
33
+
34
+ def method_missing(method_name, *args)
35
+ super if !parsed_body.has_key?(method_name.to_s)
36
+
37
+ self.class.define_method(method_name) do
38
+ BigDecimal(parsed_body[method_name.to_s])
39
+ end
40
+
41
+ self.send(method_name)
42
+ end
43
+
44
+ private
45
+
46
+ def default_success
47
+ return false if !parsed_body.present?
48
+
49
+ super
50
+ end
51
+
52
+ def default_order_book
53
+ OrderBook.new(JSON.parse(body))
54
+ end
55
+
56
+ end
57
+ end
@@ -17,6 +17,7 @@ module BitstampClient
17
17
 
18
18
  def default_parsed_body
19
19
  JSON.parse(body)
20
+ rescue JSON::ParserError
20
21
  end
21
22
 
22
23
  end
@@ -9,7 +9,8 @@ module BitstampClient
9
9
  private
10
10
 
11
11
  def default_order_book
12
- OrderBook.new(JSON.parse(body))
12
+ return nil if parsed_body.nil?
13
+ OrderBook.new(parsed_body)
13
14
  end
14
15
 
15
16
  end
@@ -1,3 +1,3 @@
1
1
  module BitstampClient
2
- VERSION = "1.1.0"
2
+ VERSION = "1.2.4"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bitstamp_client
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.0
4
+ version: 1.2.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ramon Tayag
8
- autorequire:
8
+ autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2019-01-07 00:00:00.000000000 Z
11
+ date: 2021-02-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: api_client_base
@@ -44,14 +44,42 @@ dependencies:
44
44
  requirements:
45
45
  - - "~>"
46
46
  - !ruby/object:Gem::Version
47
- version: '1.14'
47
+ version: '2.2'
48
48
  type: :development
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
- version: '1.14'
54
+ version: '2.2'
55
+ - !ruby/object:Gem::Dependency
56
+ name: dotenv
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '2.7'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '2.7'
69
+ - !ruby/object:Gem::Dependency
70
+ name: factory_bot
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
55
83
  - !ruby/object:Gem::Dependency
56
84
  name: rake
57
85
  requirement: !ruby/object:Gem::Requirement
@@ -108,20 +136,6 @@ dependencies:
108
136
  - - "~>"
109
137
  - !ruby/object:Gem::Version
110
138
  version: '3.0'
111
- - !ruby/object:Gem::Dependency
112
- name: webmock
113
- requirement: !ruby/object:Gem::Requirement
114
- requirements:
115
- - - "~>"
116
- - !ruby/object:Gem::Version
117
- version: '2.3'
118
- type: :development
119
- prerelease: false
120
- version_requirements: !ruby/object:Gem::Requirement
121
- requirements:
122
- - - "~>"
123
- - !ruby/object:Gem::Version
124
- version: '2.3'
125
139
  - !ruby/object:Gem::Dependency
126
140
  name: virtus-matchers
127
141
  requirement: !ruby/object:Gem::Requirement
@@ -137,30 +151,31 @@ dependencies:
137
151
  - !ruby/object:Gem::Version
138
152
  version: 0.4.0
139
153
  - !ruby/object:Gem::Dependency
140
- name: factory_bot
154
+ name: webmock
141
155
  requirement: !ruby/object:Gem::Requirement
142
156
  requirements:
143
- - - ">="
157
+ - - "~>"
144
158
  - !ruby/object:Gem::Version
145
- version: '0'
159
+ version: '2.3'
146
160
  type: :development
147
161
  prerelease: false
148
162
  version_requirements: !ruby/object:Gem::Requirement
149
163
  requirements:
150
- - - ">="
164
+ - - "~>"
151
165
  - !ruby/object:Gem::Version
152
- version: '0'
153
- description:
166
+ version: '2.3'
167
+ description:
154
168
  email:
155
169
  - ramon.tayag@gmail.com
156
170
  executables: []
157
171
  extensions: []
158
172
  extra_rdoc_files: []
159
173
  files:
174
+ - ".env"
175
+ - ".github/workflows/tests.yml"
160
176
  - ".gitignore"
161
177
  - ".rspec"
162
178
  - ".ruby-version"
163
- - ".travis.yml"
164
179
  - CHANGELOG.md
165
180
  - CODE_OF_CONDUCT.md
166
181
  - Gemfile
@@ -178,10 +193,12 @@ files:
178
193
  - lib/bitstamp_client/models/market_order.rb
179
194
  - lib/bitstamp_client/models/order.rb
180
195
  - lib/bitstamp_client/models/order_book.rb
196
+ - lib/bitstamp_client/requests/balance_request.rb
181
197
  - lib/bitstamp_client/requests/base_request.rb
182
198
  - lib/bitstamp_client/requests/exchange_rate_request.rb
183
199
  - lib/bitstamp_client/requests/order_book_request.rb
184
200
  - lib/bitstamp_client/requests/place_market_order_request.rb
201
+ - lib/bitstamp_client/responses/balance_response.rb
185
202
  - lib/bitstamp_client/responses/base_response.rb
186
203
  - lib/bitstamp_client/responses/exchange_rate_response.rb
187
204
  - lib/bitstamp_client/responses/order_book_response.rb
@@ -193,7 +210,7 @@ licenses:
193
210
  - MIT
194
211
  metadata:
195
212
  allowed_push_host: https://rubygems.org
196
- post_install_message:
213
+ post_install_message:
197
214
  rdoc_options: []
198
215
  require_paths:
199
216
  - lib
@@ -208,9 +225,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
208
225
  - !ruby/object:Gem::Version
209
226
  version: '0'
210
227
  requirements: []
211
- rubyforge_project:
212
- rubygems_version: 2.7.8
213
- signing_key:
228
+ rubygems_version: 3.0.8
229
+ signing_key:
214
230
  specification_version: 4
215
231
  summary: Ruby wrapper for Bitstamp's API
216
232
  test_files: []
@@ -1,7 +0,0 @@
1
- sudo: false
2
- language: ruby
3
- rvm:
4
- - 2.5.3
5
- before_script:
6
- - cp spec/config.yml{.sample,}
7
- before_install: gem install bundler -v 1.14.6