bitstamp_client 1.0.1 → 1.2.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.env.sample +3 -0
- data/.github/workflows/tests.yml +23 -0
- data/.gitignore +3 -0
- data/.ruby-version +1 -1
- data/CHANGELOG.md +26 -0
- data/README.md +12 -3
- data/bitstamp_client.gemspec +4 -3
- data/lib/bitstamp_client.rb +2 -0
- data/lib/bitstamp_client/client.rb +1 -0
- data/lib/bitstamp_client/factories.rb +13 -5
- data/lib/bitstamp_client/models/market_order.rb +15 -0
- data/lib/bitstamp_client/requests/balance_request.rb +35 -0
- data/lib/bitstamp_client/responses/balance_response.rb +57 -0
- data/lib/bitstamp_client/responses/base_response.rb +1 -0
- data/lib/bitstamp_client/responses/order_book_response.rb +2 -1
- data/lib/bitstamp_client/version.rb +1 -1
- metadata +46 -30
- data/.travis.yml +0 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8cd40bae0407669068df4b5a41644753dc5d3e03f104c06e9971ab7c3cb4ca21
|
4
|
+
data.tar.gz: 55eaefa13988e589e6b641437e48b602eaf769899e6c2644208b9ac64038d36b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 70752c1724e1892564dce76258f14ef43f0526100a42389fcc0c616cb98df3072daa4572f33e843db67cc512ab14d77a936ec11fae2d6a119908cf9cdbf8e989
|
7
|
+
data.tar.gz: fe5a68b9256ec7d0b0b61c1b59c7c2109f85dc2d4120b790cebb94fc5c65d09db924f843aa6171d7306294d9bd213434f8db7878d2681f5c947ed4bd8791fdc1
|
data/.env.sample
ADDED
@@ -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
data/.ruby-version
CHANGED
@@ -1 +1 @@
|
|
1
|
-
|
1
|
+
2.6.6
|
data/CHANGELOG.md
CHANGED
@@ -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.3] - 2021-01-06
|
8
|
+
### Changed
|
9
|
+
- `BalanceResponse#success?` first checks if `parsed_body` is present
|
10
|
+
|
11
|
+
## [1.2.2] - 2021-01-05
|
12
|
+
### Changed
|
13
|
+
- `BalanceResponse` now returns fields, only if `parsed_body` is present
|
14
|
+
- Update bundler and ruby versions
|
15
|
+
- Moved away from `config.yml` variables to `ENV` variables
|
16
|
+
- Added initial Github action for running tests
|
17
|
+
|
18
|
+
## [1.2.1] - 2019-02-15
|
19
|
+
### Fixed
|
20
|
+
- OrderBook: do not blow up with `JSON::ParserError` when response isn't JSON
|
21
|
+
|
22
|
+
## [1.2.0] - 2019-01-09
|
23
|
+
### Added
|
24
|
+
- Add `balance` API call to get balances
|
25
|
+
|
26
|
+
## [1.1.0] - 2019-01-07
|
27
|
+
### Fixed
|
28
|
+
- Factories updated to FactoryBot
|
29
|
+
|
30
|
+
### Added
|
31
|
+
- `MarketOrder` `#buy` and `#sell`
|
32
|
+
|
7
33
|
## [1.0.1] - 2019-01-07
|
8
34
|
### Fixed
|
9
35
|
- All responses are not successful when Bitstamp's response has a `status` key
|
data/README.md
CHANGED
@@ -1,8 +1,6 @@
|
|
1
1
|
# BitstampClient
|
2
2
|
|
3
|
-
|
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
|
data/bitstamp_client.gemspec
CHANGED
@@ -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", "~>
|
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 "
|
45
|
+
spec.add_development_dependency "webmock", "~> 2.3"
|
45
46
|
end
|
data/lib/bitstamp_client.rb
CHANGED
@@ -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"
|
@@ -1,19 +1,19 @@
|
|
1
|
-
|
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
|
-
|
9
|
-
|
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
|
-
|
16
|
-
|
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,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.new(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
|
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.
|
4
|
+
version: 1.2.3
|
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:
|
11
|
+
date: 2021-01-06 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: '
|
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: '
|
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:
|
154
|
+
name: webmock
|
141
155
|
requirement: !ruby/object:Gem::Requirement
|
142
156
|
requirements:
|
143
|
-
- - "
|
157
|
+
- - "~>"
|
144
158
|
- !ruby/object:Gem::Version
|
145
|
-
version: '
|
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: '
|
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
|
-
|
212
|
-
|
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: []
|