bitstamp_client 1.0.0 → 1.2.2

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: 284b6c7a1d6d71cf415e7ecaef262865e0ead1c22395d6bcdb5041b86e096aab
4
- data.tar.gz: 0214c9d3d809a5401e48cdec9b9b4e1b8121fb72382dfdcc0ba10cde53a7bedb
3
+ metadata.gz: f5f891fcf088ca5c7de2ebf3f7b9278cd5dcf2da656111bd85b8e7545a8a178a
4
+ data.tar.gz: 4e3ba70c70b3fc4d48fd4df4a2e90449882914c0a3fbea495ea56ea7986374f1
5
5
  SHA512:
6
- metadata.gz: c9c859fd3c2d78225e8698269707bd7b301cd1f42f75e4928f339d1f55e8159dea59158f94a32aef0fc95b4d072bc33d344a6dd95d1b19b32ff1a81414fbbcf1
7
- data.tar.gz: f22dd6da2654178191dc569c643fb7ef6bea9665a407ea962db8e6372f4df7e888de7de7d01b2c22d29ad5a20cc59d2a5cc7694e7203f13fd37ec513cd8f1e5c
6
+ metadata.gz: 828e7216ad247f733817a69dc1f36e95f2ef0185668c009ec93c72dee427544d81ad253abf418365670e0ed21895df7ede2f7fcafdec752e2a9abd63581a4456
7
+ data.tar.gz: aa34e0f6e78f517db198d4932de36d718d4de7c2fc9cfbdc3dfe657dffcbdadac4de2898afe4adb5ce12c65753314b66c923213591ffdf13bef97212b03cfb64
@@ -0,0 +1,3 @@
1
+ KEY=changeme
2
+ SECRET=changeme
3
+ CUSTOMER=1234
@@ -0,0 +1,23 @@
1
+ name: Ruby Tests
2
+
3
+ on:
4
+ push:
5
+ branches: [ $default-branch ]
6
+ pull_request:
7
+ branches: [ $default-branch ]
8
+
9
+ jobs:
10
+ test:
11
+ runs-on: ubuntu-latest
12
+ steps:
13
+ - uses: actions/checkout@v2
14
+ - name: Set up Ruby
15
+ # To automatically get bug fixes and new Ruby versions for ruby/setup-ruby,
16
+ # change this to (see https://github.com/ruby/setup-ruby#versioning):
17
+ # uses: ruby/setup-ruby@v1
18
+ uses: ruby/setup-ruby@ec106b438a1ff6ff109590de34ddc62c540232e0
19
+ - name: Install dependencies
20
+ run: bundle install
21
+ - name: Run tests
22
+ run: bundle exec rspec spec
23
+
data/.gitignore CHANGED
@@ -11,3 +11,6 @@
11
11
 
12
12
  # rspec failure tracking
13
13
  .rspec_status
14
+
15
+ .env
16
+ .env.local
@@ -1 +1 @@
1
- ruby-2.5.3
1
+ 2.6.6
@@ -4,6 +4,32 @@ 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.2] - 2021-01-05
8
+ ### Changed
9
+ - `BalanceResponse` now returns fields, only if `parsed_body` is present
10
+ - Update bundler and ruby versions
11
+ - Moved away from `config.yml` variables to `ENV` variables
12
+ - Added initial Github action for running tests
13
+
14
+ ## [1.2.1] - 2019-02-15
15
+ ### Fixed
16
+ - OrderBook: do not blow up with `JSON::ParserError` when response isn't JSON
17
+
18
+ ## [1.2.0] - 2019-01-09
19
+ ### Added
20
+ - Add `balance` API call to get balances
21
+
22
+ ## [1.1.0] - 2019-01-07
23
+ ### Fixed
24
+ - Factories updated to FactoryBot
25
+
26
+ ### Added
27
+ - `MarketOrder` `#buy` and `#sell`
28
+
29
+ ## [1.0.1] - 2019-01-07
30
+ ### Fixed
31
+ - All responses are not successful when Bitstamp's response has a `status` key
32
+
7
33
  ## [1.0.0] - 2019-01-04
8
34
  ### Added
9
35
  - Place market orders
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,6 +31,16 @@ 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
@@ -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_girl"
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
 
