hyperliquid 1.9.0 → 2.0.0

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.
Files changed (49) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +63 -0
  3. data/README.md +26 -0
  4. data/docs/API.md +374 -152
  5. data/docs/CONFIGURATION.md +25 -11
  6. data/docs/DEVELOPMENT.md +93 -15
  7. data/docs/ERRORS.md +2 -0
  8. data/docs/EXAMPLES.md +253 -2
  9. data/docs/WS.md +78 -20
  10. data/lib/hyperliquid/client.rb +19 -10
  11. data/lib/hyperliquid/exchange.rb +844 -22
  12. data/lib/hyperliquid/info.rb +23 -11
  13. data/lib/hyperliquid/signing/signer.rb +18 -1
  14. data/lib/hyperliquid/version.rb +1 -1
  15. data/lib/hyperliquid/ws/client.rb +192 -78
  16. data/lib/hyperliquid.rb +6 -0
  17. metadata +16 -34
  18. data/.rspec +0 -3
  19. data/.rubocop.yml +0 -49
  20. data/.ruby-version +0 -1
  21. data/CLAUDE.md +0 -104
  22. data/CODE_OF_CONDUCT.md +0 -132
  23. data/Rakefile +0 -12
  24. data/example.rb +0 -161
  25. data/scripts/test_01_spot_market_roundtrip.rb +0 -48
  26. data/scripts/test_02_spot_limit_order.rb +0 -48
  27. data/scripts/test_03_perp_market_roundtrip.rb +0 -58
  28. data/scripts/test_04_perp_limit_order.rb +0 -52
  29. data/scripts/test_05_update_leverage.rb +0 -50
  30. data/scripts/test_06_modify_order.rb +0 -67
  31. data/scripts/test_07_market_close.rb +0 -55
  32. data/scripts/test_08_usd_class_transfer.rb +0 -36
  33. data/scripts/test_09_sub_account_lifecycle.rb +0 -51
  34. data/scripts/test_10_vault.rb +0 -68
  35. data/scripts/test_11_builder_fee.rb +0 -81
  36. data/scripts/test_12_staking.rb +0 -70
  37. data/scripts/test_13_ws_l2_book.rb +0 -83
  38. data/scripts/test_14_ws_candle.rb +0 -81
  39. data/scripts/test_15_explorer.rb +0 -71
  40. data/scripts/test_16_send_to_evm_with_data.rb +0 -79
  41. data/scripts/test_17_create_vault.rb +0 -73
  42. data/scripts/test_18_user_portfolio_margin.rb +0 -72
  43. data/scripts/test_19_spot_user.rb +0 -55
  44. data/scripts/test_20_explorer_ws.rb +0 -92
  45. data/scripts/test_all.rb +0 -96
  46. data/scripts/test_automated.rb +0 -82
  47. data/scripts/test_helpers.rb +0 -238
  48. data/sig/hyperliquid.rbs +0 -4
  49. data/test_integration.rb +0 -17
data/docs/API.md CHANGED
@@ -1,125 +1,328 @@
1
1
  # API Reference
2
2
 
