ruby_bitbankcc 0.1.6 → 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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: f9a92121911729ddaffa33095532d9c990ce22786330fe58784297a16d225f03
4
- data.tar.gz: 22c8b68300550ce0883725daa22d05829a8b29191e54b634374eaf6006d60979
3
+ metadata.gz: f7600ab250d91c97a36cb6fb33ce10b11ef6db5d43271c9368d31a76b13417ba
4
+ data.tar.gz: daed140199c98dfff1ece9c79f95203bba5fc09c044a826acacb744c0247c706
5
5
  SHA512:
6
- metadata.gz: 68dd7a72133b30e96b4a0697f11f212ecffebc08aa5129a204acae7cce2ea3cf26e636cb29807c007a8a6d52091fd19504b6304b554eeb611074268de8be9ca5
7
- data.tar.gz: 57ae42d1ffe49406ced5c16a7cace67a99ead5bf0a251d368549309649a813b28e40df379ef99cee6bc41d3b4bb0d0e4de6f69f7035d24441753c5d1cc1ef2ba
6
+ metadata.gz: 566991b0d4c5cfb4e44a17d07b64ee61947ea97efdc0556ac41d1a6d26c45f1d372efa7618d4c262bf0d58dfd05fac57ba3e9a86dff134579b8e12acd33620a8
7
+ data.tar.gz: 364d1d38bff1f39cb245f4a5d0992eab9a6c3203676f512c46e26428a88a6f9eb16a384cdc0acee051b60f6fbe063899c04817f57844b3875c05ebaf9a14697e
data/README.md CHANGED
@@ -24,11 +24,16 @@ Or install it yourself as:
24
24
  #!/usr/bin/env ruby -Ilib
25
25
  require 'ruby_bitbankcc'
26
26
 
27
- bbcc = Bitbankcc.new("YOUR API KEY", "YOUR SECRET KEY")
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')
31
35
  bbcc.read_balance()
36
+ bbcc.read_circuit_break_info('btc_jpy')
32
37
  bbcc.read_active_orders('btc_jpy')
33
38
  # you can omit last post_only (omit means false)
34
39
  bbcc.create_order('btc_jpy', "0.001", 130000, 'buy', 'limit', false)