@@ -1,19 +1,19 @@
1
- FactoryGirl.define do
1
+ FactoryBot.define do
2
2
 
3
3
  factory :bitstamp_client_order_book, class: "BitstampClient::OrderBook" do
4
4
  timestamp { Time.now.to_i }
5
5
 
6
6
  bids do
7
7
  [
8
- FactoryGirl.build(:bitstamp_client_order),
9
- FactoryGirl.build(:bitstamp_client_order),
8
+ FactoryBot.build(:bitstamp_client_order),
9
+ FactoryBot.build(:bitstamp_client_order),
10
10
  ]
11
11
  end
12
12
 
13
13
  asks do
14
14
  [
15
- FactoryGirl.build(:bitstamp_client_order),
16
- FactoryGirl.build(:bitstamp_client_order),
15
+ FactoryBot.build(:bitstamp_client_order),
16
+ FactoryBot.build(:bitstamp_client_order),
17
17
  ]
18
18
  end
19
19
  end
@@ -23,4 +23,12 @@ FactoryGirl.define do
23
23
  volume { 2 }
24
24
  end
25
25
 
26
+ factory :bitstamp_client_market_order, class: "BitstampClient::MarketOrder" do
27
+ sequence(:id) {|n| n}
28
+ datetime { DateTime.now }
29
+ type { "0" }
30
+ price { 4000.99 }
31
+ amount { 0.01 }
32
+ end
33
+
26
34
  end
@@ -1,11 +1,26 @@
1
1
  module BitstampClient
2
2
  class MarketOrder < BaseModel
3
3
 
4
+ BUY_CODE = "0".freeze
5
+ SELL_CODE = "1".freeze
6
+
4
7
  attribute :id, String
5
8
  attribute :datetime, DateTime
6
9
  attribute :type, String
7
10
  attribute :price, BigDecimal
8
11
  attribute :amount, BigDecimal
12
+ attribute :buy, Boolean, default: :default_buy, lazy: true
13
+ attribute :sell, Boolean, default: :default_sell, lazy: true
14
+
15
+ private
16
+
17
+ def default_buy
18
+ type == BUY_CODE
19
+ end
20
+
21
+ def default_sell
22
+ type == SELL_CODE
23
+ end
9
24
 
10
25
  end
11
26
  end
@@ -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,52 @@
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.new(parsed_body[method_name.to_s])
39
+ end
40
+
41
+ self.send(method_name)
42
+ end
43
+
44
+ private
45
+
46
+
47
+ def default_order_book
48
+ OrderBook.new(JSON.parse(body))
49
+ end
50
+
51
+ end
52
+ end
@@ -3,6 +3,7 @@ module BitstampClient
3
3
 
4
4
  include APIClientBase::Response.module
5
5
  attribute :body, String, lazy: true, default: :default_body
6
+ attribute :parsed_body, Hash, lazy: true, default: :default_parsed_body
6
7
 
7
8
  private
8
9
 
@@ -10,5 +11,14 @@ module BitstampClient
10
11
  raw_response.body
11
12
  end
12
13
 
14
+ def default_success
15
+ raw_response.success? && !parsed_body.has_key?("status")
16
+ end
17
+
18
+ def default_parsed_body
19
+ JSON.parse(body)
20
+ rescue JSON::ParserError
21
+ end
22
+
13
23
  end
14
24
  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
@@ -7,7 +7,6 @@ module BitstampClient
7
7
  })
8
8
  attribute :status, String, lazy: true, default: :default_status
9
9
  attribute :reason, String, lazy: true, default: :default_reason
10
- attribute :parsed_body, Hash, lazy: true, default: :default_parsed_body
11
10
 
12
11
  private
13
12
 
@@ -23,9 +22,5 @@ module BitstampClient
23
22
  parsed_body["reason"]
24
23
  end
25
24
 
26
- def default_parsed_body
27
- JSON.parse(body)
28
- end
29
-
30
25
  end
31
26
  end
@@ -1,3 +1,3 @@
1
1
  module BitstampClient
2
- VERSION = "1.0.0"
2
+ VERSION = "1.2.2"
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.0.0
4
+ version: 1.2.2
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-04 00:00:00.000000000 Z
11
+ date: 2021-01-05 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_girl
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.sample"
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.3
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