btce-api 1.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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 36954fb0400939ea5647f9662df678da4352ef94
4
+ data.tar.gz: a3d0f2f464a4ac59eb44ea65bf3fbf0c360669a2
5
+ SHA512:
6
+ metadata.gz: a5bcb5c69ef80ee422c80981c1e37f195ecf07e210a34740124fe5e2078f2d6f51a63d44b0330fff69214ab632b4f2d1b04a43f23edd9e31a5664f920f52da6c
7
+ data.tar.gz: 12f75e31997982618a06d865fef7bad23744ec03659ffff49d89f9454155d0be3f0f13b9c143e38ea7f6e0e02a2f6a52c751606cba5f34f282e44e79e7613e5a
@@ -0,0 +1,19 @@
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
+ .idea
19
+ .DS_Store
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
@@ -0,0 +1,18 @@
1
+ The BTC-E Ruby API Library
2
+ Copyright (C) 2013 Maxim Kouprianov
3
+
4
+ This software is provided 'as-is', without any express or implied
5
+ warranty. In no event will the authors be held liable for any damages
6
+ arising from the use of this software.
7
+
8
+ Permission is granted to anyone to use this software for any purpose,
9
+ including commercial applications, and to alter it and redistribute it
10
+ freely, subject to the following restrictions:
11
+
12
+ 1. The origin of this software must not be misrepresented; you must not
13
+ claim that you wrote the original software. If you use this software
14
+ in a product, an acknowledgment in the product documentation would be
15
+ appreciated but is not required.
16
+ 2. Altered source versions must be plainly marked as such, and must not be
17
+ misrepresented as being the original software.
18
+ 3. This notice may not be removed or altered from any source distribution.
@@ -0,0 +1,92 @@
1
+ ## The BTC-E Ruby API Library :ru:
2
+
3
+ ### Installation
4
+ ```
5
+ gem install btce-api
6
+ ```
7
+
8
+ ### Usage
9
+ ```
10
+ $ ./balance.rb
11
+ =============================
12
+ RUR: 2001.000004
13
+ USD: 0.000061
14
+ LTC: 32.242009
15
+ BTC: 0.000141
16
+ =============================
17
+ At: 2013-04-21 16:34:50 +0400
18
+ ```
19
+ That was made with these lines:
20
+ ```Ruby
21
+ require 'btce'
22
+ api = Btce::Api.new(KEY, SECRET)
23
+
24
+ puts '============================='
25
+ puts 'RUR: %f' % api.balance.amount(Btce::RUR)
26
+ puts 'USD: %f' % api.balance.amount(Btce::USD)
27
+ puts 'LTC: %f' % api.balance.amount(Btce::LTC)
28
+ puts 'BTC: %f' % api.balance.amount(Btce::BTC)
29
+ puts '============================='
30
+ puts 'At: %s' % Time.at(api.stats.server_time)
31
+ ```
32
+ Check other examples in the **examples/** folder,
33
+ this library has the **100%** private API coverage.
34
+
35
+ ### FYI
36
+ * Public API is coming soon;
37
+ * API methods will throw an exception if server reports an error, please catch that;
38
+ * Don't forget to update keys with your own, otherwise examples won't work;
39
+ * Please feel free to report/fix any bugs;
40
+ * Check out the **LICENSE**.
41
+
42
+ ### Documentation
43
+ API is synced wih https://btc-e.com/api/documentation
44
+
45
+ * **GetInfo - Api::get_info**, also there are helpers:
46
+ - (unofficial) `Api::update`, drops info cache (next 3 methods are cached);
47
+ - (unofficial) `Api::balance`, returns a `Types::Balance` hash;
48
+ - (unofficial) `Api::rights`, returns a `Types::Rights` hash;
49
+ - (unofficial) `Api::stats`, returns a `Types::Stats` hash.
50
+ * **TransHistory - Api::trans_history**
51
+ - options: `from, count, from_id, end_id, order, since, end`
52
+ - returns a `Types::Transaction` set.
53
+ * **TradeHistory - Api::trade_history**
54
+ - options: `from, count, from_id, end_id, order, since, end, pair`
55
+ - returns a `Types::Trade` set.
56
+ * **OrderList - Api::order_list**
57
+ - options: `from, count, from_id, end_id, order, since, end, pair, active`
58
+ - returns a `Types::Order` set.
59
+ * **Trade - Api::trade**
60
+ - parameters: `pair, type, rate, amount`
61
+ - returns a `Types::PlacedOrder` object.
62
+ * **CancelOrder - Api::cancel_order**
63
+ - parameter: `order_id`
64
+ - returns `order_id` of the cancelled order.
65
+ * **Types::Response**
66
+ - models response from server, used in `Btce::Bus`
67
+ * **Types::Balance**
68
+ - `amount(currency)`, where currency is like `Btce::USD`
69
+ * **Types::Rights**
70
+ - `info?`
71
+ - `trade?`
72
+ - `withdraw?`
73
+ * **Types::Stats**
74
+ - `transaction_count`, returns your overall transaction count;
75
+ - `open_orders`, returns your overall open orders count;
76
+ - `server_time` - subj.
77
+ * **Types::Transaction**
78
+ - has methods `id, type, amount, currency, desc, status, timestamp`
79
+ * **Types::Trade**
80
+ - has methods `id, pair, type, amount, rate, order_id, is_your_order, timestamp`
81
+ * **Types::Order**
82
+ - has methods `id, pair, type, amount, rate, timestamp_created, status`
83
+ - + one bonus `active?` which returns `true` if order is active.
84
+ * **Types::PlacedOrder**
85
+ - has methods `received, remains, order_id`
86
+ - + one bonus `cancel` which cancels the order itself.
87
+
88
+ ### Donate
89
+ * Bitcoin: 1KRagCPzzLYvNVzZSXUZN4f2hCRZibtiXa
90
+ * Litecoin: LLN2L8fsATuxNtQdiKeyK8ceqNuAVNexFf
91
+
92
+ ![We love bitcoin](https://en.bitcoin.it/w/images/en/b/b2/WeLv_BC_48px.png)
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,20 @@
1
+ # coding: utf-8
2
+ require File.expand_path('../lib/btce/defines/version', __FILE__)
3
+
4
+ Gem::Specification.new do |spec|
5
+ spec.name = 'btce-api'
6
+ spec.version = Btce::Api::VERSION
7
+ spec.authors = %w(Maxim Kouprianov)
8
+ spec.email = %w(maxim@kouprianov.com)
9
+ spec.description = %q{The BTC-E Ruby API Library}
10
+ spec.summary = %q{Introduces a handy interface for API requests and useful containers for results}
11
+ spec.homepage = 'https://github.com/Xlab/btce'
12
+ spec.license = 'zlib'
13
+ spec.required_ruby_version = '>= 1.9.3'
14
+
15
+ spec.files = `git ls-files`.split($/)
16
+ spec.require_paths = %w(lib)
17
+
18
+ spec.add_development_dependency 'bundler', '~> 1.3'
19
+ spec.add_development_dependency 'rake'
20
+ end
@@ -0,0 +1,17 @@
1
+ #!/usr/bin/env ruby
2
+ # VIEW BALANCE TEST
3
+
4
+ require 'yaml'
5
+ require_relative '../lib/api'
6
+
7
+ # LOAD KEYS
8
+ keys = YAML::load( open('keys.yml') )
9
+ api = Btce::Api.new(keys['key'], keys['secret'])
10
+
11
+ puts '============================='
12
+ puts 'RUR: %f' % api.balance.amount(Btce::RUR)
13
+ puts 'USD: %f' % api.balance.amount(Btce::USD)
14
+ puts 'LTC: %f' % api.balance.amount(Btce::LTC)
15
+ puts 'BTC: %f' % api.balance.amount(Btce::BTC)
16
+ puts '============================='
17
+ puts 'At: %s' % Time.at(api.stats.server_time)
@@ -0,0 +1,4 @@
1
+ # EDIT YOUR KEYS HERE
2
+ ---
3
+ key: '19X4H27V-OQ3664TH-VJENMUAP-JK119WPC-BQIZFUNT'
4
+ secret: '428a34ff791cdf31a1ebe6041ed12299d18ff8d9578f33ff342015134646eff8'
@@ -0,0 +1,16 @@
1
+ #!/usr/bin/env ruby
2
+ # VIEW YOUR PLACED ORDERS TEST
3
+
4
+ require 'yaml'
5
+ require_relative '../lib/api'
6
+
7
+ # LOAD KEYS
8
+ keys = YAML::load( open('keys.yml') )
9
+ api = Btce::Api.new(keys['key'], keys['secret'])
10
+
11
+ puts '============================='
12
+ api.order_list(:count => 3).each { |order|
13
+ puts order
14
+ }
15
+ puts '============================='
16
+ puts 'At: %s' % Time.at(api.stats.server_time)
@@ -0,0 +1,16 @@
1
+ #!/usr/bin/env ruby
2
+ # PERMISSIONS CHECK TEST
3
+
4
+ require 'yaml'
5
+ require_relative '../lib/api'
6
+
7
+ # LOAD KEYS
8
+ keys = YAML::load( open('keys.yml') )
9
+ api = Btce::Api.new(keys['key'], keys['secret'])
10
+
11
+ puts '============================='
12
+ puts 'Info: %s' % api.rights.info?
13
+ puts 'Trade: %s' % api.rights.trade?
14
+ puts 'Withdraw: %s' % api.rights.withdraw?
15
+ puts '============================='
16
+ puts 'At: %s' % Time.at(api.stats.server_time)
@@ -0,0 +1,24 @@
1
+ #!/usr/bin/env ruby
2
+ # PLACE 1 LTC SELL ORDER, VIEW STATUS, CANCEL, VIEW STATUS
3
+
4
+ require 'yaml'
5
+ require_relative '../lib/api'
6
+
7
+ # LOAD KEYS
8
+ keys = YAML::load( open('keys.yml') )
9
+ api = Btce::Api.new(keys['key'], keys['secret'])
10
+
11
+ puts '============================='
12
+ placed = api.trade(Btce::LTC_RUR, Btce::SELL, 120, 1) # sell 1 LTC for 120 RUR
13
+ puts 'Placed: %s' % placed
14
+ puts api.order_list(:count => 1).pop # last order
15
+ puts api.trans_history(:count => 1).pop # last transaction
16
+ puts 'Sleeping for 10 secs, check website for orders or just run ./orders.rb'
17
+
18
+ sleep 10
19
+
20
+ puts 'Cancelled order %s' % api.cancel_order(placed.order_id)
21
+ puts api.trans_history(:count => 1).pop # last transaction
22
+ puts 'Please check website anyway'
23
+ puts '============================='
24
+ puts 'At: %s' % Time.at(api.stats.server_time)
@@ -0,0 +1,16 @@
1
+ #!/usr/bin/env ruby
2
+ # VIEW YOUR LAST 3 TRADES TEST
3
+
4
+ require 'yaml'
5
+ require_relative '../lib/api'
6
+
7
+ # LOAD KEYS
8
+ keys = YAML::load( open('keys.yml') )
9
+ api = Btce::Api.new(keys['key'], keys['secret'])
10
+
11
+ puts '============================='
12
+ api.trade_history(:count => 3).each { |trade|
13
+ puts trade
14
+ }
15
+ puts '============================='
16
+ puts 'At: %s' % Time.at(api.stats.server_time)
@@ -0,0 +1,16 @@
1
+ #!/usr/bin/env ruby
2
+ # VIEW YOUR LAST 3 TRANSACTIONS TEST
3
+
4
+ require 'yaml'
5
+ require_relative '../lib/api'
6
+
7
+ # LOAD KEYS
8
+ keys = YAML::load( open('keys.yml') )
9
+ api = Btce::Api.new(keys['key'], keys['secret'])
10
+
11
+ puts '============================='
12
+ api.trans_history(:count => 3).each { |transaction|
13
+ puts transaction
14
+ }
15
+ puts '============================='
16
+ puts 'At: %s' % Time.at(api.stats.server_time)
@@ -0,0 +1,36 @@
1
+ # The BTC-E Ruby API Library
2
+ # Copyright (C) 2013 Maxim Kouprianov
3
+ #
4
+ # This software is provided 'as-is', without any express or implied
5
+ # warranty. In no event will the authors be held liable for any damages
6
+ # arising from the use of this software.
7
+ #
8
+ # Permission is granted to anyone to use this software for any purpose,
9
+ # including commercial applications, and to alter it and redistribute it
10
+ # freely, subject to the following restrictions:
11
+ #
12
+ # 1. The origin of this software must not be misrepresented; you must not
13
+ # claim that you wrote the original software. If you use this software
14
+ # in a product, an acknowledgment in the product documentation would be
15
+ # appreciated but is not required.
16
+ # 2. Altered source versions must be plainly marked as such, and must not be
17
+ # misrepresented as being the original software.
18
+ # 3. This notice may not be removed or altered from any source distribution.
19
+ #
20
+ # Authors: Maxim Kouprianov <maxim@kouprianov.com>
21
+ #
22
+
23
+ require 'openssl'
24
+ require 'net/https'
25
+ require 'json'
26
+ require 'cgi'
27
+
28
+ require_relative 'btce/defines/version'
29
+ require_relative 'btce/defines/settings'
30
+ require_relative 'btce/defines/currencies'
31
+ require_relative 'btce/defines/pairs'
32
+ require_relative 'btce/defines/tradetypes'
33
+
34
+ require_relative 'btce/bus'
35
+ require_relative 'btce/types'
36
+ require_relative 'btce/api'
@@ -0,0 +1,150 @@
1
+ # The BTC-E Ruby API Library
2
+ # Copyright (C) 2013 Maxim Kouprianov
3
+ #
4
+ # This software is provided 'as-is', without any express or implied
5
+ # warranty. In no event will the authors be held liable for any damages
6
+ # arising from the use of this software.
7
+ #
8
+ # Permission is granted to anyone to use this software for any purpose,
9
+ # including commercial applications, and to alter it and redistribute it
10
+ # freely, subject to the following restrictions:
11
+ #
12
+ # 1. The origin of this software must not be misrepresented; you must not
13
+ # claim that you wrote the original software. If you use this software
14
+ # in a product, an acknowledgment in the product documentation would be
15
+ # appreciated but is not required.
16
+ # 2. Altered source versions must be plainly marked as such, and must not be
17
+ # misrepresented as being the original software.
18
+ # 3. This notice may not be removed or altered from any source distribution.
19
+ #
20
+ # Authors: Maxim Kouprianov <maxim@kouprianov.com>
21
+ #
22
+
23
+ module Btce
24
+ class Api
25
+ def initialize(api_key, api_secret)
26
+ @bus = Btce::Bus.new(api_key, api_secret)
27
+ end
28
+
29
+ # getInfo
30
+ def get_info
31
+ response = Types::Response.new(JSON.parse(@bus.request({'method' => 'getInfo'})))
32
+ raise "server responded: #{response.error}" if response.success.zero?
33
+ response
34
+ end
35
+
36
+ # UNOFFICIAL: updates `getInfo` cache
37
+ def update
38
+ @info = get_info()
39
+ end
40
+
41
+ # UNOFFICIAL: getInfo -> funds
42
+ def balance
43
+ update() unless @info
44
+ Types::Balance.new @info.return
45
+ end
46
+
47
+ # UNOFFICIAL: getInfo -> rights
48
+ def rights
49
+ update() unless @info
50
+ Types::Rights.new @info.return
51
+ end
52
+
53
+ # UNOFFICIAL: getInfo -> other
54
+ def stats
55
+ update() unless @info
56
+ Types::Stats.new @info.return
57
+ end
58
+
59
+ # TransHistory
60
+ # Options are: from, count, from_id, end_id, order, since, end
61
+ def trans_history(options = {
62
+ :from => 0,
63
+ :count => 1000,
64
+ :from_id => 0,
65
+ :end_id => nil,
66
+ :order => :DESC, # ASC
67
+ :since => 0,
68
+ :end => nil
69
+ })
70
+
71
+ options[:method] = 'TransHistory'
72
+ response = Types::Response.new(JSON.parse(@bus.request(options)))
73
+ raise "server responded: #{response.error}" if response.success.zero?
74
+ response.return.map do |id, data|
75
+ Types::Transaction.new(id, data)
76
+ end
77
+ end
78
+
79
+ # TradeHistory
80
+ # Options are: from, count, from_id, end_id, order, since, end, pair
81
+ def trade_history(options = {
82
+ :from => 0,
83
+ :count => 1000,
84
+ :from_id => 0,
85
+ :end_id => nil,
86
+ :order => :DESC, # ASC
87
+ :since => 0,
88
+ :end => nil,
89
+ :pair => nil
90
+ })
91
+
92
+ options[:method] = 'TradeHistory'
93
+ response = Types::Response.new(JSON.parse(@bus.request(options)))
94
+ raise "server responded: #{response.error}" if response.success.zero?
95
+ response.return.map do |id, data|
96
+ Types::Trade.new(id, data)
97
+ end
98
+ end
99
+
100
+ # OrderList
101
+ # Options are: from, count, from_id, end_id, order, since, end, pair, active
102
+ def order_list(options = {
103
+ :from => 0,
104
+ :count => 1000,
105
+ :from_id => 0,
106
+ :end_id => nil,
107
+ :order => :DESC, # ASC
108
+ :since => 0,
109
+ :end => nil,
110
+ :pair => nil,
111
+ :active => 1 # 0
112
+ })
113
+
114
+ options[:method] = 'OrderList'
115
+ response = Types::Response.new(JSON.parse(@bus.request(options)))
116
+ raise "server responded: #{response.error}" if response.success.zero?
117
+ response.return.map do |id, data|
118
+ Types::Order.new(id, data)
119
+ end
120
+ end
121
+
122
+ # Trade
123
+ # Parameters are: pair, type, rate, amount
124
+ def trade(pair, type, rate, amount)
125
+ options = {
126
+ :pair => pair,
127
+ :type => type,
128
+ :rate => rate,
129
+ :amount => amount,
130
+ :method => 'Trade'
131
+ }
132
+ response = Types::Response.new(JSON.parse(@bus.request(options)))
133
+ raise "server responded: #{response.error}" if response.success.zero?
134
+ Types::PlacedOrder.new(self, response.return)
135
+ end
136
+
137
+ # CancelOrder
138
+ def cancel_order(order_id)
139
+ options = {
140
+ :order_id => order_id,
141
+ :method => 'CancelOrder'
142
+ }
143
+
144
+ response = Types::Response.new(JSON.parse(@bus.request(options)))
145
+ raise "server responded: #{response.error}" if response.success.zero?
146
+ response.return['order_id']
147
+ end
148
+ end
149
+ end
150
+
@@ -0,0 +1,61 @@
1
+ # The BTC-E Ruby API Library
2
+ # Copyright (C) 2013 Maxim Kouprianov
3
+ #
4
+ # This software is provided 'as-is', without any express or implied
5
+ # warranty. In no event will the authors be held liable for any damages
6
+ # arising from the use of this software.
7
+ #
8
+ # Permission is granted to anyone to use this software for any purpose,
9
+ # including commercial applications, and to alter it and redistribute it
10
+ # freely, subject to the following restrictions:
11
+ #
12
+ # 1. The origin of this software must not be misrepresented; you must not
13
+ # claim that you wrote the original software. If you use this software
14
+ # in a product, an acknowledgment in the product documentation would be
15
+ # appreciated but is not required.
16
+ # 2. Altered source versions must be plainly marked as such, and must not be
17
+ # misrepresented as being the original software.
18
+ # 3. This notice may not be removed or altered from any source distribution.
19
+ #
20
+ # Authors: Maxim Kouprianov <maxim@kouprianov.com>
21
+ #
22
+
23
+ module Btce
24
+ class Bus
25
+ def initialize(api_key, api_secret)
26
+ @api_key = api_key
27
+ @api_secret = api_secret
28
+ @nonce = 0
29
+ end
30
+
31
+ def request(data)
32
+ # Timestamp for the request
33
+ data[:nonce] = Time::now.to_i + @nonce
34
+ @nonce += 1
35
+
36
+ # Form parametrized string
37
+ postdata = data.collect do |key, value|
38
+ "#{key}=#{CGI::escape(value.to_s)}"
39
+ end.join('&')
40
+
41
+ # Open HTTPS connection
42
+ Net::HTTP.start(Btce::Api::HOST, Btce::Api::PORT, :use_ssl => true) do |http|
43
+ # Headers setup
44
+ headers = {
45
+ 'Sign' => sign(postdata),
46
+ 'Key' => @api_key,
47
+ 'User-Agent' => Btce::Api::AGENT
48
+ }
49
+
50
+ # Send signed data
51
+ return http.post(Btce::Api::API_URL, postdata, headers).body
52
+ end
53
+ end
54
+
55
+ def sign(data)
56
+ # Sign data with the HMAC SHA-512 algorhythm
57
+ # Read https://btc-e.com/defines/documentation
58
+ OpenSSL::HMAC.hexdigest(Btce::Api::HMAC_SHA, @api_secret, data)
59
+ end
60
+ end
61
+ end
@@ -0,0 +1,11 @@
1
+ module Btce
2
+ BTC = 'btc'
3
+ LTC = 'ltc'
4
+ NMC = 'nmc'
5
+ NVC = 'nvc'
6
+ TRC = 'trc'
7
+ PPC = 'ppc'
8
+ USD = 'usd'
9
+ RUR = 'rur'
10
+ EUR = 'eur'
11
+ end
@@ -0,0 +1,14 @@
1
+ module Btce
2
+ BTC_USD = 'btc_usd'
3
+ BTC_RUR = 'btc_rur'
4
+ BTC_EUR = 'btc_eur'
5
+ LTC_BTC = 'ltc_btc'
6
+ LTC_USD = 'ltc_usd'
7
+ LTC_RUR = 'ltc_rur'
8
+ NMC_BTC = 'nmc_btc'
9
+ USD_RUR = 'usd_rur'
10
+ EUR_USD = 'eur_usd'
11
+ NVC_BTC = 'nvc_btc'
12
+ TRC_BTC = 'trc_btc'
13
+ PPC_BTC = 'ppc_btc'
14
+ end
@@ -0,0 +1,9 @@
1
+ module Btce
2
+ class Api
3
+ HOST = 'btc-e.com'
4
+ PORT = '443'
5
+ AGENT = 'Mozilla/4.0 (compatible; BTC-E Ruby API library; Xlab)'
6
+ API_URL = '/tapi'
7
+ HMAC_SHA = 'sha512'
8
+ end
9
+ end
@@ -0,0 +1,4 @@
1
+ module Btce
2
+ BUY = 'buy'
3
+ SELL = 'sell'
4
+ end
@@ -0,0 +1,5 @@
1
+ module Btce
2
+ class Api
3
+ VERSION = '1.0.0'
4
+ end
5
+ end
@@ -0,0 +1,149 @@
1
+ # The BTC-E Ruby API Library
2
+ # Copyright (C) 2013 Maxim Kouprianov
3
+ #
4
+ # This software is provided 'as-is', without any express or implied
5
+ # warranty. In no event will the authors be held liable for any damages
6
+ # arising from the use of this software.
7
+ #
8
+ # Permission is granted to anyone to use this software for any purpose,
9
+ # including commercial applications, and to alter it and redistribute it
10
+ # freely, subject to the following restrictions:
11
+ #
12
+ # 1. The origin of this software must not be misrepresented; you must not
13
+ # claim that you wrote the original software. If you use this software
14
+ # in a product, an acknowledgment in the product documentation would be
15
+ # appreciated but is not required.
16
+ # 2. Altered source versions must be plainly marked as such, and must not be
17
+ # misrepresented as being the original software.
18
+ # 3. This notice may not be removed or altered from any source distribution.
19
+ #
20
+ # Authors: Maxim Kouprianov <maxim@kouprianov.com>
21
+ #
22
+
23
+ module Btce
24
+ module Types
25
+ class Response
26
+ attr_reader :success
27
+ attr_reader :return
28
+ attr_reader :error
29
+
30
+ def initialize(data) # from JSON.parse
31
+ @success = data['success']
32
+ @return = data['return']
33
+ @error = data['error']
34
+ end
35
+ end
36
+
37
+ class Balance
38
+ def initialize(data) # from Response.return
39
+ @funds = data['funds']
40
+ end
41
+
42
+ def amount(currency)
43
+ @funds[currency]
44
+ end
45
+
46
+ def to_s
47
+ @funds.to_s
48
+ end
49
+ end
50
+
51
+ class Rights
52
+ def info?
53
+ @rights['info'].zero? ? false : true
54
+ end
55
+
56
+ def trade?
57
+ @rights['trade'].zero? ? false : true
58
+ end
59
+
60
+ def withdraw?
61
+ @rights['withdraw'].zero? ? false : true
62
+ end
63
+
64
+ def initialize(data) # from Response.return
65
+ @rights = data['rights']
66
+ end
67
+
68
+ def to_s
69
+ @rights.to_s
70
+ end
71
+ end
72
+
73
+ class Stats
74
+ attr_reader :transaction_count, :open_orders, :server_time
75
+
76
+ def initialize(data) # from Response.return
77
+ @transaction_count = data['transaction_count']
78
+ @open_orders = data['open_orders']
79
+ @server_time = data['server_time'] # UNIX timestamp
80
+ end
81
+ end
82
+
83
+ class Transaction
84
+ attr_reader :id, :type, :amount, :currency, :desc, :status, :timestamp
85
+
86
+ def initialize(id, data) # from Response.return
87
+ @values = data
88
+ @values[:id] = id
89
+ @values.each { |name, value| instance_variable_set("@#{name}", value) }
90
+ end
91
+
92
+ def to_s
93
+ @values.to_s
94
+ end
95
+ end
96
+
97
+ class Trade
98
+ attr_reader :id, :pair, :type, :amount, :rate, :order_id, :is_your_order, :timestamp
99
+
100
+ def initialize(id, data) # from Response.return
101
+ data.delete('funds')
102
+ @values = data
103
+ @values[:id] = id
104
+ @values.each { |name, value| instance_variable_set("@#{name}", value) }
105
+ end
106
+
107
+ def to_s
108
+ @values.to_s
109
+ end
110
+ end
111
+
112
+ class Order
113
+ attr_reader :id, :pair, :type, :amount, :rate, :timestamp_created, :status
114
+
115
+ def initialize(id, data) # from Response.return
116
+ @values = data
117
+ @values[:id] = id
118
+ @values.each { |name, value| instance_variable_set("@#{name}", value) }
119
+ end
120
+
121
+ def active?
122
+ @values['status'].zero? ? false : true
123
+ end
124
+
125
+ def to_s
126
+ @values.to_s
127
+ end
128
+ end
129
+
130
+ class PlacedOrder
131
+ attr_reader :received, :remains, :order_id
132
+
133
+ def initialize(api, data) # from Response.return
134
+ @api = api
135
+ data.delete('funds')
136
+ @values = data
137
+ @values.each { |name, value| instance_variable_set("@#{name}", value) }
138
+ end
139
+
140
+ def cancel
141
+ @api.cancel_order @values[:order_id]
142
+ end
143
+
144
+ def to_s
145
+ @values.to_s
146
+ end
147
+ end
148
+ end
149
+ end
metadata ADDED
@@ -0,0 +1,95 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: btce-api
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Maxim
8
+ - Kouprianov
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-04-21 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: bundler
16
+ requirement: !ruby/object:Gem::Requirement
17
+ requirements:
18
+ - - ~>
19
+ - !ruby/object:Gem::Version
20
+ version: '1.3'
21
+ type: :development
22
+ prerelease: false
23
+ version_requirements: !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - ~>
26
+ - !ruby/object:Gem::Version
27
+ version: '1.3'
28
+ - !ruby/object:Gem::Dependency
29
+ name: rake
30
+ requirement: !ruby/object:Gem::Requirement
31
+ requirements:
32
+ - - '>='
33
+ - !ruby/object:Gem::Version
34
+ version: '0'
35
+ type: :development
36
+ prerelease: false
37
+ version_requirements: !ruby/object:Gem::Requirement
38
+ requirements:
39
+ - - '>='
40
+ - !ruby/object:Gem::Version
41
+ version: '0'
42
+ description: The BTC-E Ruby API Library
43
+ email:
44
+ - maxim@kouprianov.com
45
+ executables: []
46
+ extensions: []
47
+ extra_rdoc_files: []
48
+ files:
49
+ - .gitignore
50
+ - Gemfile
51
+ - LICENSE.txt
52
+ - README.md
53
+ - Rakefile
54
+ - btce-api.gemspec
55
+ - examples/balance.rb
56
+ - examples/keys.yml
57
+ - examples/orders.rb
58
+ - examples/rights.rb
59
+ - examples/trade.rb
60
+ - examples/trades.rb
61
+ - examples/transactions.rb
62
+ - lib/btce.rb
63
+ - lib/btce/api.rb
64
+ - lib/btce/bus.rb
65
+ - lib/btce/defines/currencies.rb
66
+ - lib/btce/defines/pairs.rb
67
+ - lib/btce/defines/settings.rb
68
+ - lib/btce/defines/tradetypes.rb
69
+ - lib/btce/defines/version.rb
70
+ - lib/btce/types.rb
71
+ homepage: https://github.com/Xlab/btce
72
+ licenses:
73
+ - zlib
74
+ metadata: {}
75
+ post_install_message:
76
+ rdoc_options: []
77
+ require_paths:
78
+ - lib
79
+ required_ruby_version: !ruby/object:Gem::Requirement
80
+ requirements:
81
+ - - '>='
82
+ - !ruby/object:Gem::Version
83
+ version: 1.9.3
84
+ required_rubygems_version: !ruby/object:Gem::Requirement
85
+ requirements:
86
+ - - '>='
87
+ - !ruby/object:Gem::Version
88
+ version: '0'
89
+ requirements: []
90
+ rubyforge_project:
91
+ rubygems_version: 2.0.3
92
+ signing_key:
93
+ specification_version: 4
94
+ summary: Introduces a handy interface for API requests and useful containers for results
95
+ test_files: []