@@ -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 = Time.now.to_i.to_s
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 = Time.now.to_i.to_s
42
+ nonce = get_current_milisec
35
43
  params = {
36
44
  pair: pair,
37
45
  count: count,
@@ -45,7 +53,7 @@ class Bitbankcc
45
53
 
46
54
  def create_order(pair, amount, price, side, type, post_only = false, trigger_price = nil)
47
55
  path = "/v1/user/spot/order"
48
- nonce = Time.now.to_i.to_s
56
+ nonce = get_current_milisec
49
57
  body = {
50
58
  pair: pair,
51
59
  amount: amount,
@@ -60,7 +68,7 @@ class Bitbankcc
60
68
 
61
69
  def cancel_order(pair, order_id)
62
70
  path = "/v1/user/spot/cancel_order"
63
- nonce = Time.now.to_i.to_s
71
+ nonce = get_current_milisec
64
72
  body = {
65
73
  pair: pair,
66
74
  order_id: order_id
@@ -70,7 +78,7 @@ class Bitbankcc
70
78
 
71
79
  def read_trade_history(pair, count = nil, order_id = nil, since = nil, _end = nil, order = nil)
72
80
  path = "/v1/user/spot/trade_history"
73
- nonce = Time.now.to_i.to_s
81
+ nonce = get_current_milisec
74
82
  params = {
75
83
  pair: pair,
76
84
  count: count,
@@ -85,7 +93,7 @@ class Bitbankcc
85
93
 
86
94
  def read_deposit_history(asset, count = nil, since = nil, _end = nil, order = nil)
87
95
  path = "/v1/user/deposit_history"
88
- nonce = Time.now.to_i.to_s
96
+ nonce = get_current_milisec
89
97
  params = {
90
98
  asset: asset,
91
99
  count: count,
@@ -99,7 +107,7 @@ class Bitbankcc
99
107
 
100
108
  def read_withdrawal_account(asset)
101
109
  path = "/v1/user/withdrawal_account"
102
- nonce = Time.now.to_i.to_s
110
+ nonce = get_current_milisec
103
111
  params = {
104
112
  asset: asset
105
113
  }.compact
@@ -109,7 +117,7 @@ class Bitbankcc
109
117
 
110
118
  def request_withdrawal(asset, uuid, amount, otp_token = nil, sms_token = nil)
111
119
  path = "/v1/user/request_withdrawal"
112
- nonce = Time.now.to_i.to_s
120
+ nonce = get_current_milisec
113
121
  body = {
114
122
  asset: asset,
115
123
  uuid: uuid,
@@ -122,7 +130,7 @@ class Bitbankcc
122
130
 
123
131
  def read_withdrawal_history(asset, count = nil, since = nil, _end = nil, order = nil)
124
132
  path = "/v1/user/withdrawal_history"
125
- nonce = Time.now.to_i.to_s
133
+ nonce = get_current_milisec
126
134
  params = {
127
135
  asset: asset,
128
136
  count: count,
@@ -146,6 +154,10 @@ class Bitbankcc
146
154
  RestClient.get @@base_public_url + "/#{pair}/transactions" + (date.empty? ? '' : '/' + date)
147
155
  end
148
156
 
157
+ def read_circuit_break_info(pair)
158
+ RestClient.get @@base_public_url + "/#{pair}/circuit_break_info"
159
+ end
160
+
149
161
  private
150
162
  def http_request(uri, request)
151
163
  https = Net::HTTP.new(uri.host, uri.port)
@@ -162,17 +174,41 @@ class Bitbankcc
162
174
  response.body
163
175
  end
164
176
 
165
- def request_for_get(path, nonce, query = {})
166
- uri = URI.parse @@base_url + path
167
- signature = get_get_signature(path, @secret, nonce, query)
168
177
 
178
+ def make_nonce_header(message, api_key, secret_key, nonce)
179
+ signature = get_signature(secret_key, message)
169
180
  headers = {
170
181
  "Content-Type" => "application/json",
171
- "ACCESS-KEY" => @key,
182
+ "ACCESS-KEY" => api_key,
172
183
  "ACCESS-NONCE" => nonce,
173
184
  "ACCESS-SIGNATURE" => signature
174
185
  }
186
+ end
187
+
188
+ def make_request_time_header(message, api_key, secret_key, request_time, time_window)
189
+ signature = get_signature(secret_key, message)
190
+ headers = {
191
+ "Content-Type" => "application/json",
192
+ "ACCESS-KEY" => api_key,
193
+ "ACCESS-REQUEST-TIME" => request_time,
194
+ "ACCESS-TIME-WINDOW" => time_window.to_s,
195
+ "ACCESS-SIGNATURE" => signature
196
+ }
197
+ end
175
198
 
199
+ def request_for_get(path, nonce, query = {})
200
+ uri = URI.parse @@base_url + path
201
+ query_string = query.present? ? '?' + query.to_query : ''
202
+ if @@auth_method == "request_time"
203
+ request_time = get_current_milisec
204
+ message = request_time + @@time_window.to_s + path + query_string
205
+ headers = make_request_time_header(message, @key, @secret, request_time, @@time_window)
206
+ else
207
+ nonce = get_current_milisec
208
+ headers = make_nonce_header(path,nonce)
209
+ message = nonce + path + query_string
210
+ headers = make_nonce_header(message, @key, @secret, nonce)
211
+ end
176
212
  uri.query = query.to_query
177
213
  request = Net::HTTP::Get.new(uri.request_uri, initheader = headers)
178
214
  http_request(uri, request)
@@ -180,15 +216,16 @@ class Bitbankcc
180
216
 
181
217
  def request_for_post(path, nonce, body)
182
218
  uri = URI.parse @@base_url + path
183
- signature = get_post_signature(@secret, nonce, body)
184
-
185
- headers = {
186
- "Content-Type" => "application/json",
187
- "ACCESS-KEY" => @key,
188
- "ACCESS-NONCE" => nonce,
189
- "ACCESS-SIGNATURE" => signature,
190
- "ACCEPT" => "application/json"
191
- }
219
+ if @@auth_method == "request_time"
220
+ request_time = get_current_milisec
221
+ message = request_time + @@time_window.to_s + body
222
+ headers = make_request_time_header(message, @key, @secret, request_time, @@time_window)
223
+ else
224
+ nonce = get_current_milisec
225
+ headers = make_nonce_header(path,nonce)
226
+ message = nonce + body
227
+ headers = make_nonce_header(message, @key, @secret, nonce)
228
+ end
192
229
 
193
230
  request = Net::HTTP::Post.new(uri.request_uri, initheader = headers)
194
231
  request.body = body
@@ -196,14 +233,11 @@ class Bitbankcc
196
233
  http_request(uri, request)
197
234
  end
198
235
 
199
- def get_get_signature(path, secret_key, nonce, query = {})
200
- query_string = query.present? ? '?' + query.to_query : ''
201
- message = nonce + path + query_string
202
- signature = OpenSSL::HMAC.hexdigest(OpenSSL::Digest.new("sha256"), secret_key, message)
236
+ def get_current_milisec
237
+ (Time.now.to_f * 1000.0).to_i.to_s
203
238
  end
204
239
 
205
- def get_post_signature(secret_key, nonce, body = "")
206
- message = nonce + body
240
+ def get_signature(secret_key, message)
207
241
  signature = OpenSSL::HMAC.hexdigest(OpenSSL::Digest.new("sha256"), secret_key, message)
208
242
  end
209
243
  end
@@ -1,3 +1,3 @@
1
1
  module RubyBitbankcc
2
- VERSION = "0.1.6"
2
+ VERSION = "0.3.0"
3
3
  end
@@ -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", "~> 1.9"
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.1.6
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - bitbankcc
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2023-02-13 00:00:00.000000000 Z
11
+ date: 2024-12-06 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: '1.9'
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: '1.9'
54
+ version: '2.4'
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: rake
57
57
  requirement: !ruby/object:Gem::Requirement
@@ -116,7 +116,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
116
116
  - !ruby/object:Gem::Version
117
117
  version: '0'
118
118
  requirements: []
119
- rubygems_version: 3.0.3
119
+ rubygems_version: 3.5.18
120
120
  signing_key:
121
121
  specification_version: 4
122
122
  summary: This is ruby client of bitbankcc api