3
- ## Info Methods
4
-
5
- Read-only methods for querying market data and user information.
6
-
7
- ### General Info
8
-
9
- - `all_mids(dex: nil)` - Retrieve mids for all coins (optional dex for HIP-3 perp dexs; spot mids only included with default dex)
10
- - `open_orders(user, dex: nil)` - Retrieve a user's open orders (optional dex for HIP-3)
11
- - `frontend_open_orders(user, dex: nil)` - Retrieve a user's open orders with additional frontend info
12
- - `user_fills(user)` - Retrieve a user's fills
13
- - `user_fills_by_time(user, start_time, end_time = nil)` - Retrieve a user's fills by time (optional end time)
14
- - `user_rate_limit(user)` - Query user rate limits
15
- - `order_status(user, oid)` - Query order status by order id (oid)
16
- - `order_status_by_cloid(user, cloid)` - Query order status by client order id (cloid)
17
- - `l2_book(coin)` - L2 book snapshot (Perpetuals and Spot)
18
- - `candles_snapshot(coin, interval, start_time, end_time)` - Candle snapshot (Perpetuals and Spot)
19
- - `max_builder_fee(user, builder)` - Check builder fee approval
20
- - `historical_orders(user, start_time = nil, end_time = nil)` - Retrieve a user's historical orders
21
- - `user_twap_slice_fills(user, start_time = nil, end_time = nil)` - Retrieve a user's TWAP slice fills
22
- - `user_subaccounts(user)` - Retrieve a user's subaccounts
23
- - `vault_details(vault_address, user = nil)` - Retrieve details for a vault
24
- - `user_vault_equities(user)` - Retrieve a user's vault deposits
25
- - `user_role(user)` - Query a user's role
26
- - `portfolio(user)` - Query a user's portfolio
27
- - `referral(user)` - Query a user's referral information
28
- - `user_fees(user)` - Query a user's fees and fee schedule
29
- - `delegations(user)` - Query a user's staking delegations
30
- - `delegator_summary(user)` - Query a user's staking summary
31
- - `delegator_history(user)` - Query a user's staking history
32
- - `delegator_rewards(user)` - Query a user's staking rewards
33
- - `extra_agents(user)` - Get authorized agent addresses for a user
34
- - `user_to_multi_sig_signers(user)` - Get multi-sig signer mappings for a user
35
- - `user_dex_abstraction(user)` - Get dex abstraction config for a user
36
-
37
- ### Perpetuals Methods
38
-
39
- - `perp_dexs()` - Retrieve all perpetual DEXs
40
- - `meta(dex: nil)` - Get asset metadata (optionally for a specific perp DEX)
41
- - `meta_and_asset_ctxs()` - Get extended asset metadata
42
- - `user_state(user, dex: nil)` - Retrieve user's perpetuals account summary (optionally for a specific perp DEX)
43
- - `predicted_fundings()` - Retrieve predicted funding rates across venues
44
- - `perps_at_open_interest_cap()` - Query perps at open interest caps
45
- - `perp_deploy_auction_status()` - Retrieve Perp Deploy Auction status
46
- - `active_asset_data(user, coin)` - Retrieve a user's active asset data for a coin
47
- - `perp_dex_limits(dex)` - Retrieve builder-deployed perp market limits for a DEX
48
- - `user_funding(user, start_time, end_time = nil)` - Retrieve a user's funding history (optional end time)
49
- - `user_non_funding_ledger_updates(user, start_time, end_time = nil)` - Retrieve a user's non-funding ledger updates. Non-funding ledger updates include deposits, transfers, and withdrawals. (optional end time)
50
- - `funding_history(coin, start_time, end_time = nil)` - Retrieve historical funding rates (optional end time)
51
-
52
- ### Spot Methods
53
-
54
- - `spot_meta()` - Retrieve spot metadata (tokens and universe)
55
- - `spot_meta_and_asset_ctxs()` - Retrieve spot metadata and asset contexts
56
- - `spot_balances(user)` - Retrieve a user's spot token balances
57
- - `spot_deploy_state(user)` - Retrieve Spot Deploy Auction information
58
- - `spot_pair_deploy_auction_status()` - Retrieve Spot Pair Deploy Auction status
59
- - `token_details(token_id)` - Retrieve information about a token by tokenId
60
-
61
- ## Exchange Methods (Trading)
62
-
63
- **Note:** Exchange methods require initializing the SDK with a `private_key`.
64
-
65
- ### Order Placement
66
-
67
- - `order(coin:, is_buy:, size:, limit_px:, ...)` - Place a single limit order
68
- - `bulk_orders(orders:, grouping:, ...)` - Place multiple orders in a batch
69
- - `market_order(coin:, is_buy:, size:, slippage:, ...)` - Place a market order with slippage
70
-
71
- ### Order Modification
72
-
73
- - `modify_order(oid:, coin:, is_buy:, size:, limit_px:, ...)` - Modify an existing order by oid or cloid
74
- - `batch_modify(modifies:, ...)` - Modify multiple orders at once
75
-
76
- ### Order Cancellation
77
-
78
- - `cancel(coin:, oid:, ...)` - Cancel an order by order ID
79
- - `cancel_by_cloid(coin:, cloid:, ...)` - Cancel an order by client order ID
80
- - `bulk_cancel(cancels:, ...)` - Cancel multiple orders by order ID
81
- - `bulk_cancel_by_cloid(cancels:, ...)` - Cancel multiple orders by client order ID
82
- - `schedule_cancel(time:, ...)` - Auto-cancel all orders at a given time
83
-
84
- ### Position Management
85
-
86
- - `market_close(coin:, size:, slippage:, ...)` - Close a position at market price (auto-detects position size)
87
- - `update_leverage(coin:, leverage:, is_cross:, ...)` - Set cross or isolated leverage for a coin
88
- - `update_isolated_margin(coin:, amount:, ...)` - Add or remove isolated margin for a position
89
-
90
- ### Transfers & Account Management
91
-
92
- - `usd_send(amount:, destination:)` - Transfer USDC to another address
93
- - `spot_send(amount:, destination:, token:)` - Transfer a spot token to another address
94
- - `usd_class_transfer(amount:, to_perp:)` - Move USDC between perp and spot accounts
95
- - `withdraw_from_bridge(amount:, destination:)` - Withdraw USDC via the bridge
96
- - `send_asset(destination:, source_dex:, destination_dex:, token:, amount:)` - Move assets between DEX instances
3
+ Every public method of the SDK is listed here, grouped to mirror `lib/`. Entries use the form
4
+ `` - `method(signature)` - description ``; the signature is the Ruby signature from `lib/` (optional
5
+ arguments show their default). Info and Exchange methods return the parsed JSON response (Hash or Array)
6
+ unchanged. `spec/docs_coverage_spec.rb` fails the build when a public method, parameter, or WebSocket
7
+ channel is missing from this file.
8
+
9
+ ## SDK
10
+
11
+ - `Hyperliquid.new(testnet: false, timeout: 30, retry_enabled: false, private_key: nil, expires_after: nil)` - Create an SDK instance. `private_key` enables `exchange`; `expires_after` (ms timestamp) applies to L1 actions. See [CONFIGURATION.md](CONFIGURATION.md)
12
+ - `info` - The `Hyperliquid::Info` client (always available)
13
+ - `exchange` - The `Hyperliquid::Exchange` client, or `nil` when no `private_key` was given
14
+ - `ws` - The `Hyperliquid::WS::Client` (main API WebSocket + explorer WebSocket)
15
+ - `testnet?` - Whether the SDK targets testnet
16
+ - `base_url` - The HTTP API base URL in use
17
+
18
+ ## Info
19
+
20
+ Read-only queries (`POST /info`, or the explorer RPC for the Explorer RPC section). `user` arguments are wallet addresses (`0x` + 40 hex). Times are milliseconds since epoch.
21
+
22
+ ### General
23
+
24
+ - `all_mids(dex: nil)` - Mid prices for all coins. `dex:` selects a HIP-3 perp dex; spot mids are only included for the default dex
25
+ - `open_orders(user, dex: nil)` - A user's open orders (optional HIP-3 `dex:`)
26
+ - `frontend_open_orders(user, dex: nil)` - A user's open orders with additional frontend info (optional HIP-3 `dex:`)
27
+ - `user_fills(user)` - A user's most recent fills
28
+ - `user_fills_by_time(user, start_time, end_time = nil, aggregate_by_time: nil, reversed: nil)` - A user's fills in a time range. `aggregate_by_time: true` merges partial fills of one crossing order; `reversed: true` returns newest first
29
+ - `user_rate_limit(user)` - A user's request rate limit and usage
30
+ - `order_status(user, oid)` - Order status by order id
31
+ - `order_status_by_cloid(user, cloid)` - Order status by client order id (`Cloid` or hex String)
32
+ - `l2_book(coin)` - L2 order book snapshot (perp or spot)
33
+ - `recent_trades(coin)` - Recent trades for a coin
34
+ - `block_details(height)` - Block details by block height
35
+ - `candles_snapshot(coin, interval, start_time, end_time)` - Candles for a coin (intervals listed under WebSocket below)
36
+ - `max_builder_fee(user, builder)` - Maximum builder fee the user approved for `builder`
37
+ - `approved_builders(user)` - Builders the user has approved
38
+ - `historical_orders(user, start_time = nil, end_time = nil)` - A user's historical orders
39
+ - `user_twap_slice_fills(user, start_time = nil, end_time = nil)` - A user's TWAP slice fills
40
+ - `user_twap_slice_fills_by_time(user, start_time, end_time = nil, aggregate_by_time: nil)` - A user's TWAP slice fills in a time range (`aggregate_by_time:` as for `user_fills_by_time`)
41
+ - `user_subaccounts(user)` - A user's sub-accounts
42
+ - `sub_accounts2(user)` - A user's sub-accounts with per-dex clearinghouse and spot state
43
+ - `vault_details(vault_address, user = nil)` - Vault details, optionally with `user`'s position in it
44
+ - `user_vault_equities(user)` - A user's vault deposits
45
+ - `vault_summaries` - Vaults created less than 2 hours ago
46
+ - `user_role(user)` - A user's role (user, agent, vault, sub-account, missing)
47
+ - `portfolio(user)` - A user's portfolio history by period
48
+ - `referral(user)` - A user's referral state
49
+ - `user_fees(user)` - A user's effective fee rates and fee schedule
50
+ - `delegations(user)` - A user's staking delegations
51
+ - `delegator_summary(user)` - A user's staking summary
52
+ - `delegator_history(user)` - A user's staking history
53
+ - `delegator_rewards(user)` - A user's staking rewards
54
+ - `extra_agents(user)` - A user's authorized agent wallets
55
+ - `user_to_multi_sig_signers(user)` - Multi-sig signer configuration for a user
56
+ - `user_dex_abstraction(user)` - A user's HIP-3 dex-abstraction setting
57
+ - `user_abstraction(user)` - A user's account abstraction mode
58
+ - `pre_transfer_check(user, source)` - Destination existence, activation fee and sanctions check before a transfer from `source`
59
+ - `vip?(user)` - Whether a user is a VIP
60
+ - `liquidatable` - Addresses of currently liquidatable users
61
+ - `validator_summaries` - Validator performance summaries
62
+ - `exchange_status` - Exchange system status
63
+ - `max_market_order_ntls` - Maximum market order notional per asset
64
+ - `validator_l1_votes` - L1 governance votes cast by validators
65
+ - `gossip_root_ips` - Gossip root IPs
66
+ - `gossip_priority_auction_status` - Gossip priority auction status (previous winners and current auctions)
67
+ - `legal_check(user)` - A user's legal verification status
68
+ - `margin_table(id, dex: nil)` - Margin requirement table by id. `dex:` is `""` for the main dex; `nil` omits it
69
+ - `leading_vaults(user)` - Vaults a user leads
70
+ - `twap_history(user)` - A user's TWAP order history
71
+ - `web_data2(user)` - Combined user and market data in one response (frontend snapshot)
72
+
73
+ ### Perpetuals
74
+
75
+ - `perp_dexs` - All perp dexs (`nil` entry = the canonical dex)
76
+ - `meta(dex: nil)` - Perp asset metadata (optional HIP-3 `dex:`)
77
+ - `meta_and_asset_ctxs` - Perp metadata plus asset contexts (mark price, funding, open interest)
78
+ - `all_perp_metas` - Metadata for every perp dex
79
+ - `user_state(user, dex: nil)` - A user's perp account summary (optional HIP-3 `dex:`)
80
+ - `predicted_fundings` - Predicted funding rates across venues
81
+ - `perps_at_open_interest_cap` - Perps currently at their open interest cap
82
+ - `perp_deploy_auction_status` - Perp deploy auction status
83
+ - `active_asset_data(user, coin)` - A user's leverage, max trade sizes and available margin for a coin
84
+ - `perp_dex_limits(dex)` - Limits for a builder-deployed perp dex
85
+ - `perp_dex_status(dex)` - Status (for example total net deposit) of a builder-deployed perp dex; `""` is the first dex
86
+ - `perp_categories` - Perp asset categories
87
+ - `perp_annotation(coin)` - Annotation for one perp asset
88
+ - `perp_concise_annotations` - Concise annotations for all perp assets
89
+ - `outcome_meta` - HIP-4 prediction-market outcome metadata
90
+ - `settled_outcome(outcome:)` - Settlement details of a HIP-4 outcome (`nil` if not settled)
91
+ - `outcome_templates` - HIP-4 outcome templates available to deployers
92
+ - `outcome_deployer_limits(venue)` - Deployer limits of a HIP-4 outcome venue
93
+ - `usdc_routing` - USDC deposit/withdrawal routing configuration
94
+ - `user_funding(user, start_time, end_time = nil)` - A user's funding payments
95
+ - `user_non_funding_ledger_updates(user, start_time, end_time = nil)` - A user's deposits, transfers and withdrawals
96
+ - `funding_history(coin, start_time, end_time = nil)` - Historical funding rates for a coin
97
+
98
+ ### Spot
99
+
100
+ - `spot_meta` - Spot tokens and pairs
101
+ - `spot_meta_and_asset_ctxs` - Spot metadata plus asset contexts
102
+ - `spot_balances(user)` - A user's spot token balances
103
+ - `spot_deploy_state(user)` - A user's spot deploy auction state
104
+ - `spot_pair_deploy_auction_status` - Spot pair deploy auction status
105
+ - `token_details(token_id)` - Token details by 34-character hex token id
106
+
107
+ ### Borrow/Lend (HIP-2)
108
+
109
+ - `borrow_lend_user_state(user)` - A user's borrow/lend positions
110
+ - `borrow_lend_reserve_state(token)` - Reserve state of one token (token index)
111
+ - `all_borrow_lend_reserve_states` - Reserve states of all tokens
112
+ - `user_borrow_lend_interest(user, start_time, end_time = nil)` - A user's interest accrual history
113
+
114
+ ### Explorer RPC
115
+
116
+ Sent to the explorer RPC (`rpc.hyperliquid.xyz/explorer`, or the testnet host) instead of `/info`.
117
+
118
+ - `tx_details(hash)` - Transaction details by hash (66-character hex)
119
+ - `user_details(user)` - A user's recent transactions
120
+
121
+ ### HIP-3* Star (testnet-only)
122
+
123
+ - `user_star_state(user)` - Retrieve a user's HIP-3* (testnet-only) approval state per venue (`dexToState` as [dex, state] pairs)
124
+
125
+ ## Exchange
126
+
127
+ Signed actions (`POST /exchange`). Requires `Hyperliquid.new(private_key: ...)`. Unless noted, actions are L1 actions: they honour the SDK's `expires_after` and, where the signature has `vault_address:`, act for that vault or sub-account. User-signed actions (noted below) reject `expires_after`; leave it `nil` for them. Sizes and prices accept Numeric or String.
128
+
129
+ ### Orders
130
+
131
+ - `order(coin:, is_buy:, size:, limit_px:, order_type: { limit: { tif: 'Gtc' } }, reduce_only: false, cloid: nil, vault_address: nil, builder: nil)` - Place one order. See Order Types, Trigger Orders and Builder Fees below
132
+ - `bulk_orders(orders:, grouping: 'na', vault_address: nil, builder: nil)` - Place several orders. Each Hash takes the `order` keywords; `grouping:` is `'na'`, `'normalTpsl'` or `'positionTpsl'`
133
+ - `market_order(coin:, is_buy:, size:, slippage: 0.05, vault_address: nil, builder: nil)` - IoC limit order at the mid price plus `slippage`
134
+ - `twap_order(coin:, is_buy:, size:, reduce_only:, minutes:, randomize:, vault_address: nil, details: nil)` - TWAP order over `minutes` (5-1440). `details:` is passed through: `{ t: { p:, a: } | nil, s: <String> | nil }`
135
+ - `twap_cancel(coin:, twap_id:, vault_address: nil)` - Cancel a TWAP order
136
+ - `trailing_stop(coin:, is_buy:, size:, reduce_only:, retracement:, activation_px: nil, vault_address: nil)` - Trailing stop. `retracement:` is `{ pct: '1.5%' }` or `{ px: '<price>' }`; `activation_px: nil` means no activation price
137
+
138
+ ### Cancels
139
+
140
+ - `cancel(coin:, oid:, vault_address: nil, fast: nil)` - Cancel by order id. `fast: true` requests fast cancel
141
+ - `cancel_by_cloid(coin:, cloid:, vault_address: nil, fast: nil)` - Cancel by client order id. `fast: true` requests fast cancel
142
+ - `bulk_cancel(cancels:, vault_address: nil)` - Cancel several orders; each Hash is `{ coin:, oid: }`
143
+ - `bulk_cancel_by_cloid(cancels:, vault_address: nil)` - Cancel several orders; each Hash is `{ coin:, cloid: }`
144
+ - `schedule_cancel(time: nil, vault_address: nil)` - Cancel all orders at `time` (ms, at least 5 s ahead); `time: nil` removes the scheduled cancel
145
+
146
+ ### Modifications
147
+
148
+ - `modify_order(oid:, coin:, is_buy:, size:, limit_px:, order_type: { limit: { tif: 'Gtc' } }, reduce_only: false, cloid: nil, vault_address: nil, always_place: nil)` - Modify an order by oid or `Cloid`. `always_place: true` places the new order even if the original is gone
149
+ - `batch_modify(modifies:, vault_address: nil)` - Modify several orders; each Hash takes the `modify_order` keywords including `:always_place`
150
+
151
+ ### Positions and Margin
152
+
153
+ - `update_leverage(coin:, leverage:, is_cross: true, vault_address: nil)` - Set cross or isolated leverage
154
+ - `update_isolated_margin(coin:, amount:, vault_address: nil)` - Add (positive) or remove (negative) isolated margin
155
+ - `market_close(coin:, size: nil, slippage: 0.05, cloid: nil, vault_address: nil, builder: nil)` - Close a position at market; `size: nil` closes all of it
156
+ - `top_up_isolated_only_margin(coin:, leverage:, vault_address: nil)` - Top up isolated-only margin to reach a target leverage
157
+
158
+ ### Transfers
159
+
160
+ - `usd_send(amount:, destination:)` - Send USDC (user-signed)
161
+ - `spot_send(amount:, destination:, token:)` - Send a spot token; `token` is `"NAME:0x<tokenId>"` and token ids differ per network (`info.spot_meta`), e.g. PURR is `"PURR:0xc1fb593aeffbeb02f85e0308e9956a90"` on mainnet and `"PURR:0xc4bf3f870c0e9465323c0b6ed28096c2"` on testnet (user-signed)
162
+ - `usd_class_transfer(amount:, to_perp:, sub_account: nil)` - Move USDC between perp and spot; `sub_account:` targets a sub-account (user-signed)
163
+ - `withdraw_from_bridge(amount:, destination:)` - Withdraw USDC through the bridge (user-signed)
164
+ - `send_asset(destination:, source_dex:, destination_dex:, token:, amount:)` - Move an asset between dexes or users; dex `""` is the main perp dex, `"spot"` is spot (user-signed)
165
+ - `agent_send_asset(destination:, source_dex:, destination_dex:, token:, amount:, from_sub_account: '')` - Agent-signed `send_asset`; `destination` must be the agent's principal
166
+ - `send_to_evm_with_data(token:, amount:, source_dex:, destination_recipient:, address_encoding:, destination_chain_id:, gas_limit:, data: '0x')` - Send to HyperEVM with calldata for `ICoreReceiveWithData` contracts. `address_encoding:` is `'hex'` or `'base58'` (user-signed)
167
+
168
+ ### Sub-Accounts
169
+
97
170
  - `create_sub_account(name:)` - Create a sub-account
