vexapion 0.3.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,31 @@
1
+ # coding: utf-8
2
+
3
+ # based off of quandl gem: https://github.com/quandl/quandl-ruby
4
+
5
+ module Vexapion
6
+
7
+ class VexapionRuntimeError < StandardError
8
+ attr_reader :success
9
+ attr_reader :error_message
10
+ attr_reader :response
11
+
12
+ def initialize(i_success = nil, i_msg = nil, i_response = nil)
13
+ @success = i_success
14
+ @message = i_msg
15
+ @response = i_response
16
+ end
17
+
18
+ def to_s
19
+ "#{@error_message}: #{@response}"
20
+ end
21
+ end
22
+
23
+ #Error Response
24
+ class RequestFailed < VexapionRuntimeError
25
+ end
26
+
27
+ #Socket Error
28
+ class SocketError < VexapionRuntimeError
29
+ end
30
+
31
+ end #of Vexapion module
@@ -0,0 +1,173 @@
1
+ # coding: utf-8
2
+
3
+ require 'vexapion'
4
+
5
+ module Vexapion
6
+
7
+ class Poloniex < BaseExchanges
8
+ def initialize(key = nil, secret = nil)
9
+ super(key, secret)
10
+
11
+ @public_url = 'https://poloniex.com/public?'
12
+ @private_url = 'https://poloniex.com/tradingApi'
13
+ set_min_interval(0.5)
14
+ end
15
+
16
+ def set_min_interval(sec)
17
+ @conn.min_interval = sec
18
+ end
19
+
20
+
21
+ # Public API
22
+
23
+ def volume_24hours
24
+ get('return24hVolume')
25
+ end
26
+
27
+ def ticker
28
+ get('returnTicker')
29
+ end
30
+
31
+ def orderbook(pair, depth)
32
+ get('returnOrderBook', currencyPair: pair.upcase, depth: depth)
33
+ end
34
+
35
+ def market_trade_history(pair, start_time='', end_time='')
36
+ params = { currencyPair: pair.upcase }
37
+ params[:start] = start_time if start_time != ''
38
+ params[:end] = end_time if end_time != ''
39
+ get('returnTradeHistory', params)
40
+ end
41
+
42
+
43
+ # Trade(Private) API
44
+
45
+ def fee_info
46
+ post('returnFeeInfo')
47
+ end
48
+
49
+ def balances
50
+ post('returnBalances')
51
+ end
52
+
53
+ def complete_balances(account='all')
54
+ post('returnCompleteBalances', 'account' => account)
55
+ end
56
+
57
+ def open_orders(pair)
58
+ post('returnOpenOrders', currencyPair: pair.upcase)
59
+ end
60
+
61
+ def trade_history(pair, start, end_time)
62
+ post('returnTradeHistory', 'currencyPair' => pair.upcase,
63
+ 'start' => start, 'end' => end_time)
64
+ end
65
+
66
+ def buy(pair, rate, amount)
67
+ post('buy', 'currencyPair' => pair.upcase,
68
+ 'rate' => rate, 'amount' => amount)
69
+ end
70
+
71
+ def sell(pair, rate, amount)
72
+ post('sell', 'currencyPair' => pair.upcase,
73
+ 'rate' => rate, 'amount' => amount)
74
+ end
75
+
76
+ def cancel_order(order_number)
77
+ post('cancelOrder', orderNumber: order_number)
78
+ end
79
+
80
+ def move_order(order_number, rate)
81
+ post('moveOrder', orderNumber: order_number, 'rate' => rate)
82
+ end
83
+
84
+ def withdraw(currency, amount, address)
85
+ post('widthdraw', currency: currency.upcase,
86
+ 'amount' => amount, 'address' => address)
87
+ end
88
+
89
+ def available_account_balances
90
+ post('returnAvailableAccountBalances')
91
+ end
92
+
93
+ def tradable_balances
94
+ post('returnTradableBalances')
95
+ end
96
+
97
+ def transfer_balance(currency, amount, from_account, to_account)
98
+ post('transferBalance', currency: currency.upcase, amount: amount,
99
+ fromAccount: from_account, toAccount: to_account)
100
+ end
101
+
102
+ def margin_account_summary
103
+ post('returnMarginAccountSummary')
104
+ end
105
+
106
+ def margin_buy(pair, rate, amount)
107
+ post('marginBuy', 'currencyPair' => pair.upcase,
108
+ 'rate' => rate, 'amount' => amount)
109
+ end
110
+
111
+ def margin_sell(pair, rate, amount)
112
+ post('marginSell', 'currencyPair' => pair.upcase,
113
+ 'rate' => rate, 'amount' => amount)
114
+ end
115
+
116
+ def deposit_addresses
117
+ post('returnDepositAddresses')
118
+ end
119
+
120
+ def generate_new_address(currency)
121
+ post('generateNewAddress', 'currency' => currency.upcase)
122
+ end
123
+
124
+ def deposits_withdrawals(start_time, end_time, count)
125
+ post('returnDepositsWithdrawals',
126
+ 'start' => start_time, 'end' => end_time, 'count' => count)
127
+ end
128
+
129
+ # Create request header & body
130
+
131
+ private
132
+
133
+ def get(command, params = {})
134
+ params['command'] = command
135
+ param = URI.encode_www_form(params)
136
+ uri = URI.parse @public_url + param
137
+ request = Net::HTTP::Get.new(uri.request_uri)
138
+
139
+ res = do_command(uri, request)
140
+ error_check(res)
141
+ res
142
+ end
143
+
144
+ def post(command, params = {})
145
+ params['command'] = command
146
+ params['nonce'] = get_nonce
147
+
148
+ post_data = URI.encode_www_form(params)
149
+ header = headers(signature(post_data))
150
+
151
+ uri = URI.parse @private_url
152
+ request = Net::HTTP::Post.new(uri.request_uri, initheader = header)
153
+ request.body = post_data
154
+
155
+ res = do_command(uri, request)
156
+ error_check(res)
157
+ res
158
+ end
159
+
160
+ def signature(data)
161
+ algo = OpenSSL::Digest.new('sha512')
162
+ OpenSSL::HMAC.hexdigest(algo, @secret, data)
163
+ end
164
+
165
+ def headers(sign)
166
+ {
167
+ 'Sign' => sign,
168
+ 'Key' => @key
169
+ }
170
+ end
171
+
172
+ end #of class
173
+ end #of Vexapion module
@@ -0,0 +1,3 @@
1
+ module Vexapion
2
+ VERSION = '0.3.0'
3
+ end
@@ -0,0 +1,257 @@
1
+ # coding: utf-8
2
+
3
+ # Zaif Exchange API Ver 1.05.02 対応版
4
+ # 2017/1/21現在
5
+
6
+ require 'vexapion'
7
+
8
+ module Vexapion
9
+
10
+ # zaifのAPIラッパークラスです。
11
+ # 各メソッドの戻り値は下記URLを参照してください。
12
+ # @see https://corp.zaif.jp/api-docs/
13
+
14
+ class Zaif < BaseExchanges
15
+
16
+ def initialize(key = nil, secret = nil)
17
+ super(key,secret)
18
+
19
+ @public_url = 'https://api.zaif.jp/api/1/'
20
+ @private_url = 'https://api.zaif.jp/tapi'
21
+ end
22
+
23
+ def available_pair
24
+ #balanceから取れるかもしれない
25
+ ['btc_jpy', 'xem_jpy', 'xem_btc',
26
+ 'mona_jpy', 'mona_btc', 'zaif_jpy', 'zaif_btc']
27
+ end
28
+
29
+ # Public API
30
+
31
+ # @raise RequestFailed APIリクエストの失敗
32
+ # @raise SocketError ソケットエラー
33
+ # @raise RetryException リクエストの結果が確認できないとき 408, 500, 503
34
+ # @raise Warning 何かがおかしいと時(200 && response.body == nil), 509
35
+ # @raise Error クライアントエラー 400, 401, 403
36
+ # @raise Fatal APIラッパーの修正が必要と思われるエラー, 404
37
+
38
+
39
+ # 終値
40
+ # @param [String] pair 取得したい通貨ペア
41
+ # @return [Hash]
42
+ def last_price(pair)
43
+ get('last_price', pair)
44
+ end
45
+
46
+ # ティッカー
47
+ # @param [String] pair 取得したい通貨ペア
48
+ # @return [Hash]
49
+ def ticker(pair)
50
+ get('ticker', pair)
51
+ end
52
+
53
+ # 取引履歴
54
+ # @param [String] pair 取得したい通貨ペア
55
+ # @return [Array]
56
+ def trades(pair)
57
+ get('trades', pair)
58
+ end
59
+
60
+ # 板情報
61
+ # @param [String] pair 取得したい通貨ペア
62
+ # @return [Hash]
63
+ def depth(pair)
64
+ get('depth', pair)
65
+ end
66
+
67
+ # Private API
68
+
69
+ # 現在の残高(余力および残高・トークン)、APIキーの権限、過去のトレード数
70
+ # アクティブな注文数、サーバーのタイムスタンプを取得します
71
+ # @return [Hash]
72
+ def get_info
73
+ post('get_info')
74
+ end
75
+
76
+ # 現在の残高(余力および残高・トークン)、APIキーの権限、
77
+ # アクティブな注文数、サーバーのタイムスタンプを取得します
78
+ # @return [Hash]
79
+ def get_info2
80
+ post('get_info2')
81
+ end
82
+
83
+ # チャットに使用されるニックネームと画像のパスを返します。
84
+ # @return [Hash]
85
+ def get_personal_info
86
+ post('get_personal_info')
87
+ end
88
+
89
+ # 未約定の注文一覧を取得します
90
+ # @param [String] pair 取得したい通貨ペア。省略時はすべての通貨ペア
91
+ # @return [Hash]
92
+ def active_orders(pair = '')
93
+ params = Hash.new
94
+ params['currency_pair'] = pair if pair != ''
95
+
96
+ post('active_orders', params)
97
+ end
98
+
99
+ # 未約定の注文一覧を取得します
100
+ # @param [String] pair トレードしたい通貨ペア
101
+ # @param [String] action 注文の種類 ask(売)/bid(買)
102
+ # @param [Float] price 注文価格(ただしBTC_JPYの時はInteger)
103
+ # @param [Float] amount 注文量
104
+ # @param [Float] limit リミット注文価格(ただしBTC_JPYの時はInteger)
105
+ # @return [Hash]
106
+ def trade(pair, action, price, amount, limit = '')
107
+ params = {
108
+ currency_pair: pair,
109
+ action: action,
110
+ price: price,
111
+ amount: amount
112
+ }
113
+ params['limit'] = limit if limit != ''
114
+
115
+ post('trade', params)
116
+ end
117
+
118
+ #注文のキャンセルをします
119
+ # @param [Integer] id 注文ID
120
+ # @return [Hash]
121
+ def cancel_order(id)
122
+ post('cancel_order', 'order_id' => id)
123
+ end
124
+
125
+ # トレードヒストリーを取得します。
126
+ # @param [String] pair 取得したい通貨ペア
127
+ # @param [Integer] i_since 開始タイムスタンプ(UNIX time)
128
+ # @param [Integer] i_end 終了タイムスタンプ(UNIX time)
129
+ # @param [Integer] i_from この順番のレコードから取得
130
+ # @param [Integer] i_count 取得するレコード数
131
+ # @param [Integer] from_id このトランザクションIDのレコードから取得
132
+ # @param [Integer] end_id このトランザクションIDのレコードまで取得
133
+ # @param [String] order ソート順('ASC'/'DESC')
134
+ # @return [Hash]
135
+ def trade_history(pair = '', i_since = '', i_end = '',
136
+ i_from = '', i_count = '', from_id = '', end_id = '', order = '')
137
+
138
+ params = Hash.new
139
+ params['currency_pair'] = pair if pair != ''
140
+ params['since'] = i_since if i_since != ''
141
+ params['end'] = i_end if i_end != ''
142
+ params['from'] = i_from if i_from != ''
143
+ params['count'] = i_count if i_count != ''
144
+ params['from_id'] = from_id if from_id != ''
145
+ params['end_id'] = end_id if end_id != ''
146
+ params['order'] = order if order != ''
147
+
148
+ post('trade_history', params)
149
+ end
150
+
151
+
152
+ # 払出のリクエストをします。
153
+ # @param [String] currency 払出したい通貨
154
+ # @param [Float] amount 送金量
155
+ # @param [String] address 送信先アドレス
156
+ # @param [Float] fee 採掘者への手数料(XEM以外)
157
+ # @param [String] message 送信メッセージ(XEMのみ)
158
+ # @return [Hash]
159
+ def withdraw(currency, amount, address, fee = nil, message = nil)
160
+ params = {
161
+ currency: currency.downcase,
162
+ amount: amount,
163
+ address: address
164
+ }
165
+ params['message'] = message if message != nil
166
+ params['opt_fee'] = fee if fee != nil
167
+
168
+ post('withdraw', params)
169
+ end
170
+
171
+ # 入金履歴を取得します。
172
+ # @param [String] currency 取得したい通貨
173
+ # @param [Integer] i_since 開始タイムスタンプ(UNIX time)
174
+ # @param [Integer] i_end 終了タイムスタンプ(UNIX time)
175
+ # @param [Integer] i_from この順番のレコードから取得
176
+ # @param [Integer] i_count 取得するレコード数
177
+ # @param [Integer] from_id このトランザクションIDのレコードから取得
178
+ # @param [Integer] end_id このトランザクションIDのレコードまで取得
179
+ # @param [String] order ソート順('ASC'/'DESC')
180
+ # @return [Hash]
181
+ def deposit_history(currency, i_since = '', i_end = '',
182
+ i_from = '', i_count = '', from_id = '', end_id = '', order = '')
183
+
184
+ params = Hash.new
185
+ params['currency'] = currency
186
+ params['since'] = i_since if i_since != ''
187
+ params['end'] = i_end if i_end != ''
188
+ params['from'] = i_from if i_from != ''
189
+ params['count'] = i_count if i_count != ''
190
+ params['from_id'] = from_id if from_id != ''
191
+ params['end_id'] = end_id if end_id != ''
192
+ params['order'] = order if order != ''
193
+
194
+ post('deposit_history', params)
195
+ end
196
+
197
+ # 出金履歴を取得します。
198
+ # @param [String] currency 取得したい通貨
199
+ # @param [Integer] i_since 開始タイムスタンプ(UNIX time)
200
+ # @param [Integer] i_end 終了タイムスタンプ(UNIX time)
201
+ # @param [Integer] i_from この順番のレコードから取得
202
+ # @param [Integer] i_count 取得するレコード数
203
+ # @param [Integer] from_id このトランザクションIDのレコードから取得
204
+ # @param [Integer] end_id このトランザクションIDのレコードまで取得
205
+ # @param [String] order ソート順('ASC'/'DESC')
206
+ # @return [Hash]
207
+ def withdraw_history(currency, i_since = '', i_end = '',
208
+ i_from = '', i_count = '', from_id = '', end_id = '', order = '')
209
+
210
+ params = Hash.new
211
+ params['currency'] = currency
212
+ params['since'] = i_since if i_since != ''
213
+ params['end'] = i_end if i_end != ''
214
+ params['from'] = i_from if i_from != ''
215
+ params['count'] = i_count if i_count != ''
216
+ params['from_id'] = from_id if from_id != ''
217
+ params['end_id'] = end_id if end_id != ''
218
+ params['order'] = order if order != ''
219
+
220
+ post('withdraw_history', params)
221
+ end
222
+
223
+
224
+ # Create request header & body
225
+
226
+ private
227
+
228
+ def get(method, pair)
229
+ url = "#{@public_url}#{method.downcase}/#{pair.downcase}"
230
+ uri = URI.parse url
231
+ request = Net::HTTP::Get.new(uri.request_uri)
232
+
233
+ do_command(uri, request)
234
+ end
235
+
236
+ def post(method, params = {})
237
+ uri = URI.parse @private_url
238
+ params['method'] = method
239
+ params['nonce'] = get_nonce
240
+
241
+ request = Net::HTTP::Post.new(uri)
242
+ request.set_form_data(params) #クエリをURLエンコード (p1=v1&p2=v2...)
243
+ request['Key'] = @key
244
+ request['Sign'] = signature(request)
245
+
246
+ res = do_command(uri, request)
247
+ error_check(res)
248
+ res
249
+ end
250
+
251
+ def signature(req)
252
+ algo = OpenSSL::Digest.new('sha512')
253
+ OpenSSL::HMAC.hexdigest(algo, @secret, req.body)
254
+ end
255
+
256
+ end #of class
257
+ end #of Vexapion module
data/lib/vexapion.rb ADDED
@@ -0,0 +1,19 @@
1
+ require 'net/http'
2
+ require 'openssl'
3
+ require 'uri'
4
+ require 'json'
5
+ require 'time'
6
+ require 'bigdecimal'
7
+
8
+ require 'vexapion/version'
9
+ require 'vexapion/errors/vexapion_errors'
10
+ require 'vexapion/errors/http_errors'
11
+ require 'vexapion/connect/http_client'
12
+ require 'vexapion/base_exchanges'
13
+
14
+ require 'vexapion/zaif'
15
+ require 'vexapion/bitflyer'
16
+ require 'vexapion/coincheck'
17
+ require 'vexapion/poloniex'
18
+
19
+ Net::HTTP.version_1_2
metadata ADDED
@@ -0,0 +1,111 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: vexapion
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.3.0
5
+ platform: ruby
6
+ authors:
7
+ - fuyuton
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2017-02-09 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bigdecimal
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 1.2.6
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: 1.2.6
27
+ - !ruby/object:Gem::Dependency
28
+ name: json
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.8'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.8'
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.12'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '1.12'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rake
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '10.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '10.0'
69
+ description: This is a low layer API wrapper for easy connection to exchanges.
70
+ email:
71
+ - fuyuton@pastelpink.sakura.ne.jp
72
+ executables: []
73
+ extensions: []
74
+ extra_rdoc_files: []
75
+ files:
76
+ - lib/vexapion.rb
77
+ - lib/vexapion/base_exchanges.rb
78
+ - lib/vexapion/bitflyer.rb
79
+ - lib/vexapion/coincheck.rb
80
+ - lib/vexapion/connect/http_client.rb
81
+ - lib/vexapion/errors/http_errors.rb
82
+ - lib/vexapion/errors/vexapion_errors.rb
83
+ - lib/vexapion/poloniex.rb
84
+ - lib/vexapion/version.rb
85
+ - lib/vexapion/zaif.rb
86
+ homepage: https://github.com/fuyuton/vexapion
87
+ licenses:
88
+ - MIT
89
+ metadata:
90
+ allowed_push_host: https://rubygems.org
91
+ post_install_message:
92
+ rdoc_options: []
93
+ require_paths:
94
+ - lib
95
+ required_ruby_version: !ruby/object:Gem::Requirement
96
+ requirements:
97
+ - - ">="
98
+ - !ruby/object:Gem::Version
99
+ version: '0'
100
+ required_rubygems_version: !ruby/object:Gem::Requirement
101
+ requirements:
102
+ - - ">="
103
+ - !ruby/object:Gem::Version
104
+ version: '0'
105
+ requirements: []
106
+ rubyforge_project:
107
+ rubygems_version: 2.6.4
108
+ signing_key:
109
+ specification_version: 4
110
+ summary: Virtual currency Exchanger API wrapper
111
+ test_files: []