hyperliquid-rb 0.1.0 → 0.1.1

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: b7592a75a389665ac7ccb861b5cf9f4f500d16b712343f41b0acf5411c8408dc
4
- data.tar.gz: 5c7d881e948ae92752a8b0fa58b6738cec1318ff3ebd5e27764cac4919475460
3
+ metadata.gz: c0cb88c29e0a7a10e761bd52c99e62a07a8c878bda0871b4b8812d53b50093cc
4
+ data.tar.gz: b2cf212fcb066dd751dc261c1cdfe7d539d23bc04144cdedef7838dc56bc86aa
5
5
  SHA512:
6
- metadata.gz: dea8bc10e5b32c4e9695a11004f6c85d7bd8ef84c0afa01d3996c11d0813dbf5700a71a2203b9dc3d4bb0c2bebf262ab537b119ea122385a9ffb35f643db402e
7
- data.tar.gz: 90965b87faee7ee1e1d0ffdaca66c1e34bdd11a957aeefee5c10ab0176a10f16759055b5141307aad8a02cf7de09703464309edda514a87d2dcebc722e50642e
6
+ metadata.gz: 50666c8b56ac24dfcd33b336966dc9fa89e271ab92241cd1dbf785634475b3239669597867229029d82153bf4bcd2126f81265f754399466bde9a3d7005c4b26
7
+ data.tar.gz: 5a2d38dec0920f433565509ef01c76178b4ae990920bef46d1d86637272b4ce1eb9396705971a4f8be5527e26ab457a9f3b94f67114918ad9020cff100f39637
data/CHANGELOG.md ADDED
@@ -0,0 +1,40 @@
1
+ # Changelog
2
+
3
+ All notable changes to this project are documented in this file.
4
+
5
+ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
6
+ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7
+
8
+ ## [0.1.1] - 2026-06-17
9
+
10
+ ### Fixed
11
+
12
+ - **Spot coin → asset mapping now uses the universe entry's permanent `index`
13
+ field instead of its array position.** The live spot universe is sparse
14
+ (delisted pairs leave permanent index gaps), so for every entry after the
15
+ first gap, position no longer equals index. The old code addressed orders to
16
+ the wrong spot asset — e.g. `name_to_asset("@107")` (HYPE/USDC) returned
17
+ `10105` (HPYH/USDC) — which could be rejected or, for a similarly priced
18
+ neighbor, silently fill the wrong coin. This matches the official Python SDK
19
+ (`asset = spot_info["index"] + 10000`). Affects `Info#name_to_asset`,
20
+ `Info#spot_coin_to_asset`, and every `Exchange` trading op that resolves a
21
+ spot coin (orders, modify, cancel, TWAP, leverage/margin, slippage pricing).
22
+
23
+ ### Added
24
+
25
+ - `Info#name_to_asset` now resolves the friendly `BASE/QUOTE` spot name (e.g.
26
+ `"HYPE/USDC"`) in addition to the universe name (e.g. `"@107"`), mirroring the
27
+ Python SDK's `name_to_coin` mapping.
28
+
29
+ ### Changed (breaking)
30
+
31
+ - **`Info#asset_to_sz_decimals` spot keys moved from token index to asset id.**
32
+ Spot `szDecimals` are now keyed by the order asset id (`10_000 + index`) and
33
+ hold the base token's `szDecimals`, matching the Python SDK. Previously they
34
+ were keyed by the raw token index, which returned `nil` for real asset ids and
35
+ collided with perpetual asset ids. This also fixes spot `slippage_price`
36
+ rounding (was falling back to `0` decimals) — the likely cause of latent
37
+ "Order has invalid size" errors. Any caller that looked up spot `szDecimals`
38
+ by a small token index must switch to the asset id.
39
+
40
+ [0.1.1]: https://github.com/deltabadger/hyperliquid-rb/releases/tag/v0.1.1
data/README.md CHANGED
@@ -1,5 +1,9 @@
1
1
  # Hyperliquid Ruby SDK
2
2
 
