honeymaker 0.12.1 → 0.12.3
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:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 2306f41b9132fa6da84591b6ec38ca160a3fd052ef74a0893d3c27f01f64e8f3
|
|
4
|
+
data.tar.gz: 40bb6abacd74cfbd7fded2bb0d560700be9be0bf29c4fbf2aa7ab725d816a294
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 326a5af73ef2f8564dda06d0d6f82a3f873d5b05f725d579666ccbb1df42a74603221904190972ac8b7b7fbe74d673898f1bc5e08da799655fd11d3959dfc1a6
|
|
7
|
+
data.tar.gz: 1c24efe089db21b89d7c24bd563da3841f5cfd3899c339d5524a3c55970245632bcdf8c36b2f060bbae6bc50e8a2f7e918c87684ba9e7e2e91002cdabf14c31e
|
|
@@ -168,7 +168,8 @@ module Honeymaker
|
|
|
168
168
|
with_rescue do
|
|
169
169
|
payload = body.compact.merge(request: path, nonce: timestamp_ms.to_s)
|
|
170
170
|
encoded_payload = Base64.strict_encode64(payload.to_json)
|
|
171
|
-
|
|
171
|
+
# HMAC-SHA384, not SHA256: https://developer.gemini.com/authentication/api-key
|
|
172
|
+
signature = OpenSSL::HMAC.hexdigest("sha384", @api_secret, encoded_payload)
|
|
172
173
|
|
|
173
174
|
response = connection.post do |req|
|
|
174
175
|
req.url path
|
|
@@ -7,6 +7,7 @@ module Honeymaker
|
|
|
7
7
|
module Clients
|
|
8
8
|
class Kraken < Client
|
|
9
9
|
URL = "https://api.kraken.com"
|
|
10
|
+
UNREADABLE = "Kraken: unreadable response"
|
|
10
11
|
|
|
11
12
|
RATE_LIMITS = { default: 1000, orders: 1000 }.freeze
|
|
12
13
|
|
|
@@ -23,6 +24,7 @@ module Honeymaker
|
|
|
23
24
|
txid: txid, consolidate_taker: consolidate_taker
|
|
24
25
|
})
|
|
25
26
|
return result if result.failure?
|
|
27
|
+
return unreadable unless result.data.is_a?(Hash)
|
|
26
28
|
|
|
27
29
|
errors = result.data["error"]
|
|
28
30
|
return Result::Failure.new(*errors) if errors.is_a?(Array) && errors.any?
|
|
@@ -53,6 +55,7 @@ module Honeymaker
|
|
|
53
55
|
"deadline" => deadline, "validate" => validate
|
|
54
56
|
})
|
|
55
57
|
return result if result.failure?
|
|
58
|
+
return unreadable unless result.data.is_a?(Hash)
|
|
56
59
|
|
|
57
60
|
errors = result.data["error"]
|
|
58
61
|
return Result::Failure.new(*errors) if errors.is_a?(Array) && errors.any?
|
|
@@ -96,6 +99,7 @@ module Honeymaker
|
|
|
96
99
|
def get_balances
|
|
97
100
|
result = get_extended_balance
|
|
98
101
|
return result if result.failure?
|
|
102
|
+
return unreadable unless result.data.is_a?(Hash)
|
|
99
103
|
|
|
100
104
|
errors = result.data["error"]
|
|
101
105
|
return Result::Failure.new(*errors) if errors.is_a?(Array) && errors.any?
|
|
@@ -149,6 +153,7 @@ module Honeymaker
|
|
|
149
153
|
loop do
|
|
150
154
|
result = get_trades_history(start: start, ofs: offset)
|
|
151
155
|
return result if result.failure?
|
|
156
|
+
return unreadable unless result.data.is_a?(Hash)
|
|
152
157
|
|
|
153
158
|
errors = result.data["error"]
|
|
154
159
|
return Result::Failure.new(*errors) if errors.is_a?(Array) && errors.any?
|
|
@@ -196,6 +201,12 @@ module Honeymaker
|
|
|
196
201
|
|
|
197
202
|
private
|
|
198
203
|
|
|
204
|
+
# A 2xx body that isn't a JSON object (a maintenance page, "null"): the venue's answer is
|
|
205
|
+
# unknown, which is not the same as empty. Callers treat data[:unreadable] as ambiguous.
|
|
206
|
+
def unreadable
|
|
207
|
+
Result::Failure.new(UNREADABLE, data: { unreadable: true })
|
|
208
|
+
end
|
|
209
|
+
|
|
199
210
|
def aggregate_trades(trades)
|
|
200
211
|
first = trades.first
|
|
201
212
|
vol = trades.sum { |t| BigDecimal(t["vol"].to_s) }
|
data/lib/honeymaker/version.rb
CHANGED
|
@@ -72,6 +72,23 @@ class Honeymaker::Clients::GeminiTest < Minitest::Test
|
|
|
72
72
|
assert result.success?
|
|
73
73
|
end
|
|
74
74
|
|
|
75
|
+
# Gemini signs with HMAC-SHA384 of the base64 payload
|
|
76
|
+
# (https://developer.gemini.com/authentication/api-key); any other digest is rejected.
|
|
77
|
+
def test_private_requests_are_signed_with_hmac_sha384
|
|
78
|
+
request = Struct.new(:headers) { def url(_path) = nil }.new
|
|
79
|
+
connection = Object.new
|
|
80
|
+
connection.define_singleton_method(:post) do |&block|
|
|
81
|
+
block.call(request)
|
|
82
|
+
Struct.new(:body).new({})
|
|
83
|
+
end
|
|
84
|
+
@client.instance_variable_set(:@connection, connection)
|
|
85
|
+
|
|
86
|
+
@client.get_balances
|
|
87
|
+
|
|
88
|
+
payload = request.headers[:"X-GEMINI-PAYLOAD"]
|
|
89
|
+
assert_equal OpenSSL::HMAC.hexdigest("sha384", "test_secret", payload), request.headers[:"X-GEMINI-SIGNATURE"]
|
|
90
|
+
end
|
|
91
|
+
|
|
75
92
|
private
|
|
76
93
|
|
|
77
94
|
def stub_connection(method, body)
|
|
@@ -15,6 +15,18 @@ class Honeymaker::Clients::KrakenTest < Minitest::Test
|
|
|
15
15
|
assert_equal "https://api.kraken.com", Honeymaker::Clients::Kraken::URL
|
|
16
16
|
end
|
|
17
17
|
|
|
18
|
+
def test_non_object_2xx_is_unreadable_not_empty
|
|
19
|
+
[["<html>maintenance</html>", ->(c) { c.get_balances }],
|
|
20
|
+
[nil, ->(c) { c.query_orders_info(txid: "O1") }],
|
|
21
|
+
["oops", ->(c) { c.add_order(ordertype: "market", type: "buy", volume: "1", pair: "XBTUSD") }],
|
|
22
|
+
["oops", ->(c) { c.closed_orders_from_trades(order_ids: ["O1"]) }]].each do |body, call|
|
|
23
|
+
stub_connection(:post, body)
|
|
24
|
+
r = call.call(@client)
|
|
25
|
+
assert_equal ["Kraken: unreadable response"], r.errors
|
|
26
|
+
assert_equal({ unreadable: true }, r.data)
|
|
27
|
+
end
|
|
28
|
+
end
|
|
29
|
+
|
|
18
30
|
def test_get_tradable_asset_pairs
|
|
19
31
|
stub_connection(:get, { "error" => [], "result" => { "XBTUSDT" => { "altname" => "XBTUSDT" } } })
|
|
20
32
|
result = @client.get_tradable_asset_pairs
|