ruby_bitbankcc 0.2.0 → 0.4.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 +4 -4
- data/.gitignore +1 -1
- data/README.md +5 -1
- data/lib/ruby_bitbankcc/bitbankcc.rb +67 -30
- data/lib/ruby_bitbankcc/version.rb +1 -1
- data/ruby_bitbankcc.gemspec +1 -1
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 80daeb203ba139fb2cf1723674361978d045670293f485d826d8d4f558e4e37c
|
4
|
+
data.tar.gz: e223f54406a30c5b7255c29b2880e948d4d315a2c0c2de2839559af407cd8a7e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 632f9db1759a3e0fc7842ce5c8c65a53a611dc8a3f1150c56e7e519c7b06ef6b342bcd6960eaf4c6d8a1bb6075757ae447a2028ad1ecf37ff7e9660570f7fa3d
|
7
|
+
data.tar.gz: 9923eecd68e50aff98247e6d32fc2cf5aad33c1c873f5f002c69643d800f1233e205ca8bcb3af3069a0b18028c97913f85b69d38db13d2b35497f170aca18436
|
data/.gitignore
CHANGED
data/README.md
CHANGED
@@ -24,7 +24,11 @@ Or install it yourself as:
|
|
24
24
|
#!/usr/bin/env ruby -Ilib
|
25
25
|
require 'ruby_bitbankcc'
|
26
26
|
|
27
|
-
|
27
|
+
# use request_time method
|
28
|
+
bbcc = Bitbankcc.new("YOUR API KEY", "YOUR SECRET KEY",params= {"auth_method"=> "request_time", "time_window"=> "5000"})
|
29
|
+
# use nonce method
|
30
|
+
bbcc = Bitbankcc.new("YOUR API KEY", "YOUR SECRET KEY",params= {"auth_method"=> "nonce"})
|
31
|
+
|
28
32
|
bbcc.read_transactions('btc_jpy')
|
29
33
|
bbcc.read_ticker('btc_jpy')
|
30
34
|
bbcc.read_order_books('btc_jpy')
|
@@ -10,6 +10,8 @@ require 'rest_client'
|
|
10
10
|
class Bitbankcc
|
11
11
|
@@base_url = "https://api.bitbank.cc"
|
12
12
|
@@base_public_url = "https://public.bitbank.cc"
|
13
|
+
@@auth_method = "request_time"
|
14
|
+
@@time_window = 5000
|
13
15
|
@@ssl = true
|
14
16
|
|
15
17
|
def initialize(key = nil, secret = nil, params = {})
|
@@ -18,6 +20,12 @@ class Bitbankcc
|
|
18
20
|
if !params[:base_url].nil?
|
19
21
|
@@base_url = params[:base_url]
|
20
22
|
end
|
23
|
+
if !params[:auth_method].nil?
|
24
|
+
@@auth_method = params[:auth_method]
|
25
|
+
end
|
26
|
+
if !params[:time_window].nil?
|
27
|
+
@@time_window = params[:time_window]
|
28
|
+
end
|
21
29
|
if !params[:ssl].nil?
|
22
30
|
@@ssl = params[:ssl]
|
23
31
|
end
|
@@ -25,13 +33,13 @@ class Bitbankcc
|
|
25
33
|
|
26
34
|
def read_balance
|
27
35
|
path = "/v1/user/assets"
|
28
|
-
nonce =
|
36
|
+
nonce = get_current_milisec
|
29
37
|
request_for_get(path, nonce)
|
30
38
|
end
|
31
39
|
|
32
40
|
def read_active_orders(pair, count = nil, from_id = nil, end_id = nil, since = nil, _end = nil)
|
33
41
|
path = "/v1/user/spot/active_orders"
|
34
|
-
nonce =
|
42
|
+
nonce = get_current_milisec
|
35
43
|
params = {
|
36
44
|
pair: pair,
|
37
45
|
count: count,
|
@@ -43,9 +51,15 @@ class Bitbankcc
|
|
43
51
|
request_for_get(path, nonce, params)
|
44
52
|
end
|
45
53
|
|
46
|
-
def
|
54
|
+
def read_margin_positions()
|
55
|
+
path = "/v1/user/margin/positions"
|
56
|
+
nonce = get_current_milisec
|
57
|
+
request_for_get(path, nonce)
|
58
|
+
end
|
59
|
+
|
60
|
+
def create_order(pair, amount, price, side, type, post_only = false, trigger_price = nil, position_side = nil)
|
47
61
|
path = "/v1/user/spot/order"
|
48
|
-
nonce =
|
62
|
+
nonce = get_current_milisec
|
49
63
|
body = {
|
50
64
|
pair: pair,
|
51
65
|
amount: amount,
|
@@ -53,14 +67,15 @@ class Bitbankcc
|
|
53
67
|
side: side,
|
54
68
|
type: type,
|
55
69
|
post_only: post_only,
|
56
|
-
trigger_price: trigger_price
|
70
|
+
trigger_price: trigger_price,
|
71
|
+
position_side: position_side
|
57
72
|
}.to_json
|
58
73
|
request_for_post(path, nonce, body)
|
59
74
|
end
|
60
75
|
|
61
76
|
def cancel_order(pair, order_id)
|
62
77
|
path = "/v1/user/spot/cancel_order"
|
63
|
-
nonce =
|
78
|
+
nonce = get_current_milisec
|
64
79
|
body = {
|
65
80
|
pair: pair,
|
66
81
|
order_id: order_id
|
@@ -70,7 +85,7 @@ class Bitbankcc
|
|
70
85
|
|
71
86
|
def read_trade_history(pair, count = nil, order_id = nil, since = nil, _end = nil, order = nil)
|
72
87
|
path = "/v1/user/spot/trade_history"
|
73
|
-
nonce =
|
88
|
+
nonce = get_current_milisec
|
74
89
|
params = {
|
75
90
|
pair: pair,
|
76
91
|
count: count,
|
@@ -85,7 +100,7 @@ class Bitbankcc
|
|
85
100
|
|
86
101
|
def read_deposit_history(asset, count = nil, since = nil, _end = nil, order = nil)
|
87
102
|
path = "/v1/user/deposit_history"
|
88
|
-
nonce =
|
103
|
+
nonce = get_current_milisec
|
89
104
|
params = {
|
90
105
|
asset: asset,
|
91
106
|
count: count,
|
@@ -99,7 +114,7 @@ class Bitbankcc
|
|
99
114
|
|
100
115
|
def read_withdrawal_account(asset)
|
101
116
|
path = "/v1/user/withdrawal_account"
|
102
|
-
nonce =
|
117
|
+
nonce = get_current_milisec
|
103
118
|
params = {
|
104
119
|
asset: asset
|
105
120
|
}.compact
|
@@ -109,7 +124,7 @@ class Bitbankcc
|
|
109
124
|
|
110
125
|
def request_withdrawal(asset, uuid, amount, otp_token = nil, sms_token = nil)
|
111
126
|
path = "/v1/user/request_withdrawal"
|
112
|
-
nonce =
|
127
|
+
nonce = get_current_milisec
|
113
128
|
body = {
|
114
129
|
asset: asset,
|
115
130
|
uuid: uuid,
|
@@ -122,7 +137,7 @@ class Bitbankcc
|
|
122
137
|
|
123
138
|
def read_withdrawal_history(asset, count = nil, since = nil, _end = nil, order = nil)
|
124
139
|
path = "/v1/user/withdrawal_history"
|
125
|
-
nonce =
|
140
|
+
nonce = get_current_milisec
|
126
141
|
params = {
|
127
142
|
asset: asset,
|
128
143
|
count: count,
|
@@ -166,17 +181,41 @@ class Bitbankcc
|
|
166
181
|
response.body
|
167
182
|
end
|
168
183
|
|
169
|
-
def request_for_get(path, nonce, query = {})
|
170
|
-
uri = URI.parse @@base_url + path
|
171
|
-
signature = get_get_signature(path, @secret, nonce, query)
|
172
184
|
|
185
|
+
def make_nonce_header(message, api_key, secret_key, nonce)
|
186
|
+
signature = get_signature(secret_key, message)
|
173
187
|
headers = {
|
174
188
|
"Content-Type" => "application/json",
|
175
|
-
"ACCESS-KEY" =>
|
189
|
+
"ACCESS-KEY" => api_key,
|
176
190
|
"ACCESS-NONCE" => nonce,
|
177
191
|
"ACCESS-SIGNATURE" => signature
|
178
192
|
}
|
193
|
+
end
|
194
|
+
|
195
|
+
def make_request_time_header(message, api_key, secret_key, request_time, time_window)
|
196
|
+
signature = get_signature(secret_key, message)
|
197
|
+
headers = {
|
198
|
+
"Content-Type" => "application/json",
|
199
|
+
"ACCESS-KEY" => api_key,
|
200
|
+
"ACCESS-REQUEST-TIME" => request_time,
|
201
|
+
"ACCESS-TIME-WINDOW" => time_window.to_s,
|
202
|
+
"ACCESS-SIGNATURE" => signature
|
203
|
+
}
|
204
|
+
end
|
179
205
|
|
206
|
+
def request_for_get(path, nonce, query = {})
|
207
|
+
uri = URI.parse @@base_url + path
|
208
|
+
query_string = query.present? ? '?' + query.to_query : ''
|
209
|
+
if @@auth_method == "request_time"
|
210
|
+
request_time = get_current_milisec
|
211
|
+
message = request_time + @@time_window.to_s + path + query_string
|
212
|
+
headers = make_request_time_header(message, @key, @secret, request_time, @@time_window)
|
213
|
+
else
|
214
|
+
nonce = get_current_milisec
|
215
|
+
headers = make_nonce_header(path,nonce)
|
216
|
+
message = nonce + path + query_string
|
217
|
+
headers = make_nonce_header(message, @key, @secret, nonce)
|
218
|
+
end
|
180
219
|
uri.query = query.to_query
|
181
220
|
request = Net::HTTP::Get.new(uri.request_uri, initheader = headers)
|
182
221
|
http_request(uri, request)
|
@@ -184,15 +223,16 @@ class Bitbankcc
|
|
184
223
|
|
185
224
|
def request_for_post(path, nonce, body)
|
186
225
|
uri = URI.parse @@base_url + path
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
226
|
+
if @@auth_method == "request_time"
|
227
|
+
request_time = get_current_milisec
|
228
|
+
message = request_time + @@time_window.to_s + body
|
229
|
+
headers = make_request_time_header(message, @key, @secret, request_time, @@time_window)
|
230
|
+
else
|
231
|
+
nonce = get_current_milisec
|
232
|
+
headers = make_nonce_header(path,nonce)
|
233
|
+
message = nonce + body
|
234
|
+
headers = make_nonce_header(message, @key, @secret, nonce)
|
235
|
+
end
|
196
236
|
|
197
237
|
request = Net::HTTP::Post.new(uri.request_uri, initheader = headers)
|
198
238
|
request.body = body
|
@@ -200,14 +240,11 @@ class Bitbankcc
|
|
200
240
|
http_request(uri, request)
|
201
241
|
end
|
202
242
|
|
203
|
-
def
|
204
|
-
|
205
|
-
message = nonce + path + query_string
|
206
|
-
signature = OpenSSL::HMAC.hexdigest(OpenSSL::Digest.new("sha256"), secret_key, message)
|
243
|
+
def get_current_milisec
|
244
|
+
(Time.now.to_f * 1000.0).to_i.to_s
|
207
245
|
end
|
208
246
|
|
209
|
-
def
|
210
|
-
message = nonce + body
|
247
|
+
def get_signature(secret_key, message)
|
211
248
|
signature = OpenSSL::HMAC.hexdigest(OpenSSL::Digest.new("sha256"), secret_key, message)
|
212
249
|
end
|
213
250
|
end
|
data/ruby_bitbankcc.gemspec
CHANGED
@@ -27,7 +27,7 @@ Gem::Specification.new do |spec|
|
|
27
27
|
|
28
28
|
spec.add_dependency "activesupport"
|
29
29
|
spec.add_dependency "rest-client"
|
30
|
-
spec.add_development_dependency "bundler", "~>
|
30
|
+
spec.add_development_dependency "bundler", "~> 2.4"
|
31
31
|
spec.add_development_dependency "rake", "~> 10.0"
|
32
32
|
spec.add_development_dependency "rspec"
|
33
33
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ruby_bitbankcc
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- bitbankcc
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2025-03-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -44,14 +44,14 @@ dependencies:
|
|
44
44
|
requirements:
|
45
45
|
- - "~>"
|
46
46
|
- !ruby/object:Gem::Version
|
47
|
-
version: '
|
47
|
+
version: '2.4'
|
48
48
|
type: :development
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
52
|
- - "~>"
|
53
53
|
- !ruby/object:Gem::Version
|
54
|
-
version: '
|
54
|
+
version: '2.4'
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
56
|
name: rake
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|