queru_btce 1.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: ba163198f6876c127ab7fde52f23005830b02ad2
4
+ data.tar.gz: 43e5ffe9de29b6d8dae6bb2ee46aa57410242e6c
5
+ SHA512:
6
+ metadata.gz: ff30e470dfcfa3cb007ee876d715e59e5aaefd992f814e23cf8ca9d2c3f6e2c7322aff1880c579b4a48f829df95f0d74aca8f28126d9f50cd093190951737710
7
+ data.tar.gz: 73f7b7c2b78671a53ef63b7dc61f3104c7df707d75393154279cc4c74ece22a38c48f70e8e0a260ea81f26e920d737d047948c101f71808390300bdefa4149d8
data/.gitignore ADDED
@@ -0,0 +1,21 @@
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
18
+ .DS_Store
19
+ work
20
+ qtest.rb
21
+
data/.rubocop.yml ADDED
@@ -0,0 +1,46 @@
1
+ LineLength:
2
+ Max: 120
3
+
4
+ Style/AccessorMethodName:
5
+ Enabled: false
6
+ Style/AndOr:
7
+ Enabled: false
8
+ Style/ColonMethodCall:
9
+ Enabled: false
10
+ Style/CommandLiteral:
11
+ Enabled: false
12
+ Style/Documentation:
13
+ Enabled: false
14
+ Style/FileName:
15
+ Enabled: false
16
+ Style/FrozenStringLiteralComment:
17
+ Enabled: false
18
+ Style/Not:
19
+ Enabled: false
20
+ Style/RedundantBegin:
21
+ Enabled: false
22
+ Metrics/ClassLength:
23
+ Max: 300
24
+ Metrics/AbcSize:
25
+ Max: 150
26
+ Metrics/CyclomaticComplexity:
27
+ Max: 50
28
+ Metrics/MethodLength:
29
+ Max: 100
30
+ Metrics/PerceivedComplexity:
31
+ Max: 100
32
+ Metrics/ParameterLists:
33
+ Max: 15
34
+ Metrics/ModuleLength:
35
+ Max: 200
36
+ Metrics/BlockLength:
37
+ Max: 100
38
+
39
+ Lint/ParenthesesAsGroupedExpression:
40
+ Enabled: false
41
+ Lint/UselessComparison:
42
+ Exclude:
43
+ - test/test_queru-btce.rb
44
+
45
+ AllCops:
46
+ TargetRubyVersion: 2.3
data/.travis.yml ADDED
@@ -0,0 +1,6 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.3.0
4
+ - 2.3.1
5
+ # uncomment this line if your project needs to run something other than `rake`:
6
+ # script: bundle exec rspec spec
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in QueruBtce.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,23 @@
1
+ Original Gem: Copyright (c) 2014 Brock Harris
2
+ This fork by Queru AKA Jorge Fuertes
3
+
4
+ MIT License
5
+
6
+ Permission is hereby granted, free of charge, to any person obtaining
7
+ a copy of this software and associated documentation files (the
8
+ "Software"), to deal in the Software without restriction, including
9
+ without limitation the rights to use, copy, modify, merge, publish,
10
+ distribute, sublicense, and/or sell copies of the Software, and to
11
+ permit persons to whom the Software is furnished to do so, subject to
12
+ the following conditions:
13
+
14
+ The above copyright notice and this permission notice shall be
15
+ included in all copies or substantial portions of the Software.
16
+
17
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
18
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
19
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
20
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
21
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
22
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
23
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,64 @@
1
+ # queru-btce
2
+
3
+ KISS BTC-E API Access from Ruby.
4
+
5
+ ### Pros:
6
+
7
+ - No config file and no framework dependency.
8
+ - No weird abstractions, you can follow BTC-e API specs.
9
+ - Returns an object, keys are methods.
10
+ - Really few error abstraction, exceptions are raised.
11
+ - Nounce is enforced, I don't expect damm nounce error.
12
+ - Tests for the public API (rake test).
13
+
14
+ ### Cons:
15
+
16
+ - Not much abstraction, you should know BTC-e API.
17
+ - Its in **BETA** status. Not production tested until now.
18
+
19
+ ## Installation
20
+
21
+ Gemfile:
22
+
23
+ ```ruby
24
+ gem 'queru_btce'
25
+ ```
26
+
27
+ Execute:
28
+
29
+ ```bash
30
+ $ bundle
31
+ ```
32
+
33
+ Or install:
34
+
35
+ ```bash
36
+ $ gem install queru-btce
37
+ ```
38
+
39
+ ## Usage
40
+
41
+ This gem provides class methods for all public/private API methods offered by BTC-e.
42
+ Responses are hashes and any errors are raised as exception, your program can handle it.
43
+
44
+ - [BTC-E Trade API Documentation](https://btc-e.com/api/documentation)
45
+ - [BTC-E Public API Documentation](https://btc-e.com/api/3/docs)
46
+
47
+ You can call any BTC-e API methods this way:
48
+
49
+ ```ruby
50
+ QueruBtce.info
51
+ QueruBtce.ticker(:btc_usd)
52
+ QueruBtce.ticker(:btc_usd).btc_usd.last
53
+ QueruBtce.ticker(:btc_usd, :eth_usd).eth_usd.ask
54
+ ```
55
+
56
+ More docs to come.
57
+
58
+ ## Contributing
59
+
60
+ Pull requests, issues and comments are welcome the most of the days.
61
+
62
+ ## Thanks
63
+
64
+ To [Brock Harris](https://github.com/BrockHarris), I did started from his gem.
data/Rakefile ADDED
@@ -0,0 +1,9 @@
1
+ require 'bundler/gem_tasks'
2
+ require 'rake/testtask'
3
+
4
+ Rake::TestTask.new do |task|
5
+ task.libs << %w[test lib]
6
+ task.pattern = 'test/test_*.rb'
7
+ end
8
+
9
+ task default: :test
@@ -0,0 +1,3 @@
1
+ module QueruBtce
2
+ VERSION = '1.0'.freeze
3
+ end
data/lib/queru_btce.rb ADDED
@@ -0,0 +1,92 @@
1
+ require 'cgi'
2
+ require 'json'
3
+ require 'net/http'
4
+ require 'openssl'
5
+ require 'open-uri'
6
+ require 'ostruct'
7
+
8
+ module QueruBtce
9
+ @api_key = ''
10
+ @api_secret = ''
11
+ @last_nonce = Time.now.to_i
12
+
13
+ def self.credentials(key: '', secret: '')
14
+ @api_key = key
15
+ @api_secret = secret
16
+ end
17
+
18
+ def self.trade_api(m, opts = {})
19
+ opts[:method] = m
20
+ opts[:nonce] = nonce
21
+ payload = opts.collect do |key, val|
22
+ "#{key}=#{CGI::escape(val.to_s)}"
23
+ end.join('&')
24
+
25
+ signature = OpenSSL::HMAC.hexdigest('sha512', @api_secret, payload)
26
+
27
+ Net::HTTP.start('btc-e.com', 443, use_ssl: true) do |http|
28
+ headers = { 'Sign': signature, 'Key': @api_key }
29
+ response = http.post('/tapi', payload, headers).body
30
+ JSON.parse response, object_class: OpenStruct
31
+ end
32
+ rescue Net::HTTPUnauthorized
33
+ raise 'Bad API credentials'
34
+ rescue Net::HTTPError
35
+ raise 'HTTP Error: API down?'
36
+ end
37
+
38
+ def self.public_api(m, *pair)
39
+ if pair
40
+ pair = pair.join('-') if pair.is_a? Array
41
+ JSON.parse open("https://btc-e.com/api/3/#{m}/#{pair}").read, object_class: OpenStruct
42
+ else
43
+ JSON.parse open("https://btc-e.com/api/3/#{m}").read, object_class: OpenStruct
44
+ end
45
+ rescue OpenURI::HTTPError => e
46
+ raise "BTC-e API down? #{e}"
47
+ end
48
+
49
+ def self.nonce
50
+ new_nonce = Time.now.to_i
51
+ while new_nonce <= @last_nonce
52
+ sleep 1
53
+ new_nonce = Time.now.to_i
54
+ end
55
+ @last_nonce = new_nonce
56
+ end
57
+
58
+ def self.trade_api_methods
59
+ {
60
+ get_info: 'getInfo',
61
+ trade: 'Trade',
62
+ cancel_order: 'CancelOrder',
63
+ active_orders: 'ActiveOrders',
64
+ trans_history: 'TransHistory',
65
+ trade_history: 'TradeHistory'
66
+ }
67
+ end
68
+
69
+ def self.public_api_methods
70
+ {
71
+ info: 'info',
72
+ ticker: 'ticker',
73
+ depth: 'depth',
74
+ trades: 'trades'
75
+ }
76
+ end
77
+
78
+ def self.method_missing(m, *args)
79
+ if trade_api_methods.key? m
80
+ trade_api trade_api_methods[m], *args
81
+ elsif public_api_methods.key? m
82
+ public_api public_api_methods[m], *args
83
+ else
84
+ super
85
+ end
86
+ end
87
+
88
+ def self.respond_to_missing?(m, _include_all = false)
89
+ return true if trade_api_methods.key?(m) or public_api_methods.key?(m)
90
+ false
91
+ end
92
+ end
@@ -0,0 +1,29 @@
1
+ # coding: utf-8
2
+
3
+ lib = File.expand_path('../lib', __FILE__)
4
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
5
+ require 'queru_btce/version.rb'
6
+
7
+ Gem::Specification.new do |spec|
8
+ spec.name = 'queru_btce'
9
+ spec.version = QueruBtce::VERSION
10
+ spec.authors = ['Queru AKA Jorge Fuertes']
11
+ spec.email = ['jorge@jorgefuertes.com']
12
+ spec.summary = 'KISS BTC-E API Access from Ruby'
13
+ spec.description = 'Supports all API methods and currency pairs.'
14
+ spec.homepage = 'https://github.com/jorgefuertes/queru-btce'
15
+ spec.license = 'MIT'
16
+
17
+ spec.files = `git ls-files -z`.split("\x0")
18
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
19
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
20
+ spec.require_paths = ['lib']
21
+
22
+ spec.add_dependency 'json', '~> 2.1'
23
+ spec.add_dependency 'rubysl-ostruct', '~> 2.1'
24
+
25
+ spec.add_development_dependency 'bundler', '~> 1.5'
26
+ spec.add_development_dependency 'rake', '~> 12'
27
+ spec.add_development_dependency 'minitest', '~> 5.1'
28
+ spec.add_development_dependency 'shoulda', '~> 3.5'
29
+ end
@@ -0,0 +1,51 @@
1
+ require 'minitest/autorun'
2
+ require 'shoulda/context'
3
+ require 'queru_btce'
4
+
5
+ class TestQueruBtce < Minitest::Test
6
+ context 'QueruBtce Module' do
7
+ setup do
8
+ QueruBtce.credentials(key: 'mykey', secret: 'mysecret')
9
+ end
10
+
11
+ should 'respond to info' do
12
+ assert_respond_to QueruBtce, 'info'
13
+ end
14
+
15
+ should 'get public info as an object' do
16
+ assert_kind_of OpenStruct, QueruBtce.info
17
+ end
18
+
19
+ should 'see the server time' do
20
+ assert_kind_of Integer, QueruBtce.info.server_time
21
+ end
22
+
23
+ should 'calc consecutive nonce' do
24
+ assert QueruBtce.nonce < QueruBtce.nonce
25
+ end
26
+
27
+ should 'get a ticker' do
28
+ assert_kind_of Numeric, QueruBtce.ticker(:btc_usd).btc_usd.last
29
+ end
30
+
31
+ should 'get several tickers' do
32
+ assert_kind_of Numeric, QueruBtce.ticker(:btc_usd, :eth_usd).eth_usd.last
33
+ end
34
+
35
+ should 'get a pair depth orders' do
36
+ assert_kind_of Array, QueruBtce.depth(:btc_usd).btc_usd.asks
37
+ end
38
+
39
+ should 'get several pair depth orders' do
40
+ assert_kind_of Array, QueruBtce.depth(:btc_usd, :eth_usd).eth_usd.asks
41
+ end
42
+
43
+ should 'get a pair trades' do
44
+ assert_kind_of Numeric, QueruBtce.trades(:btc_usd).btc_usd[0].price
45
+ end
46
+
47
+ should 'get several pair trades' do
48
+ assert_kind_of Numeric, QueruBtce.trades(:btc_usd, :eth_usd).eth_usd[0].price
49
+ end
50
+ end
51
+ end
metadata ADDED
@@ -0,0 +1,140 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: queru_btce
3
+ version: !ruby/object:Gem::Version
4
+ version: '1.0'
5
+ platform: ruby
6
+ authors:
7
+ - Queru AKA Jorge Fuertes
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2017-06-14 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: json
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '2.1'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '2.1'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rubysl-ostruct
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: bundler
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '1.5'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '1.5'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rake
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '12'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '12'
69
+ - !ruby/object:Gem::Dependency
70
+ name: minitest
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '5.1'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '5.1'
83
+ - !ruby/object:Gem::Dependency
84
+ name: shoulda
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '3.5'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '3.5'
97
+ description: Supports all API methods and currency pairs.
98
+ email:
99
+ - jorge@jorgefuertes.com
100
+ executables: []
101
+ extensions: []
102
+ extra_rdoc_files: []
103
+ files:
104
+ - ".gitignore"
105
+ - ".rubocop.yml"
106
+ - ".travis.yml"
107
+ - Gemfile
108
+ - LICENSE.txt
109
+ - README.md
110
+ - Rakefile
111
+ - lib/queru_btce.rb
112
+ - lib/queru_btce/version.rb
113
+ - queru_btce.gemspec
114
+ - test/test_queru-btce.rb
115
+ homepage: https://github.com/jorgefuertes/queru-btce
116
+ licenses:
117
+ - MIT
118
+ metadata: {}
119
+ post_install_message:
120
+ rdoc_options: []
121
+ require_paths:
122
+ - lib
123
+ required_ruby_version: !ruby/object:Gem::Requirement
124
+ requirements:
125
+ - - ">="
126
+ - !ruby/object:Gem::Version
127
+ version: '0'
128
+ required_rubygems_version: !ruby/object:Gem::Requirement
129
+ requirements:
130
+ - - ">="
131
+ - !ruby/object:Gem::Version
132
+ version: '0'
133
+ requirements: []
134
+ rubyforge_project:
135
+ rubygems_version: 2.6.10
136
+ signing_key:
137
+ specification_version: 4
138
+ summary: KISS BTC-E API Access from Ruby
139
+ test_files:
140
+ - test/test_queru-btce.rb