honeymaker 0.11.4 → 0.11.5
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: d279d1416ac845778e5bf48218fbacf23498cae10bc1ed589cae28752aa4af8c
|
|
4
|
+
data.tar.gz: 2aebe8b36d740f1c09bb9ecf21ab205b911f6ce11fc41b0a7bc80898602d016f
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: ae37fa13ff7ce2db5366a408a4d006f671fcbda1c8931c8bca9c8df8a3c13c1256101a73b364bbffc58971923090d5dd8b0e44b49fdc35f73a0ecee8979f67b6
|
|
7
|
+
data.tar.gz: 0a00d2949aeba2b30b681a8021b59083de3498d201446e70ba88e1c2ccfa135f6137036620559f1e79cc2f216328639a3bf61d47f1082fa73040aa60389967c0
|
|
@@ -130,13 +130,13 @@ module Honeymaker
|
|
|
130
130
|
# --- Trading (requires hyperliquid-rb gem) ---
|
|
131
131
|
|
|
132
132
|
def order(coin:, is_buy:, size:, limit_px:, order_type: { limit: { tif: "Gtc" } })
|
|
133
|
-
|
|
133
|
+
with_status_rescue do
|
|
134
134
|
exchange_client.order(coin, is_buy: is_buy, sz: size, limit_px: limit_px, order_type: order_type)
|
|
135
135
|
end
|
|
136
136
|
end
|
|
137
137
|
|
|
138
138
|
def cancel(coin:, oid:)
|
|
139
|
-
|
|
139
|
+
with_status_rescue do
|
|
140
140
|
exchange_client.cancel(coin, oid)
|
|
141
141
|
end
|
|
142
142
|
end
|
|
@@ -157,6 +157,28 @@ module Honeymaker
|
|
|
157
157
|
|
|
158
158
|
private
|
|
159
159
|
|
|
160
|
+
# Trading does not go over this client's Faraday connection: it goes through hyperliquid-rb,
|
|
161
|
+
# which raises its own error for every non-2xx instead of answering. Client#with_rescue can
|
|
162
|
+
# only see an unlabelled StandardError there, so it flags it `client_error` — "no clean
|
|
163
|
+
# answer" — and a caller reading an order placement has to treat that as a request whose fate
|
|
164
|
+
# is unknown: nothing recorded as rejected, no retry, a line for a human to reconcile against
|
|
165
|
+
# the venue. But the status is right there on the exception, and it is exactly what tells a
|
|
166
|
+
# refusal (4xx — the gateway answered, nothing reached the matching engine) from a request the
|
|
167
|
+
# venue may still have taken (5xx). Hand it back in the same shape every other HTTP failure
|
|
168
|
+
# has, so one classifier covers both paths.
|
|
169
|
+
#
|
|
170
|
+
# Duck-typed on purpose: hyperliquid-rb is an optional dependency loaded only when trading is
|
|
171
|
+
# used, so its error classes cannot be named here. Anything without a status is classified
|
|
172
|
+
# exactly as it is everywhere else.
|
|
173
|
+
def with_status_rescue
|
|
174
|
+
Result::Success.new(yield)
|
|
175
|
+
rescue StandardError => e
|
|
176
|
+
status = e.respond_to?(:status) ? e.status.to_i : 0
|
|
177
|
+
return with_rescue { raise e } unless status.positive?
|
|
178
|
+
|
|
179
|
+
Result::Failure.new(e.message.to_s.empty? ? e.class.to_s : e.message, data: { status: status })
|
|
180
|
+
end
|
|
181
|
+
|
|
160
182
|
# Suffix-aware so the whole Hyperliquid cancel family (marginCanceled, scheduledCancel,
|
|
161
183
|
# reduceOnlyCanceled, siblingFilledCanceled, …) maps correctly. A triggered order has fired
|
|
162
184
|
# and become a live resting order → :open. An unmapped status is logged, never swallowed.
|
data/lib/honeymaker/version.rb
CHANGED
|
@@ -190,6 +190,76 @@ class Honeymaker::Clients::HyperliquidTest < Minitest::Test
|
|
|
190
190
|
assert result.success?
|
|
191
191
|
end
|
|
192
192
|
|
|
193
|
+
# == Raised trading errors keep their HTTP status ==
|
|
194
|
+
#
|
|
195
|
+
# Order placement goes through hyperliquid-rb, which raises instead of answering. Whether the
|
|
196
|
+
# venue REFUSED the request or may have TAKEN it is the whole question for a caller deciding
|
|
197
|
+
# between "record a rejected order" and "a human has to go and look" — and the status is the only
|
|
198
|
+
# thing that answers it. It must survive the trip.
|
|
199
|
+
|
|
200
|
+
# hyperliquid-rb's ClientError/ServerError shape. Rebuilt here because the gem is an optional
|
|
201
|
+
# dependency this one does not carry.
|
|
202
|
+
class RaisedWithStatus < StandardError
|
|
203
|
+
attr_reader :status
|
|
204
|
+
|
|
205
|
+
def initialize(message, status:)
|
|
206
|
+
@status = status
|
|
207
|
+
super(message)
|
|
208
|
+
end
|
|
209
|
+
end
|
|
210
|
+
|
|
211
|
+
def test_order_reports_a_refusal_with_its_status
|
|
212
|
+
@client.stubs(:exchange_client).raises(RaisedWithStatus.new("HTTP 429: rate limited", status: 429))
|
|
213
|
+
|
|
214
|
+
result = @client.order(coin: "@142", is_buy: true, size: 1, limit_px: 100)
|
|
215
|
+
|
|
216
|
+
assert result.failure?
|
|
217
|
+
assert_equal 429, result.data[:status]
|
|
218
|
+
assert_nil result.data[:client_error], "the venue answered — this is not an unknown outcome"
|
|
219
|
+
assert_equal ["HTTP 429: rate limited"], result.errors
|
|
220
|
+
end
|
|
221
|
+
|
|
222
|
+
# 5xx stays 5xx: a gateway that may have passed the order on is exactly the case a caller must
|
|
223
|
+
# keep treating as unresolved.
|
|
224
|
+
def test_order_reports_a_gateway_failure_with_its_status
|
|
225
|
+
@client.stubs(:exchange_client).raises(RaisedWithStatus.new("HTTP 502: bad gateway", status: 502))
|
|
226
|
+
|
|
227
|
+
result = @client.order(coin: "@142", is_buy: true, size: 1, limit_px: 100)
|
|
228
|
+
|
|
229
|
+
assert result.failure?
|
|
230
|
+
assert_equal 502, result.data[:status]
|
|
231
|
+
end
|
|
232
|
+
|
|
233
|
+
def test_cancel_reports_a_refusal_with_its_status
|
|
234
|
+
@client.stubs(:exchange_client).raises(RaisedWithStatus.new("HTTP 422: unknown oid", status: 422))
|
|
235
|
+
|
|
236
|
+
result = @client.cancel(coin: "@142", oid: 1)
|
|
237
|
+
|
|
238
|
+
assert result.failure?
|
|
239
|
+
assert_equal 422, result.data[:status]
|
|
240
|
+
end
|
|
241
|
+
|
|
242
|
+
# Everything the venue did not answer is untouched: a signing crash inside the gem, a network
|
|
243
|
+
# failure, a bug here. Those stay flagged as ours and unclassifiable.
|
|
244
|
+
def test_order_leaves_a_statusless_error_classified_as_before
|
|
245
|
+
@client.stubs(:exchange_client).raises(TypeError, "String can't be coerced into Float")
|
|
246
|
+
|
|
247
|
+
result = @client.order(coin: "@142", is_buy: true, size: 1, limit_px: 100)
|
|
248
|
+
|
|
249
|
+
assert result.failure?
|
|
250
|
+
assert result.data[:client_error], "no status means no answer from the venue"
|
|
251
|
+
assert_equal ["TypeError: String can't be coerced into Float"], result.errors
|
|
252
|
+
end
|
|
253
|
+
|
|
254
|
+
def test_order_wraps_an_accepted_placement
|
|
255
|
+
@client.stubs(:exchange_client).returns(stub(order: { "status" => "ok" }))
|
|
256
|
+
|
|
257
|
+
result = @client.order(coin: "@142", is_buy: true, size: 1, limit_px: 100)
|
|
258
|
+
|
|
259
|
+
assert result.success?
|
|
260
|
+
assert_equal({ "status" => "ok" }, result.data)
|
|
261
|
+
end
|
|
262
|
+
|
|
193
263
|
private
|
|
194
264
|
|
|
195
265
|
def stub_connection(method, body)
|