viabtc 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +11 -0
- data/.rspec +3 -0
- data/.ruby-gemset +1 -0
- data/.ruby-version +1 -0
- data/.travis.yml +7 -0
- data/Gemfile +6 -0
- data/Gemfile.lock +39 -0
- data/LICENSE.txt +21 -0
- data/README.md +110 -0
- data/Rakefile +6 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/lib/viabtc.rb +7 -0
- data/lib/viabtc/client.rb +238 -0
- data/lib/viabtc/config.rb +18 -0
- data/lib/viabtc/error.rb +36 -0
- data/lib/viabtc/version.rb +3 -0
- data/viabtc.gemspec +37 -0
- metadata +118 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 001c022a1d7cea8cee798dbef1a1972d2ac3bd4c12455f0a50857a34c6d1333e
|
4
|
+
data.tar.gz: 30e6f00cc3995811a92c393574799f2c987daa8df35110956bb0b8f8ce934ff8
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 63705cdc98e7ccfb8c533c097a2e2175fa26068aa649504980039b7bed73ac742e12fa49c6527b5cb59025401ade9c17399baa3de16e4b97695191c6e57bc988
|
7
|
+
data.tar.gz: 8aec121d9db1a212d772f15b797d3c1cf0a83131b89df2365ef519fa6d90561dd9f727db839ec2a588f27b7140f023fe36431fa89461aa39de68e8928766ba3a
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.ruby-gemset
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
viabtc
|
data/.ruby-version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
ruby-2.5.3
|
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,39 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
viabtc (0.1.0)
|
5
|
+
faraday (~> 0.15.3)
|
6
|
+
|
7
|
+
GEM
|
8
|
+
remote: https://rubygems.org/
|
9
|
+
specs:
|
10
|
+
diff-lcs (1.3)
|
11
|
+
faraday (0.15.3)
|
12
|
+
multipart-post (>= 1.2, < 3)
|
13
|
+
multipart-post (2.0.0)
|
14
|
+
rake (10.5.0)
|
15
|
+
rspec (3.8.0)
|
16
|
+
rspec-core (~> 3.8.0)
|
17
|
+
rspec-expectations (~> 3.8.0)
|
18
|
+
rspec-mocks (~> 3.8.0)
|
19
|
+
rspec-core (3.8.0)
|
20
|
+
rspec-support (~> 3.8.0)
|
21
|
+
rspec-expectations (3.8.2)
|
22
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
23
|
+
rspec-support (~> 3.8.0)
|
24
|
+
rspec-mocks (3.8.0)
|
25
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
26
|
+
rspec-support (~> 3.8.0)
|
27
|
+
rspec-support (3.8.0)
|
28
|
+
|
29
|
+
PLATFORMS
|
30
|
+
ruby
|
31
|
+
|
32
|
+
DEPENDENCIES
|
33
|
+
bundler (~> 1.17)
|
34
|
+
rake (~> 10.0)
|
35
|
+
rspec (~> 3.0)
|
36
|
+
viabtc!
|
37
|
+
|
38
|
+
BUNDLED WITH
|
39
|
+
1.17.1
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2018 Kerem Bozdas
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,110 @@
|
|
1
|
+
# ViaBTC
|
2
|
+
|
3
|
+
[](https://travis-ci.org/krmbzds/viabtc)
|
4
|
+
|
5
|
+
An HTTP client to interface with the open-source [ViaBTC Exchange Server][ViaBTC Exchange Server Repo] API.
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
Add `viabtc` to your Gemfile and run `bundle` OR install it yourself with `gem install viabtc`.
|
10
|
+
|
11
|
+
## Configuration
|
12
|
+
|
13
|
+
If using **Rails**, create a file named `viabtc.rb` under `config/initializers` and add the following block of code.
|
14
|
+
|
15
|
+
```rb
|
16
|
+
ViaBTC.configure do |config|
|
17
|
+
config.base_url = 'http://localhost:18080'
|
18
|
+
config.faraday_response = :logger
|
19
|
+
config.faraday_adapter = :net_http
|
20
|
+
end
|
21
|
+
```
|
22
|
+
|
23
|
+
If not, add it anywhere in your code that runs before a new client is initialized.
|
24
|
+
|
25
|
+
## Usage
|
26
|
+
|
27
|
+
Create a new instance:
|
28
|
+
|
29
|
+
```rb
|
30
|
+
viabtc_client = ViaBTC::Client.new
|
31
|
+
```
|
32
|
+
|
33
|
+
Make an API request:
|
34
|
+
|
35
|
+
```rb
|
36
|
+
viabtc_client.market_status(market: 'ETHBTC')
|
37
|
+
```
|
38
|
+
|
39
|
+
Market status example output:
|
40
|
+
```rb
|
41
|
+
{"error"=>nil, "result"=>{"low"=>"0", "period"=>86400, "last"=>"0", "high"=>"0", "open"=>"0", "volume"=>"0", "close"=>"0", "deal"=>"0"}, "id"=>0}
|
42
|
+
```
|
43
|
+
|
44
|
+
## Support
|
45
|
+
|
46
|
+
### API Actions
|
47
|
+
|
48
|
+
#### HTTP Protocol
|
49
|
+
|
50
|
+
| API Method | Corresponding Methods |
|
51
|
+
|---|---|
|
52
|
+
| `balance.query` | `#balance` |
|
53
|
+
| `balance.update` | `#withdraw` `#deposit` |
|
54
|
+
| `balance.history` | `#balance_history` |
|
55
|
+
| `asset.list` | `#asset_list` |
|
56
|
+
| `asset.summary` | `#asset_summary` |
|
57
|
+
| `order.put_limit` | `#limit_sell` `#limit_buy` |
|
58
|
+
| `order.put_market` | `#market_sell` `#market_buy` |
|
59
|
+
| `order.cancel` | `#cancel_order` |
|
60
|
+
| `order.deals` | `#order_deals` |
|
61
|
+
| `order.book` | `#sell_orders` `#buy_orders` |
|
62
|
+
| `order.depth` | `#order_depth` |
|
63
|
+
| `order.pending` | `#pending_orders` |
|
64
|
+
| `order.pending_detail` | `#pending_order_details` |
|
65
|
+
| `order.finished` | `#finished_orders` `#finished_sell_orders` `#finished_buy_orders` |
|
66
|
+
| `order.finished_detail` | `#finished_order_detail` |
|
67
|
+
| `market.last` | `#market_last` |
|
68
|
+
| `market.deals` | `#market_deals` |
|
69
|
+
| `market.user_deals` | `#user_executed_orders` |
|
70
|
+
| `market.kline` | `#market_kline` |
|
71
|
+
| `market.status` | `#market_status` |
|
72
|
+
| `market.status_today` | `#market_status_today` |
|
73
|
+
| `market.list` | `#market_list` |
|
74
|
+
| `market.summary` | `#market_summary` |
|
75
|
+
|
76
|
+
## Development
|
77
|
+
|
78
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
79
|
+
|
80
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [RubyGems][RubyGems].
|
81
|
+
|
82
|
+
## Contributing
|
83
|
+
|
84
|
+
1. [Fork the repository][Fork]
|
85
|
+
2. Switch to develop branch (`git checkout develop`)
|
86
|
+
3. Create your feature branch (`git checkout -b my-new-feature`)
|
87
|
+
4. Commit your changes (`git commit -am 'Add some feature'`)
|
88
|
+
5. Push to the branch (`git push origin my-new-feature`)
|
89
|
+
6. Create new Pull Request
|
90
|
+
|
91
|
+
### Donations
|
92
|
+
|
93
|
+
You can donate me at [Librepay][Donation]. Thanks! ☕️
|
94
|
+
|
95
|
+
## Is it any good?
|
96
|
+
|
97
|
+
Yes.
|
98
|
+
|
99
|
+
## License
|
100
|
+
|
101
|
+
Copyright © 2019 [Kerem Bozdas][Personal Webpage]
|
102
|
+
|
103
|
+
This gem is available under the terms of the [MIT License][License].
|
104
|
+
|
105
|
+
[Donation]: https://liberapay.com/krmbzds/donate
|
106
|
+
[Fork]: http://github.com/krmbzds/viabtc/fork
|
107
|
+
[License]: http://kerem.mit-license.org
|
108
|
+
[Personal Webpage]: http://kerembozdas.com
|
109
|
+
[RubyGems]: https://rubygems.org
|
110
|
+
[ViaBTC Exchange Server Repo]: https://github.com/viabtc/viabtc_exchange_server
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'bundler/setup'
|
4
|
+
require 'viabtc'
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require 'pry'
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require 'irb'
|
14
|
+
IRB.start(__FILE__)
|
data/bin/setup
ADDED
data/lib/viabtc.rb
ADDED
@@ -0,0 +1,238 @@
|
|
1
|
+
module ViaBTC
|
2
|
+
class Client
|
3
|
+
def initialize(base_url: nil, faraday_response: nil, faraday_adapter: nil)
|
4
|
+
if ViaBTC.configuration
|
5
|
+
base_url ||= ViaBTC.configuration.base_url
|
6
|
+
faraday_response ||= ViaBTC.configuration.faraday_response || :logger
|
7
|
+
faraday_adapter ||= ViaBTC.configuration.faraday_adapter || :net_http
|
8
|
+
else
|
9
|
+
faraday_response ||= :logger
|
10
|
+
faraday_adapter ||= :net_http
|
11
|
+
end
|
12
|
+
|
13
|
+
raise ViaBTC::Error::Configuration, 'required: base_url' unless base_url
|
14
|
+
|
15
|
+
@connection ||= Faraday.new(base_url) do |conn|
|
16
|
+
conn.response faraday_response
|
17
|
+
conn.adapter faraday_adapter
|
18
|
+
conn.headers['Content-Type'] = ['application/json']
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
# Asset API
|
23
|
+
|
24
|
+
def balance(user_id:, id: 0)
|
25
|
+
request(id: id, method: 'balance.query', params: [user_id])
|
26
|
+
end
|
27
|
+
|
28
|
+
def withdraw(user_id:, asset:, withdraw_id:, amount:, source: 'web', id: 0)
|
29
|
+
raise ViaBTC::Error::InvalidParameter, "invalid amount: #{amount}" unless amount_valid?(amount)
|
30
|
+
request(
|
31
|
+
id: id,
|
32
|
+
method: 'balance.update',
|
33
|
+
params: [user_id, asset, 'withdraw', withdraw_id, amount, {source: source}]
|
34
|
+
)
|
35
|
+
end
|
36
|
+
|
37
|
+
def deposit(user_id:, asset:, deposit_id:, amount:, source: 'web', id: 0)
|
38
|
+
raise ViaBTC::Error::InvalidParameter, "invalid amount: #{amount}" unless amount_valid?(amount)
|
39
|
+
request(
|
40
|
+
id: id,
|
41
|
+
method: 'balance.update',
|
42
|
+
params: [user_id, asset, 'deposit', deposit_id, amount, {source: source}]
|
43
|
+
)
|
44
|
+
end
|
45
|
+
|
46
|
+
def balance_history(user_id:, asset:, business: '', start_time: 0, end_time: 0, offset: 0, limit: 100, id: 0)
|
47
|
+
request(id: id, method: 'balance.history', params: [user_id, asset, business, start_time, end_time, offset, limit])
|
48
|
+
end
|
49
|
+
|
50
|
+
def asset_list
|
51
|
+
request(method: 'asset.list', params: [])
|
52
|
+
end
|
53
|
+
|
54
|
+
def asset_summary
|
55
|
+
request(method: 'asset.summary', params: [])
|
56
|
+
end
|
57
|
+
|
58
|
+
# Trade API
|
59
|
+
|
60
|
+
def limit_sell(user_id:, market:, amount:, price:, taker_fee_rate:, maker_fee_rate:, source: 'web', id: 0)
|
61
|
+
raise ViaBTC::Error::InvalidParameter, "invalid amount: #{amount}" unless amount_valid?(amount)
|
62
|
+
raise ViaBTC::Error::InvalidParameter, "invalid fee rate #{taker_fee_rate}" unless fee_rate_valid?(taker_fee_rate)
|
63
|
+
raise ViaBTC::Error::InvalidParameter, "invalid fee rate #{maker_fee_rate}" unless fee_rate_valid?(maker_fee_rate)
|
64
|
+
request(
|
65
|
+
id: id,
|
66
|
+
method: 'order.put_limit',
|
67
|
+
params: [user_id, market, 1, amount, price, taker_fee_rate, maker_fee_rate, source]
|
68
|
+
)
|
69
|
+
end
|
70
|
+
|
71
|
+
def limit_buy(user_id:, market:, amount:, price:, taker_fee_rate:, source: 'web', id: 0)
|
72
|
+
raise ViaBTC::Error::InvalidParameter, "invalid amount: #{amount}" unless amount_valid?(amount)
|
73
|
+
raise ViaBTC::Error::InvalidParameter, "invalid fee rate #{taker_fee_rate}" unless fee_rate_valid?(taker_fee_rate)
|
74
|
+
raise ViaBTC::Error::InvalidParameter, "invalid fee rate #{maker_fee_rate}" unless fee_rate_valid?(maker_fee_rate)
|
75
|
+
request(
|
76
|
+
id: id,
|
77
|
+
method: 'order.put_limit',
|
78
|
+
params: [user_id, market, 2, amount, price, taker_fee_rate, maker_fee_rate, source]
|
79
|
+
)
|
80
|
+
end
|
81
|
+
|
82
|
+
def market_sell(user_id:, market:, amount:, taker_fee_rate:, source: 'web', id: 0)
|
83
|
+
raise ViaBTC::Error::InvalidParameter, "invalid amount: #{amount}" unless amount_valid?(amount)
|
84
|
+
raise ViaBTC::Error::InvalidParameter, "invalid fee rate #{taker_fee_rate}" unless fee_rate_valid?(taker_fee_rate)
|
85
|
+
request(
|
86
|
+
id: id,
|
87
|
+
method: 'order.put_market',
|
88
|
+
params: [user_id, market, 1, amount, taker_fee_rate.to_s, source]
|
89
|
+
)
|
90
|
+
end
|
91
|
+
|
92
|
+
def market_buy(user_id:, market:, amount:, taker_fee_rate:, source: 'web', id: 0)
|
93
|
+
raise ViaBTC::Error::InvalidParameter, "invalid amount: #{amount}" unless amount_valid?(amount)
|
94
|
+
raise ViaBTC::Error::InvalidParameter, "invalid fee rate #{taker_fee_rate}" unless fee_rate_valid?(taker_fee_rate)
|
95
|
+
request(
|
96
|
+
id: id,
|
97
|
+
method: 'order.put_market',
|
98
|
+
params: [user_id, market, 2, amount, taker_fee_rate.to_s, source]
|
99
|
+
)
|
100
|
+
end
|
101
|
+
|
102
|
+
def cancel_order(user_id:, market:, order_id:, id: 0)
|
103
|
+
request(id: id, method: 'order.cancel', params: [user_id, market, order_id])
|
104
|
+
end
|
105
|
+
|
106
|
+
def order_deals(order_id:, offset: 0, limit: 100, id:0)
|
107
|
+
request(id: id, method: 'order.deals', params: [order_id, offset, limit])
|
108
|
+
end
|
109
|
+
|
110
|
+
def sell_orders(market:, offset: 0, limit: 100, id: 0)
|
111
|
+
request(id: id, method: 'order.book', params: [market, 1, offset, limit])
|
112
|
+
end
|
113
|
+
|
114
|
+
def buy_orders(market:, offset: 0, limit: 100, id: 0)
|
115
|
+
request(id: id, method: 'order.book', params: [market, 2, offset, limit])
|
116
|
+
end
|
117
|
+
|
118
|
+
def order_depth(market:, limit: 100, interval: '0', id: 0)
|
119
|
+
request(id: id, method: 'order.depth', params: [market, limit, interval])
|
120
|
+
end
|
121
|
+
|
122
|
+
def pending_orders(user_id:, market:, offset: 0, limit: 100, id: 0)
|
123
|
+
request(id: id, method: 'order.pending', params: [user_id, market, offset, limit])
|
124
|
+
end
|
125
|
+
|
126
|
+
def pending_order_details(order_id:, market:, id: 0)
|
127
|
+
request(id: id, method: 'order.pending_detail', params: [market, order_id])
|
128
|
+
end
|
129
|
+
|
130
|
+
def finished_orders(user_id:, market:, start_time: 0, end_time: 0, offset: 0, limit: 100, side:0, id: 0)
|
131
|
+
request(id: id, method: 'order.finished', params: [user_id, market, start_time, end_time, offset, limit, side])
|
132
|
+
end
|
133
|
+
|
134
|
+
def finished_sell_orders(user_id:, market:, start_time: 0, end_time: 0, offset: 0, limit: 100, side:1, id: 0)
|
135
|
+
request(id: id, method: 'order.finished', params: [user_id, market, start_time, end_time, offset, limit, side])
|
136
|
+
end
|
137
|
+
|
138
|
+
def finished_buy_orders(user_id:, market:, start_time: 0, end_time: 0, offset: 0, limit: 100, side:2, id: 0)
|
139
|
+
request(id: id, method: 'order.finished', params: [user_id, market, start_time, end_time, offset, limit, side])
|
140
|
+
end
|
141
|
+
|
142
|
+
def finished_order_detail(order_id:, id: 0)
|
143
|
+
request(id: id, method: 'order.finished_detail', params: [order_id])
|
144
|
+
end
|
145
|
+
|
146
|
+
# Market API
|
147
|
+
|
148
|
+
def market_last(market:, id: 0)
|
149
|
+
request(id: id, method: 'market.last', params: [market])
|
150
|
+
end
|
151
|
+
|
152
|
+
def market_deals(market:, limit: 10000, last_id: 0, id: 0)
|
153
|
+
request(id: id, method: 'market.deals', params: [market, limit, last_id])
|
154
|
+
end
|
155
|
+
|
156
|
+
def user_executed_orders(user_id:, market:, offset: 0, limit: 100, id: 0)
|
157
|
+
request(id: id, method: 'market.user_deals', params: [user_id, market, offset, limit])
|
158
|
+
end
|
159
|
+
|
160
|
+
def market_kline(market:, start_time: now - 86400, end_time: now, interval: 3600, id: 0)
|
161
|
+
request(id: id, method: 'market.kline', params: [market, start_time, end_time, interval])
|
162
|
+
end
|
163
|
+
|
164
|
+
def market_status(market:, period: 86400, id: 0)
|
165
|
+
request(id: id, method: 'market.status', params: [market, period])
|
166
|
+
end
|
167
|
+
|
168
|
+
def market_status_today(market:, id: 0)
|
169
|
+
market_status(market: market, period: 86400, id: id)
|
170
|
+
end
|
171
|
+
|
172
|
+
def market_list(id: 0)
|
173
|
+
request(id: id, method: 'market.list', params: [])
|
174
|
+
end
|
175
|
+
|
176
|
+
def market_summary(id: 0)
|
177
|
+
request(id: id, method: 'market.summary', params: [])
|
178
|
+
end
|
179
|
+
|
180
|
+
private
|
181
|
+
|
182
|
+
def request(method:, params:, id: 0)
|
183
|
+
response = @connection.post do |req|
|
184
|
+
req.body = {
|
185
|
+
'id' => id,
|
186
|
+
'method' => method,
|
187
|
+
'params' => params
|
188
|
+
}.to_json
|
189
|
+
end
|
190
|
+
response = JSON.parse(response.body)
|
191
|
+
raise_exchange_error(response) if response_invalid?(response)
|
192
|
+
response
|
193
|
+
end
|
194
|
+
|
195
|
+
def response_invalid?(response)
|
196
|
+
!response['error'].nil?
|
197
|
+
end
|
198
|
+
|
199
|
+
def amount_valid?(amount)
|
200
|
+
amount.is_a?(Numeric) && amount.positive? && (amount.is_a?(Integer) || amount.is_a?(Float))
|
201
|
+
end
|
202
|
+
|
203
|
+
def fee_rate_valid?(fee_rate)
|
204
|
+
(0...1).cover?(fee_rate)
|
205
|
+
end
|
206
|
+
|
207
|
+
def now
|
208
|
+
Time.now.to_i
|
209
|
+
end
|
210
|
+
|
211
|
+
def raise_exchange_error(response)
|
212
|
+
error_code = response['error']['code']
|
213
|
+
error_message = response['error']['message']
|
214
|
+
|
215
|
+
case error_code
|
216
|
+
when 1 then raise ViaBTC::Error::InvalidArgument.new(response)
|
217
|
+
when 2 then raise ViaBTC::Error::InternalError.new(response)
|
218
|
+
when 3 then raise ViaBTC::Error::ServiceUnavailable.new(response)
|
219
|
+
when 4 then raise ViaBTC::Error::MethodNotFound.new(response)
|
220
|
+
when 5 then raise ViaBTC::Error::ServiceTimeout.new(response)
|
221
|
+
when 10
|
222
|
+
case error_message
|
223
|
+
when 'balance not enough' then raise ViaBTC::Error::LimitOrderBalanceNotEnough.new(response)
|
224
|
+
when 'repeat update' then raise ViaBTC::Error::RepeatBalanceUpdate.new(response)
|
225
|
+
else raise ViaBTC::Error::ExchangeError.new(response)
|
226
|
+
end
|
227
|
+
when 11
|
228
|
+
case error_message
|
229
|
+
when 'amount too small' then raise ViaBTC::Error::LimitOrderAmountTooSmall.new(response)
|
230
|
+
when 'balance not enough' then raise ViaBTC::Error::BalanceNotEnough.new(response)
|
231
|
+
end
|
232
|
+
when 12 then raise ViaBTC::Error::LimitOrderNoEnoughTrader.new(response)
|
233
|
+
else raise ViaBTC::Error::ExchangeError.new(response)
|
234
|
+
end
|
235
|
+
end
|
236
|
+
|
237
|
+
end
|
238
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
module ViaBTC
|
2
|
+
class << self
|
3
|
+
attr_accessor :configuration
|
4
|
+
end
|
5
|
+
|
6
|
+
def self.configure
|
7
|
+
self.configuration ||= Configuration.new
|
8
|
+
yield(configuration)
|
9
|
+
end
|
10
|
+
|
11
|
+
class Configuration
|
12
|
+
attr_accessor :base_url, :faraday_response, :faraday_adapter
|
13
|
+
|
14
|
+
def initialize
|
15
|
+
@base_url = nil
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
data/lib/viabtc/error.rb
ADDED
@@ -0,0 +1,36 @@
|
|
1
|
+
module ViaBTC
|
2
|
+
module Error
|
3
|
+
# ViaBTC Module Error Classes
|
4
|
+
ViaBTCError = Class.new(StandardError) # Module Base Error Class
|
5
|
+
Configuration = Class.new(ViaBTCError) # Module Config Error
|
6
|
+
InvalidParameter = Class.new(ViaBTCError) # Module Invalid Param Error
|
7
|
+
|
8
|
+
# ViaBTC Exchange Server Base Error Class
|
9
|
+
class ExchangeError < StandardError
|
10
|
+
attr_reader :response
|
11
|
+
def initialize(response)
|
12
|
+
@code = response['error']['code']
|
13
|
+
@message = response['error']['message']
|
14
|
+
@response = response
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
# ViaBTC Exchange Server General Error Codes
|
19
|
+
InvalidArgument = Class.new(ExchangeError) # 1: Invalid Argument
|
20
|
+
InternalError = Class.new(ExchangeError) # 2: Internal Error
|
21
|
+
ServiceUnavailable = Class.new(ExchangeError) # 3: Service Unavailable
|
22
|
+
MethodNotFound = Class.new(ExchangeError) # 4: Method Not Found
|
23
|
+
ServiceTimeout = Class.new(ExchangeError) # 5: Service Timeout
|
24
|
+
|
25
|
+
# ViaBTC Exchange Server Undocumented Error Codes with Gotchas
|
26
|
+
|
27
|
+
# matchengine/me_server.c: on_cmd_order_put_limit
|
28
|
+
LimitOrderBalanceNotEnough = Class.new(ExchangeError) # 10: Balance Not Enough
|
29
|
+
LimitOrderAmountTooSmall = Class.new(ExchangeError) # 11: Amount Too Small
|
30
|
+
LimitOrderNoEnoughTrader = Class.new(ExchangeError) # 12: No Enough Trader
|
31
|
+
|
32
|
+
# matchengine/me_server.c: on_cmd_balance_update
|
33
|
+
RepeatBalanceUpdate = Class.new(ExchangeError) # 10: Repeat Update
|
34
|
+
BalanceNotEnough = Class.new(ExchangeError) # 11: Balance Not Enough
|
35
|
+
end
|
36
|
+
end
|
data/viabtc.gemspec
ADDED
@@ -0,0 +1,37 @@
|
|
1
|
+
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'viabtc/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = 'viabtc'
|
8
|
+
spec.version = ViaBTC::VERSION
|
9
|
+
spec.authors = ['Kerem Bozdas']
|
10
|
+
spec.email = ['krmbzds.github@gmail.com']
|
11
|
+
|
12
|
+
spec.summary = 'ViaBTC Exchange Server API Wrapper'
|
13
|
+
spec.description = 'An HTTP Client to Interface with the Open-Source ViaBTC Exchange Server'
|
14
|
+
spec.homepage = 'https://github.com/krmbzds/viabtc/'
|
15
|
+
spec.license = 'MIT'
|
16
|
+
|
17
|
+
# Specify which files should be added to the gem when it is released.
|
18
|
+
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
19
|
+
spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
|
20
|
+
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
21
|
+
end
|
22
|
+
|
23
|
+
spec.bindir = 'exe'
|
24
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
25
|
+
spec.require_paths = ['lib']
|
26
|
+
|
27
|
+
# Ruby required keyword arguments
|
28
|
+
spec.required_ruby_version = '>= 2.1.0'
|
29
|
+
|
30
|
+
# Runtime dependencies
|
31
|
+
spec.add_dependency 'faraday', '~> 0.15.3'
|
32
|
+
|
33
|
+
# Development dependencies
|
34
|
+
spec.add_development_dependency 'bundler', '~> 1.17'
|
35
|
+
spec.add_development_dependency 'rake', '~> 10.0'
|
36
|
+
spec.add_development_dependency 'rspec', '~> 3.0'
|
37
|
+
end
|
metadata
ADDED
@@ -0,0 +1,118 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: viabtc
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Kerem Bozdas
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2018-11-17 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: faraday
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 0.15.3
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 0.15.3
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: bundler
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '1.17'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '1.17'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rake
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '10.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '10.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rspec
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '3.0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '3.0'
|
69
|
+
description: An HTTP Client to Interface with the Open-Source ViaBTC Exchange Server
|
70
|
+
email:
|
71
|
+
- krmbzds.github@gmail.com
|
72
|
+
executables: []
|
73
|
+
extensions: []
|
74
|
+
extra_rdoc_files: []
|
75
|
+
files:
|
76
|
+
- ".gitignore"
|
77
|
+
- ".rspec"
|
78
|
+
- ".ruby-gemset"
|
79
|
+
- ".ruby-version"
|
80
|
+
- ".travis.yml"
|
81
|
+
- Gemfile
|
82
|
+
- Gemfile.lock
|
83
|
+
- LICENSE.txt
|
84
|
+
- README.md
|
85
|
+
- Rakefile
|
86
|
+
- bin/console
|
87
|
+
- bin/setup
|
88
|
+
- lib/viabtc.rb
|
89
|
+
- lib/viabtc/client.rb
|
90
|
+
- lib/viabtc/config.rb
|
91
|
+
- lib/viabtc/error.rb
|
92
|
+
- lib/viabtc/version.rb
|
93
|
+
- viabtc.gemspec
|
94
|
+
homepage: https://github.com/krmbzds/viabtc/
|
95
|
+
licenses:
|
96
|
+
- MIT
|
97
|
+
metadata: {}
|
98
|
+
post_install_message:
|
99
|
+
rdoc_options: []
|
100
|
+
require_paths:
|
101
|
+
- lib
|
102
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
103
|
+
requirements:
|
104
|
+
- - ">="
|
105
|
+
- !ruby/object:Gem::Version
|
106
|
+
version: 2.1.0
|
107
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
108
|
+
requirements:
|
109
|
+
- - ">="
|
110
|
+
- !ruby/object:Gem::Version
|
111
|
+
version: '0'
|
112
|
+
requirements: []
|
113
|
+
rubyforge_project:
|
114
|
+
rubygems_version: 2.7.6
|
115
|
+
signing_key:
|
116
|
+
specification_version: 4
|
117
|
+
summary: ViaBTC Exchange Server API Wrapper
|
118
|
+
test_files: []
|