bittrex_ruby 1.0.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/.rubocop.yml +1 -0
- data/.rubocop_todo.yml +33 -0
- data/.travis.yml +5 -0
- data/CODE_OF_CONDUCT.md +74 -0
- data/Gemfile +6 -0
- data/Gemfile.lock +59 -0
- data/README.md +90 -0
- data/Rakefile +6 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/bittrex_ruby.gemspec +36 -0
- data/lib/bittrex_ruby/version.rb +3 -0
- data/lib/bittrex_ruby.rb +144 -0
- data/lib/deep_symbolize.rb +68 -0
- metadata +158 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 37a2d6bd9d534a7d57e9e31608f623c2056df0648555c3aeb7dae1450612e92c
|
4
|
+
data.tar.gz: 6ef6d2974b9205c063ba5185501014f5a89cf0643a27c2c8cc9a157fc8870197
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: d67a01526eb0d81edfc006e50a51fcb923e66523dcf9bd6482ec80ced644cdf630ecabb461691478e7a0370ce9d6f095f4150a5eeb939cf4a1a171da37968760
|
7
|
+
data.tar.gz: a0b551cbc889e2f5c45df6185afd80f90c3437a9cba1cb9f74c8e05d58dfcd6bb52f87aba87bd51a3f230899c5355cb778205b93ef3335ff9995d7cd860d1f7c
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.rubocop.yml
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
inherit_from: .rubocop_todo.yml
|
data/.rubocop_todo.yml
ADDED
@@ -0,0 +1,33 @@
|
|
1
|
+
# This configuration was generated by
|
2
|
+
# `rubocop --auto-gen-config`
|
3
|
+
# on 2018-05-26 17:59:51 +0200 using RuboCop version 0.55.0.
|
4
|
+
# The point is for the user to remove these configuration records
|
5
|
+
# one by one as the offenses are removed from the code base.
|
6
|
+
# Note that changes in the inspected code, or installation of new
|
7
|
+
# versions of RuboCop, may require this file to be generated again.
|
8
|
+
|
9
|
+
# Offense count: 4
|
10
|
+
Lint/ImplicitStringConcatenation:
|
11
|
+
Exclude:
|
12
|
+
- 'bittrex_ruby.gemspec'
|
13
|
+
|
14
|
+
# Offense count: 1
|
15
|
+
Metrics/AbcSize:
|
16
|
+
Max: 17
|
17
|
+
|
18
|
+
# Offense count: 4
|
19
|
+
# Configuration parameters: CountComments, ExcludedMethods.
|
20
|
+
Metrics/BlockLength:
|
21
|
+
Max: 119
|
22
|
+
|
23
|
+
# Offense count: 1
|
24
|
+
# Cop supports --auto-correct.
|
25
|
+
Style/IfUnlessModifier:
|
26
|
+
Exclude:
|
27
|
+
- 'lib/deep_symbolize.rb'
|
28
|
+
|
29
|
+
# Offense count: 11
|
30
|
+
# Configuration parameters: AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, IgnoredPatterns.
|
31
|
+
# URISchemes: http, https
|
32
|
+
Metrics/LineLength:
|
33
|
+
Max: 105
|
data/.travis.yml
ADDED
data/CODE_OF_CONDUCT.md
ADDED
@@ -0,0 +1,74 @@
|
|
1
|
+
# Contributor Covenant Code of Conduct
|
2
|
+
|
3
|
+
## Our Pledge
|
4
|
+
|
5
|
+
In the interest of fostering an open and welcoming environment, we as
|
6
|
+
contributors and maintainers pledge to making participation in our project and
|
7
|
+
our community a harassment-free experience for everyone, regardless of age, body
|
8
|
+
size, disability, ethnicity, gender identity and expression, level of experience,
|
9
|
+
nationality, personal appearance, race, religion, or sexual identity and
|
10
|
+
orientation.
|
11
|
+
|
12
|
+
## Our Standards
|
13
|
+
|
14
|
+
Examples of behavior that contributes to creating a positive environment
|
15
|
+
include:
|
16
|
+
|
17
|
+
* Using welcoming and inclusive language
|
18
|
+
* Being respectful of differing viewpoints and experiences
|
19
|
+
* Gracefully accepting constructive criticism
|
20
|
+
* Focusing on what is best for the community
|
21
|
+
* Showing empathy towards other community members
|
22
|
+
|
23
|
+
Examples of unacceptable behavior by participants include:
|
24
|
+
|
25
|
+
* The use of sexualized language or imagery and unwelcome sexual attention or
|
26
|
+
advances
|
27
|
+
* Trolling, insulting/derogatory comments, and personal or political attacks
|
28
|
+
* Public or private harassment
|
29
|
+
* Publishing others' private information, such as a physical or electronic
|
30
|
+
address, without explicit permission
|
31
|
+
* Other conduct which could reasonably be considered inappropriate in a
|
32
|
+
professional setting
|
33
|
+
|
34
|
+
## Our Responsibilities
|
35
|
+
|
36
|
+
Project maintainers are responsible for clarifying the standards of acceptable
|
37
|
+
behavior and are expected to take appropriate and fair corrective action in
|
38
|
+
response to any instances of unacceptable behavior.
|
39
|
+
|
40
|
+
Project maintainers have the right and responsibility to remove, edit, or
|
41
|
+
reject comments, commits, code, wiki edits, issues, and other contributions
|
42
|
+
that are not aligned to this Code of Conduct, or to ban temporarily or
|
43
|
+
permanently any contributor for other behaviors that they deem inappropriate,
|
44
|
+
threatening, offensive, or harmful.
|
45
|
+
|
46
|
+
## Scope
|
47
|
+
|
48
|
+
This Code of Conduct applies both within project spaces and in public spaces
|
49
|
+
when an individual is representing the project or its community. Examples of
|
50
|
+
representing a project or community include using an official project e-mail
|
51
|
+
address, posting via an official social media account, or acting as an appointed
|
52
|
+
representative at an online or offline event. Representation of a project may be
|
53
|
+
further defined and clarified by project maintainers.
|
54
|
+
|
55
|
+
## Enforcement
|
56
|
+
|
57
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
58
|
+
reported by contacting the project team at maxime@cyberwatch.fr. All
|
59
|
+
complaints will be reviewed and investigated and will result in a response that
|
60
|
+
is deemed necessary and appropriate to the circumstances. The project team is
|
61
|
+
obligated to maintain confidentiality with regard to the reporter of an incident.
|
62
|
+
Further details of specific enforcement policies may be posted separately.
|
63
|
+
|
64
|
+
Project maintainers who do not follow or enforce the Code of Conduct in good
|
65
|
+
faith may face temporary or permanent repercussions as determined by other
|
66
|
+
members of the project's leadership.
|
67
|
+
|
68
|
+
## Attribution
|
69
|
+
|
70
|
+
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
|
71
|
+
available at [http://contributor-covenant.org/version/1/4][version]
|
72
|
+
|
73
|
+
[homepage]: http://contributor-covenant.org
|
74
|
+
[version]: http://contributor-covenant.org/version/1/4/
|
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,59 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
bittrex_ruby (1.0.0)
|
5
|
+
addressable
|
6
|
+
json
|
7
|
+
openssl
|
8
|
+
rest-client
|
9
|
+
|
10
|
+
GEM
|
11
|
+
remote: https://rubygems.org/
|
12
|
+
specs:
|
13
|
+
addressable (2.5.2)
|
14
|
+
public_suffix (>= 2.0.2, < 4.0)
|
15
|
+
diff-lcs (1.3)
|
16
|
+
domain_name (0.5.20180417)
|
17
|
+
unf (>= 0.0.5, < 1.0.0)
|
18
|
+
http-cookie (1.0.3)
|
19
|
+
domain_name (~> 0.5)
|
20
|
+
json (2.1.0)
|
21
|
+
mime-types (3.1)
|
22
|
+
mime-types-data (~> 3.2015)
|
23
|
+
mime-types-data (3.2016.0521)
|
24
|
+
netrc (0.11.0)
|
25
|
+
openssl (2.1.0)
|
26
|
+
public_suffix (3.0.2)
|
27
|
+
rake (10.5.0)
|
28
|
+
rest-client (2.0.2)
|
29
|
+
http-cookie (>= 1.0.2, < 2.0)
|
30
|
+
mime-types (>= 1.16, < 4.0)
|
31
|
+
netrc (~> 0.8)
|
32
|
+
rspec (3.7.0)
|
33
|
+
rspec-core (~> 3.7.0)
|
34
|
+
rspec-expectations (~> 3.7.0)
|
35
|
+
rspec-mocks (~> 3.7.0)
|
36
|
+
rspec-core (3.7.1)
|
37
|
+
rspec-support (~> 3.7.0)
|
38
|
+
rspec-expectations (3.7.0)
|
39
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
40
|
+
rspec-support (~> 3.7.0)
|
41
|
+
rspec-mocks (3.7.0)
|
42
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
43
|
+
rspec-support (~> 3.7.0)
|
44
|
+
rspec-support (3.7.1)
|
45
|
+
unf (0.1.4)
|
46
|
+
unf_ext
|
47
|
+
unf_ext (0.0.7.5)
|
48
|
+
|
49
|
+
PLATFORMS
|
50
|
+
ruby
|
51
|
+
|
52
|
+
DEPENDENCIES
|
53
|
+
bittrex_ruby!
|
54
|
+
bundler (~> 1.16)
|
55
|
+
rake (~> 10.0)
|
56
|
+
rspec (~> 3.0)
|
57
|
+
|
58
|
+
BUNDLED WITH
|
59
|
+
1.16.1
|
data/README.md
ADDED
@@ -0,0 +1,90 @@
|
|
1
|
+
# BittrexRuby
|
2
|
+
|
3
|
+
This gem provides a wrapper for Bittrex.com Public/Account/Market APIs.
|
4
|
+
|
5
|
+
It can for instance place buy/sell orders for you.
|
6
|
+
|
7
|
+
[![Build Status](https://travis-ci.org/tarraschk/bittrex_ruby.svg?branch=master)](https://travis-ci.org/tarraschk/bittrex_ruby)
|
8
|
+
|
9
|
+
## Installation
|
10
|
+
|
11
|
+
Add this line to your application's Gemfile:
|
12
|
+
|
13
|
+
```ruby
|
14
|
+
gem 'bittrex_ruby'
|
15
|
+
```
|
16
|
+
|
17
|
+
And then execute:
|
18
|
+
|
19
|
+
$ bundle
|
20
|
+
|
21
|
+
Or install it yourself as:
|
22
|
+
|
23
|
+
$ gem install bittrex_ruby
|
24
|
+
|
25
|
+
## Usage
|
26
|
+
|
27
|
+
|
28
|
+
### Load the gem
|
29
|
+
```
|
30
|
+
require 'bittrex_ruby'
|
31
|
+
```
|
32
|
+
|
33
|
+
### Setup your Bittrex API keys
|
34
|
+
|
35
|
+
```
|
36
|
+
BittrexRuby.setup do |config|
|
37
|
+
config.key = 'BITTREX_KEY'
|
38
|
+
config.secret = 'BITTREX_SECRET'
|
39
|
+
end
|
40
|
+
```
|
41
|
+
|
42
|
+
### Use the gem
|
43
|
+
|
44
|
+
This gem methods are named after the official Bittrex v1.1 API Documentation: https://support.bittrex.com/hc/en-us/articles/115003723911-Developer-s-Guide-API
|
45
|
+
|
46
|
+
```
|
47
|
+
# Public API
|
48
|
+
BittrexRuby.getmarkets
|
49
|
+
BittrexRuby.getcurrencies
|
50
|
+
BittrexRuby.getticker('btc-eth')
|
51
|
+
BittrexRuby.getmarketsummaries
|
52
|
+
BittrexRuby.getmarketsummary('btc-eth')
|
53
|
+
BittrexRuby.getorderbook('btc-eth', 'buy')
|
54
|
+
BittrexRuby.getmarkethistory('btc-eth')
|
55
|
+
|
56
|
+
# Market API
|
57
|
+
BittrexRuby.buylimit('btc-eth', 1.0, 1.0)
|
58
|
+
BittrexRuby.selllimit('btc-eth', 1.0, 1.0)
|
59
|
+
BittrexRuby.cancel('09aa5bb6-8232-41aa-9b78-a5a1093e0211')
|
60
|
+
BittrexRuby.getopenorders
|
61
|
+
BittrexRuby.getopenorders('btc-eth')
|
62
|
+
|
63
|
+
# Account API
|
64
|
+
BittrexRuby.getbalances
|
65
|
+
BittrexRuby.getbalance('BTC')
|
66
|
+
BittrexRuby.getdepositaddress('BTC')
|
67
|
+
BittrexRuby.withdraw('EAC', 20.40, 'EAC_ADDRESS')
|
68
|
+
BittrexRuby.withdraw('EAC', 20.40, 'EAC_ADDRESS', 'PAYMENTID')
|
69
|
+
BittrexRuby.getorder('0cb4c4e4-bdc7-4e13-8c13-430e587d2cc1')
|
70
|
+
BittrexRuby.getorderhistory
|
71
|
+
BittrexRuby.getorderhistory('btc-eth')
|
72
|
+
BittrexRuby.getwithdrawalhistory
|
73
|
+
BittrexRuby.getwithdrawalhistory('btc')
|
74
|
+
BittrexRuby.getdeposithistory
|
75
|
+
BittrexRuby.getdeposithistory('btc')
|
76
|
+
```
|
77
|
+
|
78
|
+
## Development
|
79
|
+
|
80
|
+
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.
|
81
|
+
|
82
|
+
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).
|
83
|
+
|
84
|
+
## Contributing
|
85
|
+
|
86
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/tarraschk/bittrex_ruby. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
|
87
|
+
|
88
|
+
## Code of Conduct
|
89
|
+
|
90
|
+
Everyone interacting in the BittrexRuby project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/tarraschk/bittrex_ruby/blob/master/CODE_OF_CONDUCT.md).
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'bundler/setup'
|
4
|
+
require 'bittrex_ruby'
|
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
@@ -0,0 +1,36 @@
|
|
1
|
+
|
2
|
+
lib = File.expand_path('lib', __dir__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'bittrex_ruby/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = 'bittrex_ruby'
|
8
|
+
spec.version = BittrexRuby::VERSION
|
9
|
+
spec.authors = ['Maxime Alay-Eddine']
|
10
|
+
spec.email = ['maxime.alayeddine@gmail.com']
|
11
|
+
|
12
|
+
spec.summary = ''"
|
13
|
+
Provides a wrapper for Bittrex.com Public/Account/Market APIs.
|
14
|
+
"''
|
15
|
+
spec.description = ''"
|
16
|
+
Provides a wrapper for Bittrex.com Public/Account/Market APIs.
|
17
|
+
Supports placing buy/sell orders.
|
18
|
+
"''
|
19
|
+
spec.homepage = 'https://github.com/tarraschk/bittrex_ruby'
|
20
|
+
|
21
|
+
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
22
|
+
f.match(%r{^(test|spec|features)/})
|
23
|
+
end
|
24
|
+
spec.bindir = 'exe'
|
25
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
26
|
+
spec.require_paths = ['lib']
|
27
|
+
|
28
|
+
spec.add_dependency 'addressable'
|
29
|
+
spec.add_dependency 'json'
|
30
|
+
spec.add_dependency 'openssl'
|
31
|
+
spec.add_dependency 'rest-client'
|
32
|
+
|
33
|
+
spec.add_development_dependency 'bundler', '~> 1.16'
|
34
|
+
spec.add_development_dependency 'rake', '~> 10.0'
|
35
|
+
spec.add_development_dependency 'rspec', '~> 3.0'
|
36
|
+
end
|
data/lib/bittrex_ruby.rb
ADDED
@@ -0,0 +1,144 @@
|
|
1
|
+
require 'bittrex_ruby/version'
|
2
|
+
require 'rest-client'
|
3
|
+
require 'openssl'
|
4
|
+
require 'addressable/uri'
|
5
|
+
require 'deep_symbolize'
|
6
|
+
require 'json'
|
7
|
+
|
8
|
+
# Gem to use Bittrex API
|
9
|
+
module BittrexRuby
|
10
|
+
class << self
|
11
|
+
attr_accessor :configuration
|
12
|
+
end
|
13
|
+
|
14
|
+
def self.setup
|
15
|
+
@configuration ||= Configuration.new
|
16
|
+
yield(configuration)
|
17
|
+
end
|
18
|
+
|
19
|
+
# Handles the Bittrex API keys
|
20
|
+
class Configuration
|
21
|
+
attr_accessor :key, :secret
|
22
|
+
|
23
|
+
def initialize
|
24
|
+
@key = ''
|
25
|
+
@secret = ''
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
# Public API
|
30
|
+
def self.getmarkets
|
31
|
+
get 'public', 'getmarkets'
|
32
|
+
end
|
33
|
+
|
34
|
+
def self.getcurrencies
|
35
|
+
get 'public', 'getcurrencies'
|
36
|
+
end
|
37
|
+
|
38
|
+
def self.getticker(market)
|
39
|
+
get 'public', 'getticker', market: market
|
40
|
+
end
|
41
|
+
|
42
|
+
def self.getmarketsummaries
|
43
|
+
get 'public', 'getmarketsummaries'
|
44
|
+
end
|
45
|
+
|
46
|
+
def self.getmarketsummary(market)
|
47
|
+
get 'public', 'getmarketsummary', market: market
|
48
|
+
end
|
49
|
+
|
50
|
+
def self.getorderbook(market, type)
|
51
|
+
get 'public', 'getorderbook', market: market, type: type
|
52
|
+
end
|
53
|
+
|
54
|
+
def self.getmarkethistory(market)
|
55
|
+
get 'public', 'getmarkethistory', market: market
|
56
|
+
end
|
57
|
+
|
58
|
+
# Market API
|
59
|
+
def self.buylimit(market, quantity, rate)
|
60
|
+
get_signed 'market', 'buylimit', market: market,
|
61
|
+
quantity: quantity, rate: rate
|
62
|
+
end
|
63
|
+
|
64
|
+
def self.selllimit(market, quantity, rate)
|
65
|
+
get_signed 'market', 'selllimit', market: market,
|
66
|
+
quantity: quantity, rate: rate
|
67
|
+
end
|
68
|
+
|
69
|
+
def self.cancel(uuid)
|
70
|
+
get_signed 'market', 'cancel', uuid: uuid
|
71
|
+
end
|
72
|
+
|
73
|
+
def self.getopenorders(market = nil)
|
74
|
+
get_signed 'market', 'getopenorders', market: market
|
75
|
+
end
|
76
|
+
|
77
|
+
# Account API
|
78
|
+
def self.getbalances
|
79
|
+
get_signed 'account', 'getbalances'
|
80
|
+
end
|
81
|
+
|
82
|
+
def self.getbalance(currency)
|
83
|
+
get_signed 'account', 'getbalance', currency: currency
|
84
|
+
end
|
85
|
+
|
86
|
+
def self.getdepositaddress(currency)
|
87
|
+
get_signed 'account', 'getdepositaddress', currency: currency
|
88
|
+
end
|
89
|
+
|
90
|
+
def self.withdraw(currency, quantity, address, paymentid = nil)
|
91
|
+
get_signed 'account', 'withdraw',
|
92
|
+
currency: currency, quantity: quantity,
|
93
|
+
address: address, paymentid: paymentid
|
94
|
+
end
|
95
|
+
|
96
|
+
def self.getorder(uuid)
|
97
|
+
get_signed 'account', 'getorder', uuid: uuid
|
98
|
+
end
|
99
|
+
|
100
|
+
def self.getorderhistory(market = nil)
|
101
|
+
get_signed 'account', 'getorderhistory', market: market
|
102
|
+
end
|
103
|
+
|
104
|
+
def self.getwithdrawalhistory(currency = nil)
|
105
|
+
get_signed 'account', 'getwithdrawalhistory', currency: currency
|
106
|
+
end
|
107
|
+
|
108
|
+
def self.getdeposithistory(currency = nil)
|
109
|
+
get_signed 'account', 'getdeposithistory', currency: currency
|
110
|
+
end
|
111
|
+
|
112
|
+
class << self
|
113
|
+
def resource
|
114
|
+
RestClient::Resource.new('https://bittrex.com/api/v1.1/')
|
115
|
+
end
|
116
|
+
|
117
|
+
def get(api_group, action, params = {})
|
118
|
+
res = resource[api_group + '/' + action].get params: params.compact
|
119
|
+
res_hash res
|
120
|
+
end
|
121
|
+
|
122
|
+
def get_signed(api_group, action, params = {})
|
123
|
+
params[:nonce] = Time.now.to_i
|
124
|
+
params[:apikey] = configuration.key
|
125
|
+
|
126
|
+
# Build Query parameters string
|
127
|
+
params_query = params.compact.map { |k, v| "#{k}=#{v}" }.join('&')
|
128
|
+
uri = resource[api_group + '/' + action + '?' + params_query]
|
129
|
+
|
130
|
+
res = uri.get apisign: create_sign(uri)
|
131
|
+
res_hash res
|
132
|
+
end
|
133
|
+
|
134
|
+
def create_sign(uri)
|
135
|
+
OpenSSL::HMAC.hexdigest('sha512', configuration.secret, uri.url)
|
136
|
+
end
|
137
|
+
|
138
|
+
def res_hash(res)
|
139
|
+
data = JSON.parse(res.body)
|
140
|
+
data.extend DeepSymbolizable
|
141
|
+
{ data: data.deep_symbolize, res: res }
|
142
|
+
end
|
143
|
+
end
|
144
|
+
end
|
@@ -0,0 +1,68 @@
|
|
1
|
+
# Symbolizes all of hash's keys and subkeys.
|
2
|
+
# Also allows for custom pre-processing of keys (e.g. downcasing, etc)
|
3
|
+
# if the block is given:
|
4
|
+
#
|
5
|
+
# somehash.deep_symbolize { |key| key.downcase }
|
6
|
+
#
|
7
|
+
# Usage: either include it into global Hash class to make it available to
|
8
|
+
# to all hashes, or extend only your own hash objects with this
|
9
|
+
# module.
|
10
|
+
# E.g.:
|
11
|
+
# 1) class Hash; include DeepSymbolizable; end
|
12
|
+
# 2) myhash.extend DeepSymbolizable
|
13
|
+
#
|
14
|
+
# Source: https://github.com/ntamvl/poloniex_ruby/blob/master/lib/deep_symbolize.rb
|
15
|
+
|
16
|
+
# Used to symbolize hashes
|
17
|
+
module DeepSymbolizable
|
18
|
+
def deep_symbolize(&block)
|
19
|
+
method = self.class.to_s.downcase.to_sym
|
20
|
+
syms = DeepSymbolizable::Symbolizers
|
21
|
+
syms.respond_to?(method) ? syms.send(method, self, &block) : self
|
22
|
+
end
|
23
|
+
|
24
|
+
# Used to symbolize hashes
|
25
|
+
module Symbolizers
|
26
|
+
module_function
|
27
|
+
|
28
|
+
# the primary method - symbolizes keys of the given hash,
|
29
|
+
# preprocessing them with a block if one was given, and recursively
|
30
|
+
# going into all nested enumerables
|
31
|
+
def hash(hash, &block)
|
32
|
+
hash.each_with_object({}) do |(key, value), result|
|
33
|
+
# Recursively deep-symbolize subhashes
|
34
|
+
value = _recurse_(value, &block)
|
35
|
+
|
36
|
+
# Pre-process the key with a block if it was given
|
37
|
+
key = yield key if block_given?
|
38
|
+
# Symbolize the key string if it responds to to_sym
|
39
|
+
sym_key = begin
|
40
|
+
key.to_sym
|
41
|
+
rescue StandardError
|
42
|
+
key
|
43
|
+
end
|
44
|
+
|
45
|
+
# write it back into the result and return the updated hash
|
46
|
+
result[sym_key] = value
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
# walking over arrays and symbolizing all nested elements
|
51
|
+
def array(ary, &block)
|
52
|
+
ary.map { |v| _recurse_(v, &block) }
|
53
|
+
end
|
54
|
+
|
55
|
+
# handling recursion - any Enumerable elements (except String)
|
56
|
+
# is being extended with the module, and then symbolized
|
57
|
+
def _recurse_(value, &block)
|
58
|
+
if value.is_a?(Enumerable) && !value.is_a?(String)
|
59
|
+
# support for a use case without extended core Hash
|
60
|
+
unless value.class.include?(DeepSymbolizable)
|
61
|
+
value.extend DeepSymbolizable
|
62
|
+
end
|
63
|
+
value = value.deep_symbolize(&block)
|
64
|
+
end
|
65
|
+
value
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
metadata
ADDED
@@ -0,0 +1,158 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: bittrex_ruby
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Maxime Alay-Eddine
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2018-05-26 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: addressable
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: json
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '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: bundler
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '1.16'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '1.16'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: rake
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - "~>"
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '10.0'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - "~>"
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '10.0'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: rspec
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - "~>"
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '3.0'
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - "~>"
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '3.0'
|
111
|
+
description: "\n Provides a wrapper for Bittrex.com Public/Account/Market APIs.\n
|
112
|
+
\ Supports placing buy/sell orders.\n "
|
113
|
+
email:
|
114
|
+
- maxime.alayeddine@gmail.com
|
115
|
+
executables: []
|
116
|
+
extensions: []
|
117
|
+
extra_rdoc_files: []
|
118
|
+
files:
|
119
|
+
- ".gitignore"
|
120
|
+
- ".rspec"
|
121
|
+
- ".rubocop.yml"
|
122
|
+
- ".rubocop_todo.yml"
|
123
|
+
- ".travis.yml"
|
124
|
+
- CODE_OF_CONDUCT.md
|
125
|
+
- Gemfile
|
126
|
+
- Gemfile.lock
|
127
|
+
- README.md
|
128
|
+
- Rakefile
|
129
|
+
- bin/console
|
130
|
+
- bin/setup
|
131
|
+
- bittrex_ruby.gemspec
|
132
|
+
- lib/bittrex_ruby.rb
|
133
|
+
- lib/bittrex_ruby/version.rb
|
134
|
+
- lib/deep_symbolize.rb
|
135
|
+
homepage: https://github.com/tarraschk/bittrex_ruby
|
136
|
+
licenses: []
|
137
|
+
metadata: {}
|
138
|
+
post_install_message:
|
139
|
+
rdoc_options: []
|
140
|
+
require_paths:
|
141
|
+
- lib
|
142
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
143
|
+
requirements:
|
144
|
+
- - ">="
|
145
|
+
- !ruby/object:Gem::Version
|
146
|
+
version: '0'
|
147
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
148
|
+
requirements:
|
149
|
+
- - ">="
|
150
|
+
- !ruby/object:Gem::Version
|
151
|
+
version: '0'
|
152
|
+
requirements: []
|
153
|
+
rubyforge_project:
|
154
|
+
rubygems_version: 2.7.6
|
155
|
+
signing_key:
|
156
|
+
specification_version: 4
|
157
|
+
summary: Provides a wrapper for Bittrex.com Public/Account/Market APIs.
|
158
|
+
test_files: []
|