yobit_api 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 +9 -0
- data/.ruby-gemset +1 -0
- data/.ruby-version +1 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +21 -0
- data/README.md +88 -0
- data/Rakefile +2 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/lib/yobit_api.rb +119 -0
- data/lib/yobit_api/version.rb +3 -0
- data/yobit_api.gemspec +29 -0
- metadata +125 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: f0ca0528a337ffb9b6b69f07e8a76fcff431b6ad
|
4
|
+
data.tar.gz: 5b44744c24abd9188700bf04354c7f3bd0561143
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: b75688f48c1ef5d7a6d887ddadbe2f692f3da77650143409f8067d01fb4a46845b37bed0564bcf6b90b22bf7a9a36e47031c81a1c9133db7ae2b1419ed6047fb
|
7
|
+
data.tar.gz: 4bed68bb1b400f6ea33fe55f5de184a3029d1c19503d726ee0853616dd240d7bae0948836d312e0902d22a5367bf661f6fd590076d30f659369cc236745eca5d
|
data/.gitignore
ADDED
data/.ruby-gemset
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
yobit_api
|
data/.ruby-version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
ruby-2.4.1
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2018 Oleg Belov
|
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,88 @@
|
|
1
|
+
# YobitApi
|
2
|
+
|
3
|
+
This gem provides a wrapper for the yobit.net api: [yobit.net](https://yobit.net/en/api)
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
gem 'yobit_api'
|
11
|
+
```
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
$ bundle
|
16
|
+
|
17
|
+
Or install it yourself as:
|
18
|
+
|
19
|
+
$ gem install yobit_api
|
20
|
+
|
21
|
+
## Usage
|
22
|
+
|
23
|
+
1. **Initialize:**
|
24
|
+
|
25
|
+
```ruby
|
26
|
+
client = YobitApi::Client.new
|
27
|
+
```
|
28
|
+
2. **Setup your API key (for Trade API):**
|
29
|
+
|
30
|
+
Use:
|
31
|
+
```ruby
|
32
|
+
client = YobitApi::Client.new(key: 'key', secret: 'secret', key_init_date: '01.01.2018')
|
33
|
+
```
|
34
|
+
Where key_init_date = api key release date or first usage day date.
|
35
|
+
|
36
|
+
Or:
|
37
|
+
```ruby
|
38
|
+
client.config.key = key
|
39
|
+
client.config.secret = secret
|
40
|
+
client.config.key_init_date = '01.01.2018'
|
41
|
+
```
|
42
|
+
3. **Use the api:**
|
43
|
+
|
44
|
+
```ruby
|
45
|
+
client.info
|
46
|
+
```
|
47
|
+
|
48
|
+
Full list of supported methods, see [yobit](https://yobit.net/en/api) for usage.
|
49
|
+
|
50
|
+
*Public API:*
|
51
|
+
```ruby
|
52
|
+
info
|
53
|
+
ticker(['usd_rur'])
|
54
|
+
depth(pairs_list: ['usd_rur'], limit: 1)
|
55
|
+
trades(pairs_list: ['usd_rur'], limit: 1)
|
56
|
+
```
|
57
|
+
|
58
|
+
*Trade API:*
|
59
|
+
```ruby
|
60
|
+
get_info
|
61
|
+
trade(pair: 'usd_rur', type: 'buy', rate: 1, amount: 1)
|
62
|
+
active_orders('usd_rur')
|
63
|
+
order_info(1)
|
64
|
+
cancel_order(1)
|
65
|
+
trade_history(pair: 'usd_rur')
|
66
|
+
get_deposit_address(coin_name: 'BTC', need_new: 0)
|
67
|
+
withdraw_coins_to_address(coin_name: 'BTC', amount: 1, address: 'address')
|
68
|
+
```
|
69
|
+
|
70
|
+
## Development
|
71
|
+
|
72
|
+
After checking out the repo, run `bin/setup` to install dependencies. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
73
|
+
|
74
|
+
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.org](https://rubygems.org).
|
75
|
+
|
76
|
+
## Contributing
|
77
|
+
|
78
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/ThinkAndRun/yobit_api.
|
79
|
+
|
80
|
+
1. Fork it
|
81
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
82
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
83
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
84
|
+
5. Create new Pull Request
|
85
|
+
|
86
|
+
## License
|
87
|
+
|
88
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'bundler/setup'
|
4
|
+
require 'yobit_api'
|
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/yobit_api.rb
ADDED
@@ -0,0 +1,119 @@
|
|
1
|
+
require 'yobit_api/version'
|
2
|
+
require 'openssl'
|
3
|
+
require 'rest-client'
|
4
|
+
require 'addressable/uri'
|
5
|
+
|
6
|
+
module YobitApi
|
7
|
+
PUBLIC_API_URL = 'https://yobit.net/api/3/'.freeze
|
8
|
+
TRADE_API_URL = 'https://yobit.net/tapi/'.freeze
|
9
|
+
|
10
|
+
class Client
|
11
|
+
attr_accessor :config
|
12
|
+
|
13
|
+
def initialize(key: '', secret: '', key_init_date: Time.now)
|
14
|
+
key_init_date = Time.parse(key_init_date) unless key_init_date.is_a? Time
|
15
|
+
Struct.new('ApiConfig', :key, :secret, :key_init_date)
|
16
|
+
@config = Struct::ApiConfig.new(key, secret, key_init_date)
|
17
|
+
raise 'Nonce is expired' if nonce > 2147483646
|
18
|
+
end
|
19
|
+
|
20
|
+
def info
|
21
|
+
get('info')
|
22
|
+
end
|
23
|
+
|
24
|
+
def ticker(pairs_list)
|
25
|
+
currencies = prepare_pairs(pairs_list)
|
26
|
+
get('ticker' + currencies)
|
27
|
+
end
|
28
|
+
|
29
|
+
def depth(pairs_list:, limit: 150)
|
30
|
+
limit = 2000 if (limit > 2000)
|
31
|
+
currencies = prepare_pairs(pairs_list)
|
32
|
+
get('depth' + currencies, limit: limit)
|
33
|
+
end
|
34
|
+
|
35
|
+
def trades(pairs_list:, limit: 150)
|
36
|
+
limit = 2000 if (limit > 2000)
|
37
|
+
currencies = prepare_pairs(pairs_list)
|
38
|
+
get('trades' + currencies, limit: limit)
|
39
|
+
end
|
40
|
+
|
41
|
+
def get_info
|
42
|
+
post('getInfo', client: trade_client)
|
43
|
+
end
|
44
|
+
|
45
|
+
def trade(pair:, type:, rate:, amount:)
|
46
|
+
post('Trade', client: trade_client, pair: pair, type: type, rate: rate, amount: amount)
|
47
|
+
end
|
48
|
+
|
49
|
+
def active_orders(pair)
|
50
|
+
post('ActiveOrders', client: trade_client, pair: pair)
|
51
|
+
end
|
52
|
+
|
53
|
+
def order_info(order_id)
|
54
|
+
post('OrderInfo', client: trade_client, order_id: order_id)
|
55
|
+
end
|
56
|
+
|
57
|
+
def cancel_order(order_id)
|
58
|
+
post('CancelOrder', client: trade_client, order_id: order_id)
|
59
|
+
end
|
60
|
+
|
61
|
+
def trade_history(from: 0, count: 1000, from_id: 0, end_id: 1000, order: 'DESC', since: 0, end_time: Time.new(3000).to_i, pair:)
|
62
|
+
post('TradeHistory', client: trade_client,
|
63
|
+
from: from,
|
64
|
+
count: count,
|
65
|
+
from_id: from_id,
|
66
|
+
end_id: end_id,
|
67
|
+
order: order,
|
68
|
+
since: since,
|
69
|
+
end: end_time,
|
70
|
+
pair: pair)
|
71
|
+
end
|
72
|
+
|
73
|
+
def get_deposit_address(coin_name:, need_new: 0)
|
74
|
+
post('GetDepositAddress', client: trade_client, coinName: coin_name, need_new: need_new)
|
75
|
+
end
|
76
|
+
|
77
|
+
def withdraw_coins_to_address(coin_name:, amount:, address:)
|
78
|
+
post('WithdrawCoinsToAddress', client: trade_client, coinName: coin_name, amount: amount, address: address)
|
79
|
+
end
|
80
|
+
|
81
|
+
protected
|
82
|
+
|
83
|
+
def prepare_pairs(pairs_list)
|
84
|
+
pairs_list.join("-").prepend("/")
|
85
|
+
end
|
86
|
+
|
87
|
+
def public_client
|
88
|
+
@public_client ||= RestClient::Resource.new(YobitApi::PUBLIC_API_URL)
|
89
|
+
end
|
90
|
+
|
91
|
+
def trade_client
|
92
|
+
@trade_client ||= RestClient::Resource.new(YobitApi::TRADE_API_URL)
|
93
|
+
end
|
94
|
+
|
95
|
+
def get(method_name, client: public_client, **params)
|
96
|
+
params = '?'.concat((params.map{ |k,v| "#{k}=#{v}"}).join('&'))
|
97
|
+
client[method_name + params].get
|
98
|
+
rescue => e
|
99
|
+
e.response
|
100
|
+
end
|
101
|
+
|
102
|
+
def post(method_name, client: public_client, **params)
|
103
|
+
params[:nonce] = nonce
|
104
|
+
params[:method] = method_name
|
105
|
+
client.post(params, {key: config.key, sign: create_sign(params)})
|
106
|
+
rescue => e
|
107
|
+
e.response
|
108
|
+
end
|
109
|
+
|
110
|
+
def create_sign(data)
|
111
|
+
encoded_data = Addressable::URI.form_encode(data)
|
112
|
+
OpenSSL::HMAC.hexdigest('sha512', config.secret, encoded_data)
|
113
|
+
end
|
114
|
+
|
115
|
+
def nonce
|
116
|
+
((Time.now - config.key_init_date).to_f * 10).to_i
|
117
|
+
end
|
118
|
+
end
|
119
|
+
end
|
data/yobit_api.gemspec
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'yobit_api/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = 'yobit_api'
|
8
|
+
spec.version = YobitApi::VERSION
|
9
|
+
spec.authors = ['Oleg Belov']
|
10
|
+
|
11
|
+
spec.summary = %q{Yet another Yobit.net API wrapper}
|
12
|
+
spec.description = %q{Yet another Yobit.net API wrapper}
|
13
|
+
spec.homepage = 'https://github.com/ThinkAndRun/yobit_api'
|
14
|
+
spec.license = 'MIT'
|
15
|
+
|
16
|
+
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
17
|
+
f.match(%r{^(test|spec|features)/})
|
18
|
+
end
|
19
|
+
spec.bindir = 'exe'
|
20
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
21
|
+
spec.require_paths = ['lib']
|
22
|
+
|
23
|
+
spec.add_development_dependency 'bundler', '~> 1.16'
|
24
|
+
spec.add_development_dependency 'rake', '~> 10.0'
|
25
|
+
|
26
|
+
spec.add_dependency 'openssl'
|
27
|
+
spec.add_dependency 'rest-client'
|
28
|
+
spec.add_dependency 'addressable'
|
29
|
+
end
|
metadata
ADDED
@@ -0,0 +1,125 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: yobit_api
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Oleg Belov
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2018-03-18 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.16'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.16'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: openssl
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rest-client
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: addressable
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :runtime
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
description: Yet another Yobit.net API wrapper
|
84
|
+
email:
|
85
|
+
executables: []
|
86
|
+
extensions: []
|
87
|
+
extra_rdoc_files: []
|
88
|
+
files:
|
89
|
+
- ".gitignore"
|
90
|
+
- ".ruby-gemset"
|
91
|
+
- ".ruby-version"
|
92
|
+
- Gemfile
|
93
|
+
- LICENSE.txt
|
94
|
+
- README.md
|
95
|
+
- Rakefile
|
96
|
+
- bin/console
|
97
|
+
- bin/setup
|
98
|
+
- lib/yobit_api.rb
|
99
|
+
- lib/yobit_api/version.rb
|
100
|
+
- yobit_api.gemspec
|
101
|
+
homepage: https://github.com/ThinkAndRun/yobit_api
|
102
|
+
licenses:
|
103
|
+
- MIT
|
104
|
+
metadata: {}
|
105
|
+
post_install_message:
|
106
|
+
rdoc_options: []
|
107
|
+
require_paths:
|
108
|
+
- lib
|
109
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
110
|
+
requirements:
|
111
|
+
- - ">="
|
112
|
+
- !ruby/object:Gem::Version
|
113
|
+
version: '0'
|
114
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
115
|
+
requirements:
|
116
|
+
- - ">="
|
117
|
+
- !ruby/object:Gem::Version
|
118
|
+
version: '0'
|
119
|
+
requirements: []
|
120
|
+
rubyforge_project:
|
121
|
+
rubygems_version: 2.6.11
|
122
|
+
signing_key:
|
123
|
+
specification_version: 4
|
124
|
+
summary: Yet another Yobit.net API wrapper
|
125
|
+
test_files: []
|