98
- - `sub_account_transfer(sub_account_user:, is_deposit:, usd:)` - Transfer USDC to/from a sub-account
99
- - `sub_account_spot_transfer(sub_account_user:, is_deposit:, token:, amount:)` - Transfer spot tokens to/from a sub-account
100
- - `vault_transfer(vault_address:, is_deposit:, usd:)` - Deposit or withdraw USDC to/from a vault
101
- - `set_referrer(code:)` - Set referral code
171
+ - `sub_account_transfer(sub_account_user:, is_deposit:, usd:)` - Move USDC to or from a sub-account
172
+ - `sub_account_spot_transfer(sub_account_user:, is_deposit:, token:, amount:)` - Move a spot token to or from a sub-account
173
+ - `sub_account_modify(sub_account_user:, name:)` - Rename a sub-account
174
+
175
+ ### Vaults
176
+
177
+ - `vault_transfer(vault_address:, is_deposit:, usd:)` - Deposit to or withdraw from a vault
178
+ - `create_vault(name:, description:, initial_usd:)` - Create a vault led by this wallet (name 3-50 chars, description 10-250 chars, at least 100 USD)
179
+ - `vault_modify(vault_address:, allow_deposits: nil, always_close_on_withdraw: nil)` - Change vault settings (leader only); `nil` leaves a setting unchanged
180
+ - `vault_distribute(vault_address:, usd:)` - Distribute USD to followers (leader only); `usd: 0` closes the vault
181
+
182
+ ### Referrals and Profile
183
+
184
+ - `set_referrer(code:)` - Use a referral code
185
+ - `register_referrer(code:)` - Create your own referral code
186
+ - `claim_rewards` - Claim referral rewards
187
+ - `set_display_name(display_name:)` - Set the leaderboard name; `""` removes it
188
+
189
+ ### Agents and Builders
190
+
191
+ - `approve_agent(agent_address:, agent_name: nil)` - Authorize an agent wallet (user-signed)
192
+ - `approve_builder_fee(builder:, max_fee_rate:)` - Approve a builder fee, for example `max_fee_rate: '0.01%'` (user-signed)
193
+
194
+ ### Staking
195
+
196
+ - `token_delegate(validator:, wei:, is_undelegate:)` - Delegate or undelegate HYPE; `wei` is HYPE x 1e8 (user-signed)
197
+ - `c_deposit(wei:)` - Move HYPE from spot into staking; `wei` is HYPE x 1e8 (user-signed)
198
+ - `c_withdraw(wei:)` - Move HYPE from staking to spot; `wei` is HYPE x 1e8 (user-signed)
199
+ - `link_staking_user(user:, is_finalize:)` - Link staking and trading accounts: the trading user calls with `is_finalize: false`, the staking user finalizes with `true`; `user` is the other account (user-signed)
200
+ - `staking_link_disable_trading_user(trading_user:)` - Permanently disable a linked trading user. Irreversible (user-signed)
201
+
202
+ ### Account Modes
203
+
204
+ - `user_dex_abstraction(enabled:, user: nil)` - Enable or disable HIP-3 dex abstraction (user-signed)
205
+ - `agent_enable_dex_abstraction(vault_address: nil)` - Enable dex abstraction from an agent (enable only)
206
+ - `agent_set_abstraction(abstraction:, vault_address: nil)` - Set abstraction from an agent: `'u'` unified, `'p'` portfolio margin, `'i'` disabled
207
+ - `user_set_abstraction(user:, abstraction:)` - Set a user's abstraction: `'unifiedAccount'`, `'portfolioMargin'` or `'disabled'` (long form, unlike the agent action's short codes) (user-signed)
208
+ - `user_portfolio_margin(user:, enabled:)` - Enable or disable portfolio margin (user-signed)
209
+ - `use_big_blocks(enable:)` - Route the account's HyperEVM transactions to big blocks
210
+ - `spot_user(opt_out:)` - Opt out of (`true`) or into (`false`) spot dusting
211
+
212
+ ### Multi-Sig
213
+
214
+ - `convert_to_multi_sig_user(authorized_users:, threshold:)` - Turn this account into a multi-sig user (user-signed)
215
+ - `multi_sig(multi_sig_user:, inner_action:, signatures:, nonce: nil, vault_address: nil)` - Submit `inner_action` for a multi-sig user with co-signer signatures. `nonce` must equal the nonce every co-signer signed. See Multi-Sig Co-Signing below
216
+
217
+ ### Borrow/Lend (HIP-2)
218
+
219
+ - `borrow_lend(operation:, token:, amount: nil, vault_address: nil)` - `operation:` is `'supply'`, `'withdraw'`, `'repay'` or `'borrow'`; `token` is a token index; `amount: nil` uses the full position
220
+
221
+ ### HIP-3
222
+
223
+ - `hip3_liquidator_transfer(dex:, ntl:, is_deposit:)` - Deposit to or withdraw from a HIP-3 dex's backstop liquidator; `ntl` is in 1e-6 quote units, multiple of 1_000_000_000
224
+
225
+ ### Perp Deploy (HIP-3)
102
226
 
