bitopro 1.0.3 → 1.0.4
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/lib/bitopro/api/account.rb +5 -1
- data/lib/bitopro/client.rb +27 -56
- data/lib/bitopro/version.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1e5c53c96852494993e32b2148fe51924f5ab735724cc397a22ec6167b31bb07
|
4
|
+
data.tar.gz: befe9c38587c12d2704471ca03d731c2d5e54bd931edd47a1eff7ed05ccf3e82
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: da5bf8178cefc5ad31ce79cfc4d8081121df3e4273908ace9823e6618b9319cf010a352aa10c438be019894b82f730f68e7f5644f911dd0bb81933a5b472af10
|
7
|
+
data.tar.gz: d3d93dbddbc92db71d5e6ad68bc7b7d82c8e394eff030acc506ef00d73e82910d7e1263b6ea9df61c27eda5fc7900f4101de592828ce2aa76c652239f46b261d
|
data/lib/bitopro/api/account.rb
CHANGED
@@ -1,5 +1,7 @@
|
|
1
1
|
module Bitopro
|
2
2
|
module Account
|
3
|
+
class Error < StandardError; end
|
4
|
+
|
3
5
|
def account_balance
|
4
6
|
authenticated_get("/accounts/balance")
|
5
7
|
end
|
@@ -9,7 +11,9 @@ module Bitopro
|
|
9
11
|
end
|
10
12
|
|
11
13
|
def order_list(pair: "", page: 1, active: false)
|
12
|
-
|
14
|
+
raise Error, "pair is required" unless pair
|
15
|
+
|
16
|
+
authenticated_get("/orders/#{pair}", params: { page: page, active: active })
|
13
17
|
end
|
14
18
|
end
|
15
19
|
end
|
data/lib/bitopro/client.rb
CHANGED
@@ -6,6 +6,7 @@ module Bitopro
|
|
6
6
|
class Client
|
7
7
|
class SetupError < StandardError; end
|
8
8
|
|
9
|
+
AUTH_HTTP_ACTION = %w(get post delete)
|
9
10
|
BASE_URL = "https://api.bitopro.com/v2".freeze
|
10
11
|
|
11
12
|
include Bitopro::Public
|
@@ -18,71 +19,33 @@ module Bitopro
|
|
18
19
|
|
19
20
|
private
|
20
21
|
|
21
|
-
def
|
22
|
+
def complete_url(url)
|
22
23
|
"#{BASE_URL}#{url}"
|
23
24
|
end
|
24
25
|
|
25
|
-
|
26
|
-
|
26
|
+
AUTH_HTTP_ACTION.each do |action|
|
27
|
+
define_method "authenticated_#{action}" do |url, params = {}|
|
28
|
+
raise SetupError, "Must be set configure before call authenticate action" unless Bitopro.configured?
|
27
29
|
|
28
|
-
|
30
|
+
json_body = build_json_body(params: params, action: action)
|
31
|
+
payload = build_payload(json_body)
|
32
|
+
headers = build_headers(payload)
|
29
33
|
|
30
|
-
|
31
|
-
|
32
|
-
|
34
|
+
response = RestClient::Request.execute(method: action,
|
35
|
+
url: complete_url(url),
|
36
|
+
headers: headers,
|
37
|
+
payload: params,
|
38
|
+
timeout: 10)
|
33
39
|
|
34
|
-
|
35
|
-
|
36
|
-
headers: headers,
|
37
|
-
payload: params,
|
38
|
-
timeout: 10)
|
39
|
-
|
40
|
-
JSON.parse(response.body)
|
41
|
-
end
|
42
|
-
|
43
|
-
def authenticated_post(url, params = {})
|
44
|
-
raise SetupError, "Must be set configure before call authenticate action" unless Bitopro.configured?
|
45
|
-
|
46
|
-
complete_url = build_url(url)
|
47
|
-
|
48
|
-
json_body = params[:body].to_json
|
49
|
-
payload = build_payload(json_body)
|
50
|
-
headers = build_headers(payload)
|
51
|
-
|
52
|
-
response = RestClient::Request.execute(method: :post,
|
53
|
-
url: complete_url,
|
54
|
-
headers: headers,
|
55
|
-
payload: json_body,
|
56
|
-
timeout: 10)
|
57
|
-
|
58
|
-
JSON.parse(response.body)
|
59
|
-
end
|
60
|
-
|
61
|
-
def authenticated_delete(url, params = {})
|
62
|
-
raise BitoproSetupError, "Must be set configure before call authenticate action" unless Bitopro.configured?
|
63
|
-
|
64
|
-
complete_url = build_url(url)
|
65
|
-
|
66
|
-
json_body = { identity: @config.email, nonce: timestamp }.to_json
|
67
|
-
payload = build_payload(json_body)
|
68
|
-
headers = build_headers(payload)
|
69
|
-
|
70
|
-
response = RestClient::Request.execute(method: :delete,
|
71
|
-
url: complete_url,
|
72
|
-
headers: headers,
|
73
|
-
payload: params,
|
74
|
-
timeout: 10)
|
75
|
-
|
76
|
-
JSON.parse(response.body)
|
40
|
+
JSON.parse(response.body)
|
41
|
+
end
|
77
42
|
end
|
78
43
|
|
79
44
|
def get(url, params = {})
|
80
|
-
complete_url = build_url(url)
|
81
|
-
headers = { "X-BITOPRO-API": "ruby" }
|
82
45
|
response = RestClient::Request.execute(method: :get,
|
83
|
-
url: complete_url,
|
46
|
+
url: complete_url(url),
|
84
47
|
payload: params,
|
85
|
-
headers:
|
48
|
+
headers: tracking_header,
|
86
49
|
timeout: 10)
|
87
50
|
|
88
51
|
JSON.parse(response.body)
|
@@ -92,6 +55,11 @@ module Bitopro
|
|
92
55
|
Base64.strict_encode64(json_body)
|
93
56
|
end
|
94
57
|
|
58
|
+
def build_json_body(params:, action:)
|
59
|
+
body = action == "post" ? params[:body] : { identity: @config.email, nonce: timestamp }
|
60
|
+
body.to_json
|
61
|
+
end
|
62
|
+
|
95
63
|
def timestamp
|
96
64
|
(Time.now.to_f * 1000).floor
|
97
65
|
end
|
@@ -100,13 +68,16 @@ module Bitopro
|
|
100
68
|
OpenSSL::HMAC.hexdigest("SHA384", @config.secret, payload)
|
101
69
|
end
|
102
70
|
|
71
|
+
def tracking_header
|
72
|
+
{ "X-BITOPRO-API": "ruby" }
|
73
|
+
end
|
74
|
+
|
103
75
|
def build_headers(payload)
|
104
76
|
{
|
105
|
-
"X-BITOPRO-API": "ruby",
|
106
77
|
"X-BITOPRO-APIKEY": @config.key,
|
107
78
|
"X-BITOPRO-PAYLOAD": payload,
|
108
79
|
"X-BITOPRO-SIGNATURE": signature(payload)
|
109
|
-
}
|
80
|
+
}.merge!(tracking_header)
|
110
81
|
end
|
111
82
|
end
|
112
83
|
end
|
data/lib/bitopro/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: bitopro
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- niclin
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-05-
|
11
|
+
date: 2019-05-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -141,7 +141,7 @@ rubyforge_project:
|
|
141
141
|
rubygems_version: 2.7.8
|
142
142
|
signing_key:
|
143
143
|
specification_version: 4
|
144
|
-
summary: bitopro-1.0.
|
144
|
+
summary: bitopro-1.0.4
|
145
145
|
test_files:
|
146
146
|
- spec/spec_helper.rb
|
147
147
|
- spec/bitopro/config_spec.rb
|