ru_bittrex 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.github/workflows/ruby.yml +23 -0
- data/.gitignore +9 -0
- data/Gemfile +2 -0
- data/Gemfile.lock +27 -0
- data/LICENSE.txt +21 -0
- data/README.md +134 -0
- data/Rakefile +10 -0
- data/bin/console +13 -0
- data/bin/setup +6 -0
- data/credentials.example.yml +4 -0
- data/lib/ru_bittrex.rb +47 -0
- data/lib/ru_bittrex/account.rb +24 -0
- data/lib/ru_bittrex/address.rb +26 -0
- data/lib/ru_bittrex/balance.rb +25 -0
- data/lib/ru_bittrex/client.rb +69 -0
- data/lib/ru_bittrex/client_api.rb +96 -0
- data/lib/ru_bittrex/client_helper.rb +18 -0
- data/lib/ru_bittrex/configuration.rb +14 -0
- data/lib/ru_bittrex/currency.rb +32 -0
- data/lib/ru_bittrex/deposit.rb +37 -0
- data/lib/ru_bittrex/helpers.rb +10 -0
- data/lib/ru_bittrex/market.rb +32 -0
- data/lib/ru_bittrex/order.rb +5 -0
- data/lib/ru_bittrex/summary.rb +28 -0
- data/lib/ru_bittrex/ticker.rb +24 -0
- data/lib/ru_bittrex/version.rb +3 -0
- data/ru_bittrex.gemspec +29 -0
- data/test/fixtures/account.json +5 -0
- data/test/fixtures/address.json +5 -0
- data/test/fixtures/balance.json +6 -0
- data/test/fixtures/currency.json +13 -0
- data/test/fixtures/deposit.json +13 -0
- data/test/fixtures/market.json +12 -0
- data/test/fixtures/summary.json +9 -0
- data/test/fixtures/ticker.json +6 -0
- data/test/ru_bittrex/account_test.rb +31 -0
- data/test/ru_bittrex/address_test.rb +30 -0
- data/test/ru_bittrex/balance_test.rb +32 -0
- data/test/ru_bittrex/client_api_test.rb +61 -0
- data/test/ru_bittrex/client_helper_test.rb +48 -0
- data/test/ru_bittrex/client_test.rb +45 -0
- data/test/ru_bittrex/configuration_test.rb +61 -0
- data/test/ru_bittrex/currency_test.rb +38 -0
- data/test/ru_bittrex/deposit_test.rb +47 -0
- data/test/ru_bittrex/helpers_test.rb +17 -0
- data/test/ru_bittrex/market_test.rb +38 -0
- data/test/ru_bittrex/summary_test.rb +35 -0
- data/test/ru_bittrex/ticker_test.rb +31 -0
- data/test/ru_bittrex_test.rb +7 -0
- data/test/test_helper.rb +10 -0
- metadata +178 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 18d0a412304dc74b70d6d3aabb78f48a514620bb8fb4b2bc683bd1dea7b18711
|
4
|
+
data.tar.gz: '0588a04c4eec8630ba2ac650c0df1384b5924f1083d44bf09dfeca4a164e5aec'
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: dcead54bb062b4322610fc19ccf768480c4092dc156a4d7a53d2682e7fb477fd19d7c9e73d9a32ad2e6cba49548e98107f0c2c5143e9d969ebb7d78c96d0552c
|
7
|
+
data.tar.gz: '0792bbd48dd7fd388fbefe0131eeba5b9050778f215894ca3564cd987112f9de86b9b65aa3b8b030c9059faefd34bfec58660d514ab0f06ceaad41984085041d'
|
@@ -0,0 +1,23 @@
|
|
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
|
+
|
14
|
+
steps:
|
15
|
+
- uses: actions/checkout@v2
|
16
|
+
- name: Set up Ruby
|
17
|
+
uses: ruby/setup-ruby@v1
|
18
|
+
with:
|
19
|
+
ruby-version: 2.7.1
|
20
|
+
- name: Install dependencies
|
21
|
+
run: bundle install
|
22
|
+
- name: Run tests
|
23
|
+
run: bundle exec rake
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
ru_bittrex (0.2.0)
|
5
|
+
faraday (~> 1.0.1)
|
6
|
+
|
7
|
+
GEM
|
8
|
+
remote: https://rubygems.org/
|
9
|
+
specs:
|
10
|
+
faraday (1.0.1)
|
11
|
+
multipart-post (>= 1.2, < 3)
|
12
|
+
minitest (5.14.2)
|
13
|
+
mocha (1.11.2)
|
14
|
+
multipart-post (2.1.1)
|
15
|
+
rake (12.3.3)
|
16
|
+
|
17
|
+
PLATFORMS
|
18
|
+
ruby
|
19
|
+
|
20
|
+
DEPENDENCIES
|
21
|
+
minitest (~> 5.0)
|
22
|
+
mocha (~> 1.11.2)
|
23
|
+
rake (~> 12.0)
|
24
|
+
ru_bittrex!
|
25
|
+
|
26
|
+
BUNDLED WITH
|
27
|
+
2.1.4
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2020 david metta
|
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,134 @@
|
|
1
|
+
# RuBittrex
|
2
|
+
|
3
|
+
RuBittrex is a Ruby wrapper for the Bittrex API.
|
4
|
+
|
5
|
+
Currently RuBittrex only supports [Bittrex API V3](https://bittrex.github.io/api/v3) and is available for use with multiple clients (multiple Bittrex accounts).
|
6
|
+
|
7
|
+
## Table of Contents
|
8
|
+
- [Installation](#installation)
|
9
|
+
- [Usage](#usage)
|
10
|
+
- [Development](#development)
|
11
|
+
- [Testing](#testing)
|
12
|
+
- [Contributing](#contributing)
|
13
|
+
- [License](#license)
|
14
|
+
|
15
|
+
## Installation
|
16
|
+
|
17
|
+
Add this line to your application's Gemfile:
|
18
|
+
|
19
|
+
```ruby
|
20
|
+
gem 'ru_bittrex'
|
21
|
+
```
|
22
|
+
|
23
|
+
And then execute:
|
24
|
+
|
25
|
+
$ bundle install
|
26
|
+
|
27
|
+
Or install it yourself as:
|
28
|
+
|
29
|
+
$ gem install ru_bittrex
|
30
|
+
|
31
|
+
## Usage
|
32
|
+
|
33
|
+
#### Auth Configuration
|
34
|
+
In Order to use RuBittrex you must add authentication configuration after requiring the gem, or in an initializer.
|
35
|
+
```ruby
|
36
|
+
RuBittrex.configure do |config|
|
37
|
+
config.api_key = "MY_API_KEY"
|
38
|
+
config.secret = "MY_SECRET"
|
39
|
+
end
|
40
|
+
```
|
41
|
+
|
42
|
+
#### Basic Usage
|
43
|
+
Once configured you can use any of the classes by calling class methods directly:
|
44
|
+
```ruby
|
45
|
+
RuBittrex::Currency.get('btc')
|
46
|
+
```
|
47
|
+
The code above returns an instance of `RuBittrex::Currency`
|
48
|
+
|
49
|
+
This is a comprehensive list of the classes available and their methods:
|
50
|
+
```ruby
|
51
|
+
RuBittrex::Account.get
|
52
|
+
RuBittrex::Account.volume
|
53
|
+
|
54
|
+
RuBittrex::Address.all
|
55
|
+
RuBittrex::Address.get(currency) #==> RuBittrex::Address.get('btc')
|
56
|
+
|
57
|
+
RuBittrex::Balance.all
|
58
|
+
RuBittrex::Balance.get(currency) #==> RuBittrex::Balance.get('btc')
|
59
|
+
|
60
|
+
RuBittrex::Currency.all
|
61
|
+
RuBittrex::Currency.get(symbol) #==> RuBittrex::Currency.get('btc')
|
62
|
+
|
63
|
+
RuBittrex::Deposit.open(opts) #==> RuBittrex::Deposit.get(status: 'PENDING')
|
64
|
+
RuBittrex::Deposit.closed(opts) #==> RuBittrex::Deposit.get(status: 'COMPLETED')
|
65
|
+
RuBittrex::Deposit.get(id) #==> RuBittrex::Deposit.get('353fd-etwv-wrtvv')
|
66
|
+
|
67
|
+
RuBittrex::Market.all
|
68
|
+
RuBittrex::Market.get(symbol) #==> RuBittrex::Market.get('btc-eth')
|
69
|
+
|
70
|
+
RuBittrex::Summary.all
|
71
|
+
RuBittrex::Summary.get(market) #==> RuBittrex::Summary.get('btc-eth')
|
72
|
+
|
73
|
+
RuBittrex::Ticker.all
|
74
|
+
RuBittrex::Ticker.get(market) #==> RuBittrex::Ticker.get('btc-eth')
|
75
|
+
```
|
76
|
+
For the full list of options and params please refer to the [Bittrex API Documentation](https://bittrex.github.io/api/v3)
|
77
|
+
|
78
|
+
#### Client Usage
|
79
|
+
Alternatively you can instantiate the client directly, and then call the methods from there.
|
80
|
+
```ruby
|
81
|
+
client = RuBittrex::Client.new(api_key: 'MY_API_KEY', secret: 'MY_SECRET')
|
82
|
+
client.currency('btc')
|
83
|
+
```
|
84
|
+
The code above returns an instance of `RuBittrex::Currency`
|
85
|
+
|
86
|
+
This is especially useful when needing to perform actions from multiple clients (hence multiple accounts).
|
87
|
+
|
88
|
+
This is a comprehensive list of the methods available from the client:
|
89
|
+
```ruby
|
90
|
+
client.account
|
91
|
+
client.account_volume
|
92
|
+
|
93
|
+
client.addresses
|
94
|
+
client.address(currency) #===> client.address('btc')
|
95
|
+
|
96
|
+
client.balances
|
97
|
+
client.balance(currency) #===> client.balance('btc')
|
98
|
+
|
99
|
+
client.currencies
|
100
|
+
client.currency(symbol) #===> client.currency('btc')
|
101
|
+
|
102
|
+
client.open_deposits(opts) #===> client.open_deposit(status: 'PENDING')
|
103
|
+
client.closed_deposits(opts) #===> client.closed_deposit(status: 'COMPLETED')
|
104
|
+
client.deposit(id) #===> client.deposit('353fd-etwv-wrtvv')
|
105
|
+
|
106
|
+
client.markets
|
107
|
+
client.market(symbol) #===> client.market('btc-eth')
|
108
|
+
|
109
|
+
client.summaries
|
110
|
+
client.summary(market) #===> client.summary('btc-eth')
|
111
|
+
|
112
|
+
client.tickers
|
113
|
+
client.ticker(market) #===> client.ticker('btc-eth')
|
114
|
+
```
|
115
|
+
For the full list of options and params please refer to the [Bittrex API Documentation](https://bittrex.github.io/api/v3)
|
116
|
+
|
117
|
+
## Development
|
118
|
+
|
119
|
+
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.
|
120
|
+
|
121
|
+
When using the gem in development remember to create a `credentials.yml` file in the root of the library folder and insert a valid **api_key** and **secret** from Bittrex. You can find an example in `credentials.example.yml`.
|
122
|
+
|
123
|
+
|
124
|
+
## Testing
|
125
|
+
|
126
|
+
To test the gem simply run `rake test` from the root of the library folder.
|
127
|
+
|
128
|
+
## Contributing
|
129
|
+
|
130
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/davidmetta/ru_bittrex.
|
131
|
+
|
132
|
+
## License
|
133
|
+
|
134
|
+
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,13 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
require "bundler/setup"
|
3
|
+
require "ru_bittrex"
|
4
|
+
require 'yaml'
|
5
|
+
require "irb"
|
6
|
+
|
7
|
+
creds = YAML.load_file('credentials.yml')
|
8
|
+
RuBittrex.configure do |config|
|
9
|
+
config.api_key = creds["api_key"]
|
10
|
+
config.secret = creds["secret"]
|
11
|
+
end
|
12
|
+
|
13
|
+
IRB.start(__FILE__)
|
data/bin/setup
ADDED
data/lib/ru_bittrex.rb
ADDED
@@ -0,0 +1,47 @@
|
|
1
|
+
require "ru_bittrex/version"
|
2
|
+
|
3
|
+
module RuBittrex
|
4
|
+
class Error < StandardError; end
|
5
|
+
class AuthError < Error; end
|
6
|
+
|
7
|
+
autoload :Configuration, 'ru_bittrex/configuration'
|
8
|
+
autoload :Client, 'ru_bittrex/client'
|
9
|
+
autoload :ClientApi, 'ru_bittrex/client_api'
|
10
|
+
autoload :ClientHelper, 'ru_bittrex/client_helper'
|
11
|
+
autoload :Helpers, 'ru_bittrex/helpers'
|
12
|
+
autoload :Account, 'ru_bittrex/account'
|
13
|
+
autoload :Address, 'ru_bittrex/address'
|
14
|
+
autoload :Balance, 'ru_bittrex/balance'
|
15
|
+
autoload :Currency, 'ru_bittrex/currency'
|
16
|
+
autoload :Deposit, 'ru_bittrex/deposit'
|
17
|
+
autoload :Market, 'ru_bittrex/market'
|
18
|
+
autoload :Order, 'ru_bittrex/order'
|
19
|
+
autoload :Summary, 'ru_bittrex/summary'
|
20
|
+
autoload :Ticker, 'ru_bittrex/ticker'
|
21
|
+
|
22
|
+
class << self
|
23
|
+
def configuration
|
24
|
+
@configuration ||= Configuration.new
|
25
|
+
end
|
26
|
+
|
27
|
+
def reset_config
|
28
|
+
@configuration = Configuration.new
|
29
|
+
end
|
30
|
+
|
31
|
+
def configure
|
32
|
+
yield(configuration)
|
33
|
+
end
|
34
|
+
|
35
|
+
def client
|
36
|
+
@client ||= Client.new(configuration.auth)
|
37
|
+
end
|
38
|
+
|
39
|
+
def reset_client
|
40
|
+
@client = nil
|
41
|
+
end
|
42
|
+
|
43
|
+
def root
|
44
|
+
File.expand_path('../..', __FILE__)
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
module RuBittrex
|
2
|
+
class Account
|
3
|
+
extend ClientHelper
|
4
|
+
include Helpers
|
5
|
+
|
6
|
+
attr_reader :id, :updated_at, :volume_30_days, :raw
|
7
|
+
alias_method :volume, :volume_30_days
|
8
|
+
|
9
|
+
def initialize(attrs = {})
|
10
|
+
@id = attrs["accountId"]
|
11
|
+
@updated_at = extract_timestamp(attrs["updated"])
|
12
|
+
@volume_30_days = attrs["volume30days"]
|
13
|
+
@raw = attrs
|
14
|
+
end
|
15
|
+
|
16
|
+
def self.get(params = {})
|
17
|
+
new _get('account', params)
|
18
|
+
end
|
19
|
+
|
20
|
+
def self.volume(params = {})
|
21
|
+
new _get('account/volume', params)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
module RuBittrex
|
2
|
+
class Address
|
3
|
+
extend ClientHelper
|
4
|
+
|
5
|
+
attr_reader :status, :currency, :address, :raw
|
6
|
+
|
7
|
+
def initialize(attrs = {})
|
8
|
+
@status = attrs["status"]
|
9
|
+
@currency = attrs["currencySymbol"]
|
10
|
+
@address = attrs["cryptoAddress"]
|
11
|
+
@raw = attrs
|
12
|
+
end
|
13
|
+
|
14
|
+
def self.all(params = {})
|
15
|
+
collection _get('addresses', params)
|
16
|
+
end
|
17
|
+
|
18
|
+
def self.get(currency, params = {})
|
19
|
+
new _get("addresses/#{currency}", params)
|
20
|
+
end
|
21
|
+
|
22
|
+
# TODO: provision new address
|
23
|
+
# def self.create
|
24
|
+
# end
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
module RuBittrex
|
2
|
+
class Balance
|
3
|
+
extend ClientHelper
|
4
|
+
include Helpers
|
5
|
+
|
6
|
+
attr_reader :currency, :total, :available, :updated_at, :raw
|
7
|
+
|
8
|
+
def initialize(attrs = {})
|
9
|
+
@currency = attrs["currencySymbol"]
|
10
|
+
@total = attrs["total"]
|
11
|
+
@available = attrs["available"]
|
12
|
+
@updated_at = extract_timestamp(attrs["updatedAt"])
|
13
|
+
@raw = attrs
|
14
|
+
end
|
15
|
+
|
16
|
+
def self.all(params = {})
|
17
|
+
collection _get('balances', params)
|
18
|
+
end
|
19
|
+
|
20
|
+
# TODO: check that currency exists
|
21
|
+
def self.get(currency, params = {})
|
22
|
+
new _get("balances/#{currency}", params)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,69 @@
|
|
1
|
+
require 'faraday'
|
2
|
+
require 'digest'
|
3
|
+
require 'openssl'
|
4
|
+
require 'uri'
|
5
|
+
require 'json'
|
6
|
+
|
7
|
+
module RuBittrex
|
8
|
+
class Client
|
9
|
+
include ClientApi
|
10
|
+
|
11
|
+
API_URI = 'https://api.bittrex.com/v3'
|
12
|
+
|
13
|
+
attr_reader :secret, :api_key
|
14
|
+
|
15
|
+
def initialize(opts = {})
|
16
|
+
raise AuthError.new('You must provide API key and Secret') unless opts[:secret] && opts[:api_key]
|
17
|
+
|
18
|
+
@secret = opts[:secret]
|
19
|
+
@api_key = opts[:api_key]
|
20
|
+
end
|
21
|
+
|
22
|
+
def get(path, params = {})
|
23
|
+
uri = encode_uri(path, params)
|
24
|
+
timestamp = nonce
|
25
|
+
content_hash = digest
|
26
|
+
presign = timestamp.to_s + uri + 'GET' + content_hash
|
27
|
+
|
28
|
+
resp = Faraday.get(uri) do |req|
|
29
|
+
req.params = params
|
30
|
+
# req.params['limit'] = 100
|
31
|
+
req.headers['Api-Key'] = @api_key
|
32
|
+
req.headers['Api-Timestamp'] = timestamp.to_s
|
33
|
+
req.headers['Api-Content-Hash'] = content_hash
|
34
|
+
req.headers['Api-Signature'] = sign(presign)
|
35
|
+
req.headers['Content-Type'] = 'application/json'
|
36
|
+
# req.body = body.to_json
|
37
|
+
end
|
38
|
+
|
39
|
+
JSON.parse(resp.body)
|
40
|
+
end
|
41
|
+
|
42
|
+
private
|
43
|
+
|
44
|
+
def encode_uri(path, params)
|
45
|
+
uri = API_URI + '/' + path
|
46
|
+
uri = uri + '?' + URI.encode_www_form(params) if params.any?
|
47
|
+
uri
|
48
|
+
end
|
49
|
+
|
50
|
+
def nonce
|
51
|
+
(Time.now.to_f * 1000).to_i
|
52
|
+
end
|
53
|
+
|
54
|
+
def digest(body = nil)
|
55
|
+
string =
|
56
|
+
if body.is_a?(Hash)
|
57
|
+
body.to_json
|
58
|
+
elsif body.nil?
|
59
|
+
''
|
60
|
+
end
|
61
|
+
|
62
|
+
Digest::SHA512.hexdigest(string)
|
63
|
+
end
|
64
|
+
|
65
|
+
def sign(presign)
|
66
|
+
OpenSSL::HMAC.hexdigest('sha512', @secret, presign)
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|