103
- ### Agent & Builder
227
+ HIP-3 deployer actions: each method signs one variant of the `perpDeploy` L1 action, which only the dex deployer (or a sub-deployer granted that variant) may send. Coins are full `dex:COIN` names (for example `"test:TEST0"`); the SDK never prefixes or resolves them. Coin-keyed Hash arguments are converted to `[coin, value]` pairs and sorted by coin for you. Decimal arguments take a String (sent verbatim) or a Numeric (normalized like prices). Integer arguments are never scaled: `max_gas` is in native-token wei (HYPE has 8 wei decimals), and open-interest caps and margin-tier `lower_bound` are in 1e-6 collateral units. `max_gas: 0` uses a reserve deployment at the current auction price. `expires_after` is honoured; there is no `vault_address:`. Related Info queries: `perp_deploy_auction_status`, `perp_dexs`, `perp_dex_limits`, `perp_dex_status`.
104
228
 
105
- - `approve_agent(agent_address:, agent_name:)` - Authorize an agent wallet to trade on behalf of this account
106
- - `approve_builder_fee(builder:, max_fee_rate:)` - Approve a builder fee rate for a builder address
107
- - `token_delegate(validator:, wei:, is_undelegate:)` - Delegate or undelegate HYPE tokens to a validator
229
+ - `perp_deploy_register_asset(dex:, coin:, sz_decimals:, oracle_px:, margin_table_id:, only_isolated:, max_gas: nil, schema: nil)` - Register an asset (legacy `registerAsset`, Python SDK parity); `max_gas: nil` bids the current auction price; `schema: { full_name:, collateral_token:, oracle_updater: nil }` also creates the dex on its first registration (`oracle_updater` is lowercased; an optional `is_star:` key is passed through)
230
+ - `perp_deploy_register_asset2(dex:, coin:, sz_decimals:, oracle_px:, margin_table_id:, margin_mode:, max_gas: nil, schema: nil)` - Register an asset with `margin_mode:` `'strictIsolated'`, `'noCross'` or `'normal'` (`registerAsset2`); other arguments as `perp_deploy_register_asset`
231
+ - `perp_deploy_set_oracle(dex:, oracle_pxs:, all_mark_pxs:, external_perp_pxs:)` - Push prices: `oracle_pxs` and `external_perp_pxs` are `{ coin => price }` (`external_perp_pxs` must cover every asset); `all_mark_pxs` is an Array of 0-2 such Hashes; at most one call per 2.5s
232
+ - `perp_deploy_set_funding_multipliers(multipliers:)` - Set funding multipliers: `{ coin => multiplier }` (0-10)
233
+ - `perp_deploy_set_funding_interest_rates(rates:)` - Set 8h funding interest rates: `{ coin => rate }` (-0.01 to 0.01)
234
+ - `perp_deploy_set_funding_clamps(clamps:)` - Set 8h funding clamps: `{ coin => clamp }` (0 to 0.01; default 0.0003)
235
+ - `perp_deploy_halt_trading(coin:, is_halted:)` - Halt (`true`) or resume (`false`) trading on an asset
236
+ - `perp_deploy_insert_margin_table(dex:, description:, margin_tiers:)` - Insert a margin table; `margin_tiers` is an Array of up to 3 `{ lower_bound:, max_leverage: }` Hashes (`lower_bound` in 1e-6 collateral units, `max_leverage` 1-50), sent in the given order
237
+ - `perp_deploy_set_margin_table_ids(margin_table_ids:)` - Assign margin tables: `{ coin => margin_table_id }` (non-zero Integer ids)
238
+ - `perp_deploy_set_margin_modes(margin_modes:)` - Set margin modes: `{ coin => mode }` with `'strictIsolated'`, `'noCross'` or `'normal'`
239
+ - `perp_deploy_set_open_interest_caps(caps:)` - Set open interest caps: `{ coin => cap }` in 1e-6 collateral units (at least 1_000_000); a `nil` cap removes the custom cap
240
+ - `perp_deploy_set_fee_recipient(dex:, fee_recipient:)` - Set the dex fee recipient address (lowercased)
241
+ - `perp_deploy_set_deployer_fees(fees:)` - Set per-asset deployer fees: `{ coin => { scale:, growth_mode: } }`; `scale` is a decimal (0-3, or below 10 with growth mode), `growth_mode` a Boolean; on mainnet at most one change per 30 days
242
+ - `perp_deploy_set_sub_deployers(dex:, sub_deployers:)` - Grant or revoke sub-deployer permissions: an Array of `{ variant:, user:, allowed: }` Hashes, sent in the given order; `variant` is a variant name String (for example `'setOracle'`) or a Hash (for example `{ hip3Star: 'order' }`) passed through verbatim; `user` is lowercased
243
+ - `perp_deploy_set_perp_annotation(coin:, category:, description:, display_name: nil, keywords: [])` - Annotate an asset: `category` up to 15 chars, `description` up to 400, `display_name` up to 9 (`nil` sends null), up to 2 `keywords` of up to 10 chars each
244
+ - `perp_deploy_disable_dex(dex:)` - Disable (shut down) a perp dex
108
245
 
