bittrex-rb 2.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 7893a08c208aede437fadcc53439a7afb568e617
4
+ data.tar.gz: 3e96027aee93a6e6fb4c98c8ecb385b5a05700eb
5
+ SHA512:
6
+ metadata.gz: 43f9236474d50425ee1c354a0a18aff52bdb2389eb73d4541f2cb55485511cea836a7e3d9e335c819332c7d643fa88e475a4c43fafa647b5bc0d444772372010
7
+ data.tar.gz: a804bc2b301cd1b0da8ec15a5ba3fee10bdfb9bf6a434b77df5f4662d76c3c0396b9a744f5ae3683ef726b7dbf9f39e8af119c86b13ef972201672bf2c2be7f0
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in bittrex.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 Vizakenjack
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,55 @@
1
+ # Bittrex
2
+
3
+ This gem allows you to connect and send requests to Bittrex exchange.
4
+
5
+ ## Example
6
+
7
+ client = Bittrex::Api.new("API_KEY", "API_SECRET")
8
+
9
+ client.summaries
10
+
11
+ cclient.balances
12
+
13
+ client.balance('BTC')
14
+
15
+ client.ticker('USD-BTC')
16
+
17
+ client.orderbook('USD-BTC', 'buy', 50)
18
+
19
+ client.market_history('USD-BTC', 10)
20
+
21
+ client.buy('USD-BTC', 1, 7500)
22
+
23
+ client.sell('USD-BTC', 1, 10000)
24
+
25
+ client.cancel(order_id)
26
+
27
+ client.open_orders('USD-BTC')
28
+
29
+ client.order_history('USD-BTC', 5)
30
+
31
+
32
+ ## Installation
33
+
34
+ Add this line to your application's Gemfile:
35
+
36
+ gem 'bittrex-rb', git: 'git://github.com/vizakenjack/ruby-bittrex-api.git'
37
+
38
+ And then execute:
39
+
40
+ $ bundle
41
+
42
+ Or install it yourself as:
43
+
44
+ $ gem install bittrex-rb
45
+
46
+ Require it at the top of the script:
47
+
48
+ $ require 'bittrex-rb'
49
+
50
+ ## Contributing
51
+
52
+ 1. Fork it
53
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
54
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
55
+ 4. Push to the branch (`git push origin my-new-feature`)
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
data/bittrex.gemspec ADDED
@@ -0,0 +1,25 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'bittrex/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'bittrex-rb'
8
+ spec.version = Bittrex::VERSION
9
+ spec.authors = ['Vizakenjack']
10
+ spec.email = ['vizakenjack@gmail.com']
11
+ spec.description = %q{Ruby Bittrex.com client}
12
+ spec.summary = %q{Working with API}
13
+ spec.homepage = ''
14
+ spec.license = 'MIT'
15
+
16
+ spec.files = `git ls-files`.split($/)
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ['lib']
20
+
21
+ spec.add_development_dependency 'rake', '~> 12.3'
22
+
23
+ spec.add_runtime_dependency 'json', '~> 2.1'
24
+ spec.add_runtime_dependency 'httparty', '~> 0.16'
25
+ end
data/lib/api.rb ADDED
@@ -0,0 +1,63 @@
1
+ module Bittrex
2
+ class Api
3
+ attr_reader :request
4
+
5
+ def initialize(api_key, api_secret)
6
+ @request = Request.new(api_key, api_secret)
7
+ end
8
+
9
+ def ticker(market)
10
+ request.get "/public/getticker", "market=#{market}"
11
+ end
12
+
13
+ def summaries
14
+ request.get "/public/getmarketsummaries"
15
+ end
16
+
17
+ def orderbook(market, type, depth = 50)
18
+ request.get "/public/getorderbook", "market=#{market}&type=#{type}&depth=#{depth}"
19
+ end
20
+
21
+ def market_history(market, count = 10)
22
+ request.get "/public/getmarkethistory", "market=#{market}&count=#{count}"
23
+ end
24
+
25
+ def buy(market, quantity, rate = nil)
26
+ if rate
27
+ request.get "/market/buylimit", "market=#{market}&quantity=#{quantity}&rate=#{rate}"
28
+ else
29
+ request.get "/market/buymarket", "market=#{market}&quantity=#{quantity}"
30
+ end
31
+ end
32
+
33
+ def sell(market, quantity, rate = nil)
34
+ if rate
35
+ request.get "/market/selllimit", "market=#{market}&quantity=#{quantity}&rate=#{rate}"
36
+ else
37
+ request.get "/market/sellmarket", "market=#{market}&quantity=#{quantity}"
38
+ end
39
+ end
40
+
41
+ def cancel(order_id)
42
+ request.get "/market/cancel", "uuid=#{order_id}"
43
+ end
44
+
45
+ def open_orders(market = '')
46
+ request.get "/market/getopenorders", "market=#{market}"
47
+ end
48
+
49
+ def balances
50
+ request.get "/account/getbalances"
51
+ end
52
+
53
+ def balance(currency)
54
+ request.get "/account/getbalance", "currency=#{currency}"
55
+ end
56
+
57
+ def order_history(market = nil, count = 5)
58
+ params = market ? "market=#{market}&count=#{count}" : "count=#{count}"
59
+ request.get "/account/getorderhistory", params
60
+ end
61
+ end
62
+
63
+ end
@@ -0,0 +1,3 @@
1
+ module Bittrex
2
+ VERSION = "2.0.0"
3
+ end
data/lib/bittrex.rb ADDED
@@ -0,0 +1,3 @@
1
+ require 'httparty'
2
+ require 'request'
3
+ require 'api'
data/lib/request.rb ADDED
@@ -0,0 +1,40 @@
1
+ module Bittrex
2
+ class Request
3
+ BASE_URL = 'https://bittrex.com/api/v1.1'
4
+ attr_reader :api_key, :api_secret
5
+
6
+ def initialize(api_key, api_secret)
7
+ @api_key = api_key
8
+ @api_secret = api_secret
9
+ end
10
+
11
+ def get(path, params = '')
12
+ begin
13
+ nonce = Time.now.to_i
14
+ final_url = "#{BASE_URL}#{path}?apikey=#{api_key}&nonce=#{nonce}&"+params
15
+ hmac_sign = generate_sign(final_url)
16
+
17
+ response = HTTParty.get(final_url, headers: { apisign: hmac_sign })
18
+ handle_response response.body
19
+ rescue Exception => e
20
+ nil
21
+ end
22
+ end
23
+
24
+ private
25
+
26
+ def generate_sign(url)
27
+ OpenSSL::HMAC.hexdigest('sha512', api_secret, url)
28
+ end
29
+
30
+ def handle_response(response)
31
+ json = JSON.parse(response)
32
+ if json['success']
33
+ json['result']
34
+ else
35
+ puts "Request failed: #{json}"
36
+ json['message']
37
+ end
38
+ end
39
+ end
40
+ end
metadata ADDED
@@ -0,0 +1,96 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: bittrex-rb
3
+ version: !ruby/object:Gem::Version
4
+ version: 2.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Vizakenjack
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2018-06-07 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rake
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '12.3'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '12.3'
27
+ - !ruby/object:Gem::Dependency
28
+ name: json
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '2.1'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '2.1'
41
+ - !ruby/object:Gem::Dependency
42
+ name: httparty
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '0.16'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '0.16'
55
+ description: Ruby Bittrex.com client
56
+ email:
57
+ - vizakenjack@gmail.com
58
+ executables: []
59
+ extensions: []
60
+ extra_rdoc_files: []
61
+ files:
62
+ - ".gitignore"
63
+ - Gemfile
64
+ - LICENSE.txt
65
+ - README.md
66
+ - Rakefile
67
+ - bittrex.gemspec
68
+ - lib/api.rb
69
+ - lib/bittrex.rb
70
+ - lib/bittrex/version.rb
71
+ - lib/request.rb
72
+ homepage: ''
73
+ licenses:
74
+ - MIT
75
+ metadata: {}
76
+ post_install_message:
77
+ rdoc_options: []
78
+ require_paths:
79
+ - lib
80
+ required_ruby_version: !ruby/object:Gem::Requirement
81
+ requirements:
82
+ - - ">="
83
+ - !ruby/object:Gem::Version
84
+ version: '0'
85
+ required_rubygems_version: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ requirements: []
91
+ rubyforge_project:
92
+ rubygems_version: 2.5.2
93
+ signing_key:
94
+ specification_version: 4
95
+ summary: Working with API
96
+ test_files: []