3
+ [![Gem Version](https://img.shields.io/gem/v/hyperliquid-rb)](https://rubygems.org/gems/hyperliquid-rb)
4
+ [![CI](https://github.com/deltabadger/hyperliquid-rb/actions/workflows/ci.yml/badge.svg)](https://github.com/deltabadger/hyperliquid-rb/actions)
5
+ [![License](https://img.shields.io/github/license/deltabadger/hyperliquid-rb)](LICENSE.txt)
6
+
3
7
  Complete Ruby SDK for the [Hyperliquid](https://hyperliquid.xyz) DEX. Covers 100% of the official Python SDK — trading, market data, EIP-712 signing, WebSocket subscriptions, and account management.
4
8
 
5
9
  Verified with 314 tests including 141 cross-library test vectors generated from the official Python SDK to ensure byte-identical signing output.
@@ -422,9 +422,8 @@ module Hyperliquid
422
422
  def load_spot_coin_mapping!
423
423
  m = spot_meta
424
424
  @spot_coin_to_asset = {}
425
- m["universe"].each_with_index do |token_info, index|
426
- name = token_info["name"]
427
- @spot_coin_to_asset[name] = 10_000 + index
425
+ m["universe"].each do |token_info|
426
+ @spot_coin_to_asset[token_info["name"]] = 10_000 + token_info["index"]
428
427
  end
429
428
  end
430
429
 
@@ -439,16 +438,7 @@ module Hyperliquid
439
438
 
440
439
  # Load spot metadata
441
440
  begin
442
- sm = spot_meta
443
- sm["universe"].each_with_index do |token_info, index|
444
- name = token_info["name"]
445
- asset = 10_000 + index
446
- @coin_to_asset[name] = asset
447
- @name_to_coin[name] = name
448
- end
449
- sm["tokens"]&.each do |token|
450
- @asset_to_sz_decimals[token["index"]] = token["szDecimals"] if token["index"]
451
- end
441
+ set_spot_meta(spot_meta)
452
442
  rescue Error
453
443
  # spot_meta may not be available
454
444
  end
@@ -472,6 +462,26 @@ module Hyperliquid
472
462
  @spot_coin_to_asset = @coin_to_asset.select { |_k, v| v >= 10_000 && v < 110_000 }
473
463
  end
474
464
 
465
+ # Load the spot section of the mappings (mirrors the official Python SDK).
466
+ # Asset ids use the universe entry's permanent `index` field (10_000 + index),
467
+ # never its array position; the spot universe is sparse so the two diverge.
468
+ def set_spot_meta(m)
469
+ tokens = m["tokens"] || []
470
+ m["universe"].each do |spot_info|
471
+ asset = 10_000 + spot_info["index"]
472
+ name = spot_info["name"]
473
+ @coin_to_asset[name] = asset
474
+ @name_to_coin[name] = name
475
+ base, quote = spot_info["tokens"] # nil tokens => base=quote=nil (safe)
476
+ base_info = tokens[base] if base
477
+ quote_info = tokens[quote] if quote
478
+ @asset_to_sz_decimals[asset] = base_info["szDecimals"] if base_info
479
+ next unless base_info && quote_info
480
+
481
+ @name_to_coin["#{base_info["name"]}/#{quote_info["name"]}"] ||= name
482
+ end
483
+ end
484
+
475
485
  def set_perp_meta(m, offset, dex: nil)
476
486
  m["universe"].each_with_index do |asset_info, index|
477
487
  name = asset_info["name"]
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Hyperliquid
4
- VERSION = "0.1.0"
4
+ VERSION = "0.1.1"
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hyperliquid-rb
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Deltabadger
@@ -73,6 +73,7 @@ executables: []
73
73
  extensions: []
74
74
  extra_rdoc_files: []
75
75
  files:
76
+ - CHANGELOG.md
76
77
  - LICENSE.txt
77
78
  - README.md
78
79
  - lib/hyperliquid.rb
@@ -92,7 +93,7 @@ licenses:
92
93
  metadata:
93
94
  homepage_uri: https://github.com/deltabadger/hyperliquid-rb
94
95
  source_code_uri: https://github.com/deltabadger/hyperliquid-rb
95
- changelog_uri: https://github.com/deltabadger/hyperliquid-rb/commits/main
96
+ changelog_uri: https://github.com/deltabadger/hyperliquid-rb/blob/main/CHANGELOG.md
96
97
  rubygems_mfa_required: 'true'
97
98
  rdoc_options: []
98
99
  require_paths:
@@ -101,7 +102,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
101
102
  requirements:
102
103
  - - ">="
103
104
  - !ruby/object:Gem::Version
104
- version: '3.1'
105
+ version: '3.4'
105
106
  required_rubygems_version: !ruby/object:Gem::Requirement
106
107
  requirements:
107
108
  - - ">="