109
- ### HIP-3 DEX Abstraction
246
+ ### Outcomes (HIP-4)
110
247
 
111
- HIP-3 DEX abstraction allows automatic collateral transfers when trading on builder-deployed perpetual DEXs.
248
+ - `split_outcome(outcome:, amount:)` - Split quote tokens into Yes and No shares
249
+ - `merge_outcome(outcome:, amount: nil)` - Merge Yes and No shares into quote tokens; `nil` merges the maximum
250
+ - `merge_question(question:, amount: nil)` - Merge Yes shares of every outcome of a question; `nil` merges the maximum
251
+ - `negate_outcome(question:, outcome:, amount:)` - Turn No shares of one outcome into Yes shares of the question's other outcomes
112
252
 
113
- - `user_dex_abstraction(enabled:, user: nil)` - Enable or disable DEX abstraction for an account (user-signed)
114
- - `agent_enable_dex_abstraction(vault_address: nil)` - Enable DEX abstraction via agent (L1 action, enable only)
253
+ ### Outcome Deploy (HIP-4)
115
254
 
116
- ### Other
255
+ Deployer actions for HIP-4 outcome venues. `keyword_to_value` takes a Hash or an Array of pairs; the SDK stringifies and sorts it by keyword before signing. Decimals (`deployer_fee_scale`, `settle_fraction`) accept a String (sent verbatim) or a Numeric. Settlements must echo the outcome's `name`, `description` and side names from `outcome_meta`. Responses are passed through unmodified, so check `status`.
117
256
 
