honeymaker 0.12.6 → 0.12.9
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/.github/workflows/native-gems.yml +2 -2
- data/.github/workflows/test.yml +1 -1
- data/Cargo.lock +3 -3
- data/Cargo.toml +1 -1
- data/lib/honeymaker/exchanges/okx.rb +88 -0
- data/lib/honeymaker/version.rb +1 -1
- data/lib/honeymaker.rb +3 -1
- data/test/fixtures/okx_instruments.json +16 -0
- data/test/fixtures/okx_ticker.json +1 -0
- data/test/honeymaker/exchanges/okx_test.rb +111 -0
- data/test/honeymaker/honeymaker_test.rb +1 -1
- metadata +5 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: b5f9ae7746f19bf30f0e0c996398d65e8d41fb7fe38a906ae94c42e9201838c4
|
|
4
|
+
data.tar.gz: 9651a481a48f1552f9723e940a958cec70a50dc04bcf784cadb07daae3a34c93
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: e676c91decb71d9633535872db3bb98dfefeaa5991d570713b7eecaa4fab9e1a133234e3ec0b08c63c933a209e4d5f3f51cebaa0ae6c3f1f8cbae79006dde45f
|
|
7
|
+
data.tar.gz: 5a71fb58d265db27e0e257208ef7ab5b9dd8272cc058eea56b0e66d7f43d523addc9c9bbd339ccf230fb8a8d3513002673d2973904bea5fb000a13848477f4e3
|
|
@@ -79,8 +79,8 @@ jobs:
|
|
|
79
79
|
- { os: ubuntu-24.04-arm, platform: aarch64-linux, ruby: "4.0" }
|
|
80
80
|
- { os: macos-15-intel, platform: x86_64-darwin, ruby: "3.4" }
|
|
81
81
|
- { os: macos-15-intel, platform: x86_64-darwin, ruby: "4.0" }
|
|
82
|
-
- { os: macos-
|
|
83
|
-
- { os: macos-
|
|
82
|
+
- { os: macos-15, platform: arm64-darwin, ruby: "3.4" }
|
|
83
|
+
- { os: macos-15, platform: arm64-darwin, ruby: "4.0" }
|
|
84
84
|
- { os: windows-latest, platform: x64-mingw-ucrt, ruby: "3.4" }
|
|
85
85
|
- { os: windows-latest, platform: x64-mingw-ucrt, ruby: "4.0" }
|
|
86
86
|
runs-on: ${{ matrix.os }}
|
data/.github/workflows/test.yml
CHANGED
data/Cargo.lock
CHANGED
|
@@ -265,7 +265,7 @@ dependencies = [
|
|
|
265
265
|
|
|
266
266
|
[[package]]
|
|
267
267
|
name = "honeymaker"
|
|
268
|
-
version = "0.12.
|
|
268
|
+
version = "0.12.9"
|
|
269
269
|
dependencies = [
|
|
270
270
|
"base64",
|
|
271
271
|
"bigdecimal",
|
|
@@ -278,7 +278,7 @@ dependencies = [
|
|
|
278
278
|
|
|
279
279
|
[[package]]
|
|
280
280
|
name = "honeymaker-client"
|
|
281
|
-
version = "0.12.
|
|
281
|
+
version = "0.12.9"
|
|
282
282
|
dependencies = [
|
|
283
283
|
"base64",
|
|
284
284
|
"bigdecimal",
|
|
@@ -300,7 +300,7 @@ dependencies = [
|
|
|
300
300
|
|
|
301
301
|
[[package]]
|
|
302
302
|
name = "honeymaker_native"
|
|
303
|
-
version = "0.12.
|
|
303
|
+
version = "0.12.9"
|
|
304
304
|
dependencies = [
|
|
305
305
|
"honeymaker",
|
|
306
306
|
"magnus",
|
data/Cargo.toml
CHANGED
|
@@ -3,7 +3,7 @@ members = ["crates/honeymaker", "crates/honeymaker-client", "ext/honeymaker_nati
|
|
|
3
3
|
resolver = "3"
|
|
4
4
|
|
|
5
5
|
[workspace.package]
|
|
6
|
-
version = "0.12.
|
|
6
|
+
version = "0.12.9" # lockstep with lib/honeymaker/version.rb (test/native/lockstep_test.rb)
|
|
7
7
|
edition = "2024"
|
|
8
8
|
rust-version = "1.94"
|
|
9
9
|
license = "MIT"
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Honeymaker
|
|
4
|
+
module Exchanges
|
|
5
|
+
class Okx < Exchange
|
|
6
|
+
BASE_URL = "https://openapi.okx.com"
|
|
7
|
+
|
|
8
|
+
def get_tickers_info
|
|
9
|
+
with_rescue do
|
|
10
|
+
response = connection.get("/api/v5/public/instruments") do |req|
|
|
11
|
+
req.params = { instType: "SPOT" }
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
okx_data(response).filter_map do |product|
|
|
15
|
+
lot = step_of(product["lotSz"])
|
|
16
|
+
tick = step_of(product["tickSz"])
|
|
17
|
+
base = product["baseCcy"].to_s
|
|
18
|
+
quote = product["quoteCcy"].to_s
|
|
19
|
+
next if base.empty? || quote.empty?
|
|
20
|
+
|
|
21
|
+
{
|
|
22
|
+
ticker: product["instId"],
|
|
23
|
+
base: base,
|
|
24
|
+
quote: quote,
|
|
25
|
+
# minSz is in base; OKX has no notional floor for spot.
|
|
26
|
+
minimum_base_size: product["minSz"]&.to_s,
|
|
27
|
+
minimum_quote_size: "0",
|
|
28
|
+
maximum_base_size: product["maxLmtSz"]&.to_s,
|
|
29
|
+
maximum_quote_size: nil,
|
|
30
|
+
base_decimals: step_decimals(lot),
|
|
31
|
+
quote_decimals: step_decimals(tick),
|
|
32
|
+
price_decimals: step_decimals(tick),
|
|
33
|
+
available: true,
|
|
34
|
+
trading_enabled: product["state"] == "live" && decimal_step?(lot) && decimal_step?(tick)
|
|
35
|
+
}
|
|
36
|
+
end
|
|
37
|
+
end
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
def get_bid_ask(symbol)
|
|
41
|
+
with_rescue do
|
|
42
|
+
response = connection.get("/api/v5/market/ticker") do |req|
|
|
43
|
+
req.params = { instId: symbol }
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
data = okx_data(response).first or raise "OKX has no ticker for #{symbol}"
|
|
47
|
+
{
|
|
48
|
+
bid: BigDecimal(data["bidPx"]),
|
|
49
|
+
ask: BigDecimal(data["askPx"])
|
|
50
|
+
}
|
|
51
|
+
end
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
private
|
|
55
|
+
|
|
56
|
+
# OKX answers some errors with HTTP 200 and a nonzero `code` (50011 rate limit, with empty `data`): a failure, not
|
|
57
|
+
# an empty catalogue.
|
|
58
|
+
def okx_data(response)
|
|
59
|
+
body = response.body
|
|
60
|
+
raise "OKX API error #{body["code"]}: #{body["msg"]}" unless body["code"].to_s == "0"
|
|
61
|
+
|
|
62
|
+
body["data"]
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
# A step as a finite positive number, read in any notation ("0.00000001", "1e-8"); else nil. A row with such a step
|
|
66
|
+
# has no decimals (data-api skips it) and does not trade, and the rest of the catalogue still reads.
|
|
67
|
+
def step_of(raw)
|
|
68
|
+
step = BigDecimal(raw.to_s)
|
|
69
|
+
step if step.finite? && step.positive?
|
|
70
|
+
rescue ArgumentError, TypeError, FloatDomainError
|
|
71
|
+
nil
|
|
72
|
+
end
|
|
73
|
+
|
|
74
|
+
def step_decimals(step)
|
|
75
|
+
step&.scale
|
|
76
|
+
end
|
|
77
|
+
|
|
78
|
+
# Decimal places express only a step of 10^-n (n >= 0): a pair stepping by 0.05 or 10 is listed, not tradable.
|
|
79
|
+
def decimal_step?(step)
|
|
80
|
+
!step.nil? && step == BigDecimal("1e-#{step_decimals(step)}")
|
|
81
|
+
end
|
|
82
|
+
|
|
83
|
+
def connection
|
|
84
|
+
@connection ||= build_connection(BASE_URL, content_type_match: //)
|
|
85
|
+
end
|
|
86
|
+
end
|
|
87
|
+
end
|
|
88
|
+
end
|
data/lib/honeymaker/version.rb
CHANGED
data/lib/honeymaker.rb
CHANGED
|
@@ -38,6 +38,7 @@ require_relative "honeymaker/exchanges/kucoin"
|
|
|
38
38
|
require_relative "honeymaker/exchanges/hyperliquid"
|
|
39
39
|
require_relative "honeymaker/exchanges/bingx"
|
|
40
40
|
require_relative "honeymaker/exchanges/bitrue"
|
|
41
|
+
require_relative "honeymaker/exchanges/okx"
|
|
41
42
|
|
|
42
43
|
if Honeymaker::Native.enabled?("kraken")
|
|
43
44
|
Honeymaker::Native.load! # fail at boot, not at the first order
|
|
@@ -60,7 +61,8 @@ module Honeymaker
|
|
|
60
61
|
"kucoin" => Exchanges::Kucoin,
|
|
61
62
|
"hyperliquid" => Exchanges::Hyperliquid,
|
|
62
63
|
"bingx" => Exchanges::BingX,
|
|
63
|
-
"bitrue" => Exchanges::Bitrue
|
|
64
|
+
"bitrue" => Exchanges::Bitrue,
|
|
65
|
+
"okx" => Exchanges::Okx
|
|
64
66
|
}.freeze
|
|
65
67
|
|
|
66
68
|
CLIENTS = {
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
{
|
|
2
|
+
"code": "0",
|
|
3
|
+
"msg": "",
|
|
4
|
+
"data": [
|
|
5
|
+
{"instType": "SPOT", "instId": "BTC-USDT", "baseCcy": "BTC", "quoteCcy": "USDT", "state": "live",
|
|
6
|
+
"lotSz": "0.00000001", "minSz": "0.00001", "tickSz": "0.1", "maxLmtSz": "9999999999", "maxMktSz": "1000000"},
|
|
7
|
+
{"instType": "SPOT", "instId": "ETH-EUR", "baseCcy": "ETH", "quoteCcy": "EUR", "state": "suspend",
|
|
8
|
+
"lotSz": "0.000001", "minSz": "0.0001", "tickSz": "0.01", "maxLmtSz": "1000000", "maxMktSz": "1000000"},
|
|
9
|
+
{"instType": "SPOT", "instId": "XYZ-USDT", "baseCcy": "XYZ", "quoteCcy": "USDT", "state": "live",
|
|
10
|
+
"lotSz": "1", "minSz": "10", "tickSz": "0.05", "maxLmtSz": "1000000", "maxMktSz": "1000000"},
|
|
11
|
+
{"instType": "SPOT", "instId": "BROKEN", "baseCcy": "", "quoteCcy": "", "state": "live",
|
|
12
|
+
"lotSz": "1", "minSz": "1", "tickSz": "1", "maxLmtSz": "1", "maxMktSz": "1"},
|
|
13
|
+
{"instType": "SPOT", "instId": "TEN-USDT", "baseCcy": "TEN", "quoteCcy": "USDT", "state": "live",
|
|
14
|
+
"lotSz": "10", "minSz": "10", "tickSz": "0.0010", "maxLmtSz": "1000000", "maxMktSz": "1000000"}
|
|
15
|
+
]
|
|
16
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"code": "0", "msg": "", "data": [{"instId": "BTC-USDT", "last": "67124", "askPx": "67125.6", "bidPx": "67123.4"}]}
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "test_helper"
|
|
4
|
+
|
|
5
|
+
# Fixtures follow the shapes in OKX's v5 docs (public instruments, market ticker).
|
|
6
|
+
class Honeymaker::Exchanges::OkxTest < Minitest::Test
|
|
7
|
+
include FixtureHelper
|
|
8
|
+
|
|
9
|
+
def setup
|
|
10
|
+
@exchange = Honeymaker::Exchanges::Okx.new
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
def test_get_tickers_info_parses_response
|
|
14
|
+
stub_connection(load_fixture("okx_instruments.json"))
|
|
15
|
+
|
|
16
|
+
result = @exchange.get_tickers_info
|
|
17
|
+
|
|
18
|
+
assert result.success?
|
|
19
|
+
assert_equal %w[BTC-USDT ETH-EUR XYZ-USDT TEN-USDT], result.data.map { |t| t[:ticker] }
|
|
20
|
+
|
|
21
|
+
btc = result.data.first
|
|
22
|
+
assert_equal "BTC", btc[:base]
|
|
23
|
+
assert_equal "USDT", btc[:quote]
|
|
24
|
+
assert_equal "0.00001", btc[:minimum_base_size]
|
|
25
|
+
assert_equal "0", btc[:minimum_quote_size]
|
|
26
|
+
assert_equal "9999999999", btc[:maximum_base_size]
|
|
27
|
+
assert_equal 8, btc[:base_decimals]
|
|
28
|
+
assert_equal 1, btc[:quote_decimals]
|
|
29
|
+
assert_equal 1, btc[:price_decimals]
|
|
30
|
+
assert btc[:available]
|
|
31
|
+
assert btc[:trading_enabled]
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
def test_only_live_instruments_trade
|
|
35
|
+
stub_connection(load_fixture("okx_instruments.json"))
|
|
36
|
+
|
|
37
|
+
refute @exchange.get_tickers_info.data.find { |t| t[:ticker] == "ETH-EUR" }[:trading_enabled]
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
def test_a_step_decimals_cannot_express_does_not_trade
|
|
41
|
+
stub_connection(load_fixture("okx_instruments.json"))
|
|
42
|
+
|
|
43
|
+
xyz = @exchange.get_tickers_info.data.find { |t| t[:ticker] == "XYZ-USDT" }
|
|
44
|
+
refute xyz[:trading_enabled]
|
|
45
|
+
assert_equal 0, xyz[:base_decimals]
|
|
46
|
+
|
|
47
|
+
# A lot of 10 is a power of ten, but zero decimal places would still allow 11.
|
|
48
|
+
ten = @exchange.get_tickers_info.data.find { |t| t[:ticker] == "TEN-USDT" }
|
|
49
|
+
refute ten[:trading_enabled]
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
def test_trailing_zeros_still_read_as_a_decimal_step
|
|
53
|
+
stub_connection({ "code" => "0", "data" => [{ "instId" => "A-B", "baseCcy" => "A", "quoteCcy" => "B", "state" => "live",
|
|
54
|
+
"lotSz" => "0.0100", "tickSz" => "1.0", "minSz" => "1" }] })
|
|
55
|
+
|
|
56
|
+
a = @exchange.get_tickers_info.data.first
|
|
57
|
+
assert a[:trading_enabled]
|
|
58
|
+
assert_equal 2, a[:base_decimals]
|
|
59
|
+
assert_equal 0, a[:price_decimals]
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
def test_get_bid_ask_parses_response
|
|
63
|
+
stub_connection(load_fixture("okx_ticker.json"))
|
|
64
|
+
|
|
65
|
+
result = @exchange.get_bid_ask("BTC-USDT")
|
|
66
|
+
|
|
67
|
+
assert result.success?
|
|
68
|
+
assert_equal BigDecimal("67123.4"), result.data[:bid]
|
|
69
|
+
assert_equal BigDecimal("67125.6"), result.data[:ask]
|
|
70
|
+
end
|
|
71
|
+
|
|
72
|
+
def test_an_error_envelope_fails_instead_of_reading_as_an_empty_catalogue
|
|
73
|
+
stub_connection({ "code" => "50011", "msg" => "Too Many Requests", "data" => [] })
|
|
74
|
+
|
|
75
|
+
result = @exchange.get_tickers_info
|
|
76
|
+
assert result.failure?
|
|
77
|
+
assert_equal ["OKX API error 50011: Too Many Requests"], result.errors
|
|
78
|
+
|
|
79
|
+
assert_equal ["OKX API error 50011: Too Many Requests"], @exchange.get_bid_ask("BTC-USDT").errors
|
|
80
|
+
end
|
|
81
|
+
|
|
82
|
+
def test_an_unknown_instrument_has_no_bid_ask
|
|
83
|
+
stub_connection({ "code" => "0", "msg" => "", "data" => [] })
|
|
84
|
+
|
|
85
|
+
assert_equal ["OKX has no ticker for NOPE-USDT"], @exchange.get_bid_ask("NOPE-USDT").errors
|
|
86
|
+
end
|
|
87
|
+
|
|
88
|
+
def test_an_unreadable_step_disables_its_row_only
|
|
89
|
+
row = ->(id, lot) { { "instId" => id, "baseCcy" => id, "quoteCcy" => "USDT", "state" => "live", "lotSz" => lot, "tickSz" => "0.1", "minSz" => "1" } }
|
|
90
|
+
stub_connection({ "code" => "0", "data" => [row.("BLANK", ""), row.("DOT", "."), row.("NAN", "NaN"), row.("INF", "Infinity"), row.("EXP", "1e-8")] })
|
|
91
|
+
|
|
92
|
+
result = @exchange.get_tickers_info
|
|
93
|
+
assert result.success?
|
|
94
|
+
by = result.data.to_h { |t| [t[:ticker], t] }
|
|
95
|
+
%w[BLANK DOT NAN INF].each do |id|
|
|
96
|
+
assert_nil by[id][:base_decimals], id
|
|
97
|
+
refute by[id][:trading_enabled], id
|
|
98
|
+
end
|
|
99
|
+
assert by["EXP"][:trading_enabled]
|
|
100
|
+
assert_equal 8, by["EXP"][:base_decimals]
|
|
101
|
+
end
|
|
102
|
+
|
|
103
|
+
private
|
|
104
|
+
|
|
105
|
+
def stub_connection(body)
|
|
106
|
+
response = stub(body: body)
|
|
107
|
+
connection = stub
|
|
108
|
+
connection.stubs(:get).returns(response)
|
|
109
|
+
@exchange.instance_variable_set(:@connection, connection)
|
|
110
|
+
end
|
|
111
|
+
end
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: honeymaker
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.12.
|
|
4
|
+
version: 0.12.9
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Deltabadger
|
|
@@ -179,6 +179,7 @@ files:
|
|
|
179
179
|
- lib/honeymaker/exchanges/kraken.rb
|
|
180
180
|
- lib/honeymaker/exchanges/kucoin.rb
|
|
181
181
|
- lib/honeymaker/exchanges/mexc.rb
|
|
182
|
+
- lib/honeymaker/exchanges/okx.rb
|
|
182
183
|
- lib/honeymaker/floors.rb
|
|
183
184
|
- lib/honeymaker/native.rb
|
|
184
185
|
- lib/honeymaker/native/kraken.rb
|
|
@@ -220,6 +221,8 @@ files:
|
|
|
220
221
|
- test/fixtures/kucoin_symbols.json
|
|
221
222
|
- test/fixtures/mexc_book_ticker.json
|
|
222
223
|
- test/fixtures/mexc_exchange_info.json
|
|
224
|
+
- test/fixtures/okx_instruments.json
|
|
225
|
+
- test/fixtures/okx_ticker.json
|
|
223
226
|
- test/honeymaker/client_test.rb
|
|
224
227
|
- test/honeymaker/clients/binance_client_test.rb
|
|
225
228
|
- test/honeymaker/clients/binance_us_client_test.rb
|
|
@@ -253,6 +256,7 @@ files:
|
|
|
253
256
|
- test/honeymaker/exchanges/kraken_test.rb
|
|
254
257
|
- test/honeymaker/exchanges/kucoin_test.rb
|
|
255
258
|
- test/honeymaker/exchanges/mexc_test.rb
|
|
259
|
+
- test/honeymaker/exchanges/okx_test.rb
|
|
256
260
|
- test/honeymaker/floors_test.rb
|
|
257
261
|
- test/honeymaker/honeymaker_test.rb
|
|
258
262
|
- test/honeymaker/result_test.rb
|