118
- - `address` - Get the wallet address associated with the private key
257
+ - `activate_outcome_deployer(venue_name:)` - Activate this wallet as an outcome deployer and claim `venue_name` (2-4 lowercase letters); locks stake and reserves the venue permanently
258
+ - `deactivate_outcome_deployer` - Permanently deactivate this wallet as an outcome deployer (needs the minimum staking duration elapsed and no active outcomes)
259
+ - `register_standalone_outcome_from_template(venue:, template_id:, keyword_to_value:, deployer_fee_scale:)` - Deploy a standalone Yes/No outcome from a template; `deployer_fee_scale` is a decimal in [0, 10]
260
+ - `register_question_from_template(venue:, template_id:, keyword_to_value:, deployer_fee_scale:, named_outcomes:)` - Deploy a question and its named outcomes; `named_outcomes` is an Array of `{ template_id:, keyword_to_value: }` (order kept); the fee scale applies to every outcome of the question
261
+ - `register_and_associate_named_outcome_from_template(venue:, question:, template_id:, keyword_to_value:)` - Add one named outcome to a live template-deployed question
262
+ - `settle_outcome(venue:, outcome:, settle_fraction:, name:, description:, side_names:, details: '')` - Settle one outcome; `settle_fraction` is the first side's payout in [0, 1]; `side_names` is the two side names
263
+ - `settle_question(venue:, question:, name:, description:, settlements:)` - Settle all remaining named outcomes of a question (wire `settleQuestion2`); `settlements` is an Array of `{ outcome:, settle_fraction:, name:, description:, side_names:, details: '' }` (Symbol keys, order kept), exactly one with fraction `'1'`, the rest `'0'`
264
+ - `set_outcome_sub_deployers(venue:, changes:)` - Grant or revoke sub-deployer permissions; `changes` is an Array of `{ variant:, user:, allowed: }` with the camelCase operation name (`'settleQuestion'` authorizes `settle_question`); `user` is lowercased, order kept
119
265
 
120
- Order placement and management methods support an optional `vault_address:` parameter for vault trading.
266
+ ### Tokens and HyperEVM
121
267
 
122
- Order placement methods (`order`, `bulk_orders`, `market_order`, `market_close`) support an optional `builder:` parameter for builder fee integration. The builder is a Hash with `:b` (builder address) and `:f` (fee in tenths of a basis point).
268
+ - `finalize_evm_contract(token:, input:)` - Finalize a spot token's ERC-20 link; `input:` is `{ create: { nonce: n } }`, `'firstStorageSlot'` or `'customStorageSlot'`
269
+ - `authorize_aqav2_role(token:, role:)` - Authorize an AQAv2 role, `'technical'` or `'treasury'`
270
+
271
+ ### Spot Deploy (HIP-1)
272
+
273
+ All are L1 `spotDeploy` actions; `expires_after` is honored; no `vault_address`. Deploy order: `spot_deploy_register_token` → `spot_deploy_user_genesis` (repeatable; `spot_deploy_enable_freeze_privilege` must come before genesis) → `spot_deploy_genesis` → `spot_deploy_register_spot` → `spot_deploy_register_hyperliquidity`. Optional afterwards: fee share, quote token, annotation, label, EVM link (+ `finalize_evm_contract`). Related info: `spot_deploy_state(user)`, `spot_pair_deploy_auction_status`, `token_details`.
274
+
275
+ - `spot_deploy_register_token(token_name:, sz_decimals:, wei_decimals:, max_gas:, full_name: nil)` - Register a token via the deploy gas auction; `response.data` is the new token index
276
+ - `spot_deploy_user_genesis(token:, user_and_wei:, existing_token_and_wei:, blacklist_users: nil)` - Assign genesis balances (`[[address, wei]]`, `[[token, wei]]`); `blacklist_users` only when both lists are empty
277
+ - `spot_deploy_genesis(token:, max_supply:, no_hyperliquidity: false)` - Finalize genesis; wei amounts are Integer or String
278
+ - `spot_deploy_register_spot(base_token:, quote_token:)` - Register a spot pair; `response.data` is the spot index
279
+ - `spot_deploy_register_hyperliquidity(spot:, start_px:, order_sz:, n_orders:, n_seeded_levels: nil)` - Seed Hyperliquidity for a spot pair
280
+ - `spot_deploy_set_deployer_trading_fee_share(token:, share:)` - Set the deployer fee share (percent String, may only decrease)
281
+ - `spot_deploy_enable_freeze_privilege(token:)` - Enable freezing (before genesis)
282
+ - `spot_deploy_freeze_user(token:, user:, freeze:)` - Freeze or unfreeze a user
283
+ - `spot_deploy_revoke_freeze_privilege(token:)` - Permanently give up the freeze privilege
284
+ - `spot_deploy_enable_quote_token(token:)` - Make the token a permissionless quote token (irreversible)
285
+ - `spot_deploy_disable_quote_token(token:)` - Disable the token as a quote token
286
+ - `spot_deploy_request_evm_contract(token:, address:, evm_extra_wei_decimals:)` - Request an ERC-20 link; finish with `finalize_evm_contract`
287
+ - `spot_deploy_set_token_annotation(token:, category:, description:, keywords:, display_name: nil)` - Set the token annotation (once per day)
288
+ - `spot_deploy_set_deployer_label(label:)` - Set the deployer label (once per deployer)
289
+
290
+ ### Rate Limits and Nonces
291
+
292
+ - `reserve_request_weight(weight:, destination: nil)` - Buy extra request weight, optionally for another existing user
293
+ - `noop(nonce: nil, vault_address: nil)` - Consume a nonce without side effects
294
+
295
+ ### Validators
296
+
297
+ - `gossip_priority_bid(slot_id:, ip:, max_gas:, vault_address: nil)` - Bid for a gossip priority slot
298
+
299
+ Validator-operator L1 actions. Signed by the validator (or, for `c_signer_*`, its signer) key; no `vault_address:`; all support `expires_after`.
300
+
301
+ - `c_signer_jail_self` - Jail the signer's own validator (`CSignerAction`)
302
+ - `c_signer_unjail_self` - Unjail the signer's own validator (`CSignerAction`)
303
+ - `validator_l1_stream(risk_free_rate:)` - Validator vote on the aligned-quote-asset risk-free rate (e.g. `'0.04'` for 4%)
304
+ - `c_validator_register(node_ip:, name:, description:, delegations_disabled:, commission_bps:, signer:, unjailed:, initial_wei:)` - Register a validator (`CValidatorAction`)
305
+ - `c_validator_change_profile(unjailed:, node_ip: nil, name: nil, description: nil, disable_delegations: nil, commission_bps: nil, signer: nil)` - Change validator profile; `nil` fields are left unchanged
306
+ - `c_validator_unregister` - Unregister the validator (`CValidatorAction`)
307
+
308
+ ### HIP-3* Star (testnet-only)
309
+
310
+ Deployer/sub-deployer actions on HIP-3* venues (`perpDeploy` L1 action, `star` variant). Coins are dex-prefixed (`'mydex:BTC'`); `user`/`destination` are lowercased; `star_set_oracle` prices and `star_send_asset` amounts take String (sent verbatim) or Numeric (normalized); oracle prices are sorted by coin; `star_order` orders default to reduce-only.
311
+
312
+ - `star_modify_approval(dex:, user:, approved:)` - Add (`true`) or remove (`false`) a user on the venue's allow-list (removal clears the user's flags)
313
+ - `star_modify_backstop_liquidator_approval(dex:, user:, allowed:)` - Allow (`true`) or disallow (`false`) a user to deposit to/withdraw from the venue's backstop liquidator
314
+ - `star_set_reduce_only(dex:, user:, reduce_only:)` - Restrict (`true`) or unrestrict (`false`) an approved user to reducing positions on the venue
315
+ - `star_cancel(dex:, user:, cancels:)` - Cancel the user's resting orders; `cancels` is an Array of `{ coin:, oid: }`
316
+ - `star_cancel_all(dex:, user:, coins: nil)` - Cancel the user's orders and TWAPs on 1-10 `coins`, or on every coin when `coins` is `nil`
317
+ - `star_order(dex:, user:, orders:, grouping: 'na')` - Place orders for the user; `orders` take the `bulk_orders` hash shape (`:coin, :is_buy, :size, :limit_px, :order_type, :reduce_only, :cloid`) with `:reduce_only` defaulting to `true`
318
+ - `star_send_asset(dex:, user:, destination:, amount:)` - Send `amount` of collateral from `user` to `destination` on the same venue
319
+ - `star_set_oracle(dex:, oracle_pxs:)` - Set the venue's spot oracle prices from `{ coin => price }`
320
+
321
+ ### Client Utilities
322
+
323
+ - `address` - The signing wallet's address
324
+ - `expires_after=(value)` - Set or clear (`nil`) the ms expiry applied to later L1 actions
325
+ - `reload_metadata!` - Clear the cached asset metadata (call after new listings)
123
326
 
124
327
  ### Order Types
125
328
 
@@ -129,66 +332,85 @@ Order placement methods (`order`, `bulk_orders`, `market_order`, `market_close`)
129
332
 
130
333
  ### Trigger Orders (Stop Loss / Take Profit)
131
334
 
132
- Trigger orders execute when a price threshold is reached:
335
+ `order_type: { trigger: { trigger_px:, is_market:, tpsl: } }`, where `tpsl:` is `'sl'` (stop loss) or `'tp'` (take profit) and `is_market:` chooses a market or limit order on trigger.
133
336
 
134
- - `tpsl: 'sl'` - Stop loss
135
- - `tpsl: 'tp'` - Take profit
136
- - `is_market: true/false` - Execute as market or limit order when triggered
337
+ ### Builder Fees
137
338
 
138
- ### Client Order IDs (Cloid)
339
+ `order`, `bulk_orders`, `market_order` and `market_close` take `builder: { b: '0x...', f: 10 }`: builder address and fee in tenths of a basis point. The user must first call `approve_builder_fee`.
139
340
 
140
- Client order IDs must be 16 bytes in hex format (`0x` + 32 hex characters).
341
+ ## Multi-Sig Co-Signing
141
342
 
142
- Factory methods:
143
- - `Hyperliquid::Cloid.from_int(n)` - Create from integer (zero-padded)
144
- - `Hyperliquid::Cloid.from_str(s)` - Create from hex string
145
- - `Hyperliquid::Cloid.from_uuid(uuid)` - Create from UUID
146
- - `Hyperliquid::Cloid.random` - Generate random
343
+ Co-signers sign the inner action themselves and hand the signature (`{ r:, s:, v: }`) to the submitter, who calls `Exchange#multi_sig` with the same `nonce`. `signer:` is a `Hyperliquid::Signing::Signer.new(private_key:, testnet:)`.
147
344
 
148
- ## WebSocket
345
+ - `Hyperliquid::Signing::MultiSig.sign_as_co_signer_l1(signer:, inner_action:, multi_sig_user:, outer_signer:, nonce:, vault_address: nil, expires_after: nil)` - Co-sign an L1 inner action (orders, cancels, leverage)
346
+ - `Hyperliquid::Signing::MultiSig.sign_as_co_signer_user_signed(signer:, inner_action:, multi_sig_user:, outer_signer:, primary_type:, sign_types:)` - Co-sign a user-signed inner action; `primary_type:`/`sign_types:` are the inner action's EIP-712 type name and `Signing::EIP712` constant
149
347
 
150
- Real-time data streaming via WebSocket. No private key required.
348
+ ## Client Order IDs (Cloid)
151
349
 
152
- ### Connection
350
+ A client order id is 16 bytes, `0x` + 32 hex characters.
153
351
 
154
- - `ws.connect` - Connect to the WebSocket server (also called automatically on first `subscribe`)
155
- - `ws.connected?` - Check if the WebSocket is connected
156
- - `ws.close` - Disconnect and stop all background threads
352
+ - `Hyperliquid::Cloid.from_int(value)` - From an integer (zero-padded)
353
+ - `Hyperliquid::Cloid.from_str(value)` - From a hex string
354
+ - `Hyperliquid::Cloid.from_uuid(uuid)` - From a UUID
355
+ - `Hyperliquid::Cloid.random` - Random id
356
+ - `to_raw` - The `0x`-prefixed hex string
157
357
 
158
- ### Subscriptions
159
-
160
- - `ws.subscribe(subscription, &callback)` - Subscribe to a channel. Returns a subscription ID.
161
- - `ws.unsubscribe(id)` - Unsubscribe by subscription ID. Sends unsubscribe to server when the last callback for a channel is removed.
162
-
163
- ### Lifecycle Events
164
-
165
- - `ws.on(:open, &callback)` - Called when connection is established
166
- - `ws.on(:close, &callback)` - Called when connection is closed
167
- - `ws.on(:error, &callback)` - Called on connection error
358
+ ## WebSocket
168
359
 
169
- ### Monitoring
360
+ `sdk.ws` streams real-time data and needs no private key. It holds two independent connections: the main API WebSocket (`subscribe`) and the explorer WebSocket (`subscribe_explorer_block`, `subscribe_explorer_txs`). Each connects on first use. See [WS.md](WS.md) for threading, routing and reconnection.
170
361
 
171
- - `ws.dropped_message_count` - Number of messages dropped due to a full internal queue (callbacks too slow)
362
+ - `Hyperliquid::WS::Client.new(testnet: false, max_queue_size: 1024, reconnect: true, explorer_ws_url: nil)` - Standalone client; `explorer_ws_url: nil` disables the explorer methods (the SDK passes the right URL)
363
+ - `connect` - Open the main connection (`subscribe` calls it if needed)
364
+ - `subscribe(subscription, &callback)` - Subscribe to a main-API channel (table below); the block gets each message's `data`. Returns a subscription id. Raises `Hyperliquid::WebSocketError` for an unsupported type or a subscription that conflicts with an active one on an exclusive channel (see below)
365
+ - `subscribe_explorer_block(&)` - Stream new blocks; the block gets an Array of block summaries. Returns a subscription id
366
+ - `subscribe_explorer_txs(&)` - Stream new transactions; the block gets an Array of transactions. Returns a subscription id
367
+ - `unsubscribe(subscription_id)` - Remove a callback; the server unsubscribe is sent when a channel's last callback goes
368
+ - `close` - Close both connections and stop their threads
369
+ - `connected?` - Whether the main connection is open
370
+ - `explorer_connected?` - Whether the explorer connection is open
371
+ - `on(event, &callback)` - Lifecycle hook for `:open`, `:close` or `:error` on the main connection only (the explorer connection has no hooks). One callback per event; a new one replaces the old
372
+ - `dropped_message_count` - Main-connection messages dropped because the queue was full
373
+ - `explorer_dropped_message_count` - Explorer messages dropped because the queue was full
172
374
 
173
- ### Available Channels
375
+ ### Main API Channels
174
376
 
175
377
  | Channel | Subscription | Description |
176
378
  |---------|-------------|-------------|
177
379
  | `allMids` | `{ type: 'allMids' }` | Mid prices for all coins |
178
- | `l2Book` | `{ type: 'l2Book', coin: 'ETH' }` | Level 2 order book updates |
179
- | `trades` | `{ type: 'trades', coin: 'ETH' }` | Trade feed for a coin |
380
+ | `l2Book` | `{ type: 'l2Book', coin: 'ETH' }` | Order book updates; add `fast: true` for faster, shallower snapshots |
381
+ | `trades` | `{ type: 'trades', coin: 'ETH' }` | Trades for a coin |
180
382
  | `bbo` | `{ type: 'bbo', coin: 'ETH' }` | Best bid/offer for a coin |
181
- | `candle` | `{ type: 'candle', coin: 'ETH', interval: '1m' }` | Candlestick updates |
182
- | `orderUpdates` | `{ type: 'orderUpdates', user: '0x...' }` | Order status changes for a user |
183
- | `userEvents` | `{ type: 'userEvents', user: '0x...' }` | All events for a user (fills, liquidations, etc.) |
184
- | `userFills` | `{ type: 'userFills', user: '0x...' }` | Fill updates for a user |
185
- | `userFundings` | `{ type: 'userFundings', user: '0x...' }` | Funding payments for a user |
383
+ | `candle` | `{ type: 'candle', coin: 'ETH', interval: '1m' }` | Candle updates |
384
+ | `orderUpdates` | `{ type: 'orderUpdates', user: '0x...' }` | A user's order status changes |
385
+ | `userEvents` | `{ type: 'userEvents', user: '0x...' }` | A user's fills, funding, liquidations and other events (server channel `user`) |
386
+ | `userFills` | `{ type: 'userFills', user: '0x...' }` (optional `aggregateByTime: true`) | A user's fills; `aggregateByTime: true` merges partial fills of one order |
387
+ | `userFundings` | `{ type: 'userFundings', user: '0x...' }` | A user's funding payments |
388
+ | `userNonFundingLedgerUpdates` | `{ type: 'userNonFundingLedgerUpdates', user: '0x...' }` | A user's non-funding ledger updates (deposits, withdrawals, transfers, liquidations) |
389
+ | `userTwapSliceFills` | `{ type: 'userTwapSliceFills', user: '0x...' }` | A user's TWAP slice fills |
390
+ | `userTwapHistory` | `{ type: 'userTwapHistory', user: '0x...' }` | A user's TWAP order history |
391
+ | `userHistoricalOrders` | `{ type: 'userHistoricalOrders', user: '0x...' }` | A user's historical orders |
392
+ | `allDexsClearinghouseState` | `{ type: 'allDexsClearinghouseState', user: '0x...' }` | A user's perp clearinghouse state on every dex |
393
+ | `webData3` | `{ type: 'webData3', user: '0x...' }` | Aggregate user state (`userState`, `perpDexStates`) as used by the web frontend |
394
+ | `clearinghouseState` | `{ type: 'clearinghouseState', user: '0x...' }` (optional `dex: 'xyz'`; omit for the main dex) | A user's perp clearinghouse state (positions, margin) on one dex |
395
+ | `openOrders` | `{ type: 'openOrders', user: '0x...' }` (optional `dex: 'xyz'`; omit for the main dex) | A user's open orders on one dex |
396
+ | `twapStates` | `{ type: 'twapStates', user: '0x...' }` (optional `dex: 'xyz'`; omit for the main dex) | A user's active TWAP orders on one dex |
397
+ | `spotState` | `{ type: 'spotState', user: '0x...' }` (optional `ignorePortfolioMargin: true`) | A user's spot balances |
398
+ | `notification` | `{ type: 'notification', user: '0x...' }` | A user's notifications (event-driven, no snapshot) |
399
+ | `activeAssetCtx` | `{ type: 'activeAssetCtx', coin: 'BTC' }` (perp, HIP-3 `'xyz:XYZ100'`, or spot `'@107'`/`'PURR/USDC'`) | One asset's context (mark/oracle/mid price, funding, open interest, volume) |
400
+ | `activeAssetData` | `{ type: 'activeAssetData', user: '0x...', coin: 'BTC' }` | A user's leverage, max trade sizes and available-to-trade for one perp coin |
401
+ | `assetCtxs` | `{ type: 'assetCtxs' }` (optional `dex: 'xyz'`; omit for the main dex) | Asset contexts of every perp on one dex (`dex`, `ctxs`) |
402
+ | `allDexsAssetCtxs` | `{ type: 'allDexsAssetCtxs' }` | Perp asset contexts for every dex (`ctxs`: Array of `[dex, ctxs]`) |
403
+ | `spotAssetCtxs` | `{ type: 'spotAssetCtxs' }` | Asset contexts of every spot pair (the data is an Array) |
404
+ | `outcomeMetaUpdates` | `{ type: 'outcomeMetaUpdates' }` | HIP-4 outcome metadata changes (event-driven, no snapshot; `updates`) |
405
+ | `fastAssetCtxs` | `{ type: 'fastAssetCtxs' }` | Mark/mid prices for all assets (all dexes); first message is a full snapshot, later messages only changed coins/fields. Decoded from base64 + raw DEFLATE automatically |
406
+
407
+ `orderUpdates`, `userEvents`, `notification`: one user per `WS::Client` (payload carries no user); `spotState`/`userFills`: one `ignorePortfolioMargin`/`aggregateByTime` setting per user per client; conflicting subscriptions raise `WebSocketError`. Use a second `WS::Client` for another user. Spot coins on `activeAssetCtx` arrive on channel `activeSpotAssetCtx` and are routed transparently; `{ type: 'activeSpotAssetCtx' }` is not a subscription type.
186
408
 
187
409
  Candle intervals: `1m`, `3m`, `5m`, `15m`, `30m`, `1h`, `2h`, `4h`, `8h`, `12h`, `1d`, `3d`, `1w`, `1M`
188
410
 
189
- ### Configuration
411
+ ### Explorer Channels
190
412
 
191
- `Hyperliquid::WS::Client.new` accepts:
192
- - `testnet:` (Boolean, default: false) - Use testnet WebSocket endpoint
193
- - `max_queue_size:` (Integer, default: 1024) - Max messages buffered before dropping
194
- - `reconnect:` (Boolean, default: true) - Auto-reconnect on unexpected disconnect
413
+ | Channel | Method | Callback receives |
414
+ |---------|--------|-------------------|
415
+ | `explorerBlock` | `subscribe_explorer_block` | Array of blocks (`height`, `blockTime`, `hash`, `numTxs`, `proposer`) |
416
+ | `explorerTxs` | `subscribe_explorer_txs` | Array of transactions (`action`, `block`, `error`, `hash`, `time`, `user`) |