hyperliquid 0.1.1 → 0.3.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.
- checksums.yaml +4 -4
- data/.rubocop.yml +4 -0
- data/CHANGELOG.md +10 -2
- data/README.md +232 -60
- data/lib/hyperliquid/info.rb +299 -18
- data/lib/hyperliquid/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: f5ac9afd372d7362c7d984fa21d21ef3822a2b3a2beebeb2067f088055be2b7b
|
|
4
|
+
data.tar.gz: b45bb221a66d07fa76d5f53375c24aef11f55a421cf0f33c038c53cbf49b797e
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: d55505a3ebf3595363542005aa5b6e3400678b22bd6689ffb38318f4f8450362d1e3ae2a8041a877dab82d1343f28bc48ba61f6a50a02dd81fbd2989bcad2660
|
|
7
|
+
data.tar.gz: 17e7a2df87f5f30b3ce79f6767ba5da9a95d097990b2b990ddc7d71bee2600c15630c3b3f96bcf350a151479eebd8520eb38f74949bad2e9fc6026a23d740d80
|
data/.rubocop.yml
CHANGED
|
@@ -10,6 +10,10 @@ Metrics/MethodLength:
|
|
|
10
10
|
Metrics/AbcSize:
|
|
11
11
|
Max: 25
|
|
12
12
|
|
|
13
|
+
# Disable class length checks so rubocop doesn't complain that we implement all of Hyperliquid's endpoints
|
|
14
|
+
Metrics/ClassLength:
|
|
15
|
+
Enabled: false
|
|
16
|
+
|
|
13
17
|
# Allow longer blocks in specs - this is normal for tests
|
|
14
18
|
Metrics/BlockLength:
|
|
15
19
|
Exclude:
|
data/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,13 @@
|
|
|
1
|
-
## [
|
|
1
|
+
## [Ruby Hyperliquid SDK Changelog]
|
|
2
2
|
|
|
3
3
|
## [0.1.0] - 2025-08-21
|
|
4
4
|
|
|
5
|
-
- Initial release
|
|
5
|
+
- Initial release which includes info endpoints for market and user perps data
|
|
6
|
+
|
|
7
|
+
## [0.1.1] - 2025-09-23
|
|
8
|
+
|
|
9
|
+
- Fixed retry logic, make retry logic disabled by default
|
|
10
|
+
|
|
11
|
+
## [0.2.0] - 2025-09-24
|
|
12
|
+
|
|
13
|
+
- Add info endpoints for user spot data
|
data/README.md
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
A Ruby SDK for interacting with the Hyperliquid decentralized exchange API.
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
The latest version is v0.2.0 - a read-only implementation focusing on the Info API endpoints for market data, user information, and order book data.
|
|
6
6
|
|
|
7
7
|
## Installation
|
|
8
8
|
|
|
@@ -37,54 +37,254 @@ testnet_sdk = Hyperliquid.new(testnet: true)
|
|
|
37
37
|
info = sdk.info
|
|
38
38
|
```
|
|
39
39
|
|
|
40
|
-
###
|
|
41
|
-
|
|
42
|
-
The SDK provides access to
|
|
43
|
-
|
|
44
|
-
####
|
|
40
|
+
### Supported APIs
|
|
41
|
+
|
|
42
|
+
The SDK provides access to the following Hyperliquid APIs:
|
|
43
|
+
|
|
44
|
+
#### Info Methods
|
|
45
|
+
- `all_mids()` - Retrieve mids for all coins
|
|
46
|
+
- `open_orders(user)` - Retrieve a user's open orders
|
|
47
|
+
- `frontend_open_orders(user, dex: nil)` - Retrieve a user's open orders with additional frontend info
|
|
48
|
+
- `user_fills(user)` - Retrieve a user's fills
|
|
49
|
+
- `user_fills_by_time(user, start_time, end_time = nil)` - Retrieve a user's fills by time (optional end time)
|
|
50
|
+
- `user_rate_limit(user)` - Query user rate limits
|
|
51
|
+
- `order_status(user, oid)` - Query order status by order id (oid)
|
|
52
|
+
- `order_status_by_cloid(user, cloid)` - Query order status by client order id (cloid)
|
|
53
|
+
- `l2_book(coin)` - L2 book snapshot (Perpetuals and Spot)
|
|
54
|
+
- `candles_snapshot(coin, interval, start_time, end_time)` - Candle snapshot (Perpetuals and Spot)
|
|
55
|
+
- `max_builder_fee(user, builder)` - Check builder fee approval
|
|
56
|
+
- `historical_orders(user, start_time = nil, end_time = nil)` - Retrieve a user's historical orders
|
|
57
|
+
- `user_twap_slice_fills(user, start_time = nil, end_time = nil)` - Retrieve a user's TWAP slice fills
|
|
58
|
+
- `user_subaccounts(user)` - Retrieve a user's subaccounts
|
|
59
|
+
- `vault_details(vault_address, user = nil)` - Retrieve details for a vault
|
|
60
|
+
- `user_vault_equities(user)` - Retrieve a user's vault deposits
|
|
61
|
+
- `user_role(user)` - Query a user's role
|
|
62
|
+
- `portfolio(user)` - Query a user's portfolio
|
|
63
|
+
- `referral(user)` - Query a user's referral information
|
|
64
|
+
- `user_fees(user)` - Query a user's fees and fee schedule
|
|
65
|
+
- `delegations(user)` - Query a user's staking delegations
|
|
66
|
+
- `delegator_summary(user)` - Query a user's staking summary
|
|
67
|
+
- `delegator_history(user)` - Query a user's staking history
|
|
68
|
+
- `delegator_rewards(user)` - Query a user's staking rewards
|
|
69
|
+
|
|
70
|
+
##### Perpetuals Methods
|
|
71
|
+
- `perp_dexs()` - Retrieve all perpetual DEXs
|
|
72
|
+
- `meta(dex: nil)` - Get asset metadata (optionally for a specific perp DEX)
|
|
73
|
+
- `meta_and_asset_ctxs()` - Get extended asset metadata
|
|
74
|
+
- `user_state(user, dex: nil)` - Retrieve user's perpetuals account summary (optionally for a specific perp DEX)
|
|
75
|
+
- `predicted_fundings()` - Retrieve predicted funding rates across venues
|
|
76
|
+
- `perps_at_open_interest_cap()` - Query perps at open interest caps
|
|
77
|
+
- `perp_deploy_auction_status()` - Retrieve Perp Deploy Auction status
|
|
78
|
+
- `active_asset_data(user, coin)` - Retrieve a user's active asset data for a coin
|
|
79
|
+
- `perp_dex_limits(dex)` - Retrieve builder-deployed perp market limits for a DEX
|
|
80
|
+
- `user_funding(user, start_time, end_time = nil)` - Retrieve a user's funding history (optional end time)
|
|
81
|
+
- `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)
|
|
82
|
+
- `funding_history(coin, start_time, end_time = nil)` - Retrieve historical funding rates (optional end time)
|
|
83
|
+
|
|
84
|
+
##### Spot Methods
|
|
85
|
+
- `spot_meta()` - Retrieve spot metadata (tokens and universe)
|
|
86
|
+
- `spot_meta_and_asset_ctxs()` - Retrieve spot metadata and asset contexts
|
|
87
|
+
- `spot_balances(user)` - Retrieve a user's spot token balances
|
|
88
|
+
- `spot_deploy_state(user)` - Retrieve Spot Deploy Auction information
|
|
89
|
+
- `spot_pair_deploy_auction_status()` - Retrieve Spot Pair Deploy Auction status
|
|
90
|
+
- `token_details(token_id)` - Retrieve information about a token by tokenId
|
|
91
|
+
|
|
92
|
+
#### Examples: Info
|
|
45
93
|
|
|
46
94
|
```ruby
|
|
47
|
-
#
|
|
95
|
+
# Retrieve mids for all coins
|
|
48
96
|
mids = sdk.info.all_mids
|
|
49
97
|
# => { "BTC" => "50000", "ETH" => "3000", ... }
|
|
50
98
|
|
|
51
|
-
|
|
52
|
-
meta = sdk.info.meta
|
|
53
|
-
# => { "universe" => [...] }
|
|
99
|
+
user_address = "0x..."
|
|
54
100
|
|
|
55
|
-
#
|
|
56
|
-
|
|
57
|
-
# => { "
|
|
101
|
+
# Retrieve a user's open orders
|
|
102
|
+
orders = sdk.info.open_orders(user_address)
|
|
103
|
+
# => [{ "coin" => "BTC", "sz" => "0.1", "px" => "50000", "side" => "A" }]
|
|
104
|
+
|
|
105
|
+
# Retrieve a user's open orders with additional frontend info
|
|
106
|
+
frontend_orders = sdk.info.frontend_open_orders(user_address)
|
|
107
|
+
# => [{ "coin" => "BTC", "isTrigger" => false, ... }]
|
|
108
|
+
|
|
109
|
+
# Retrieve a user's fills
|
|
110
|
+
fills = sdk.info.user_fills(user_address)
|
|
111
|
+
# => [{ "coin" => "BTC", "sz" => "0.1", "px" => "50000", "side" => "A", "time" => 1234567890 }]
|
|
112
|
+
|
|
113
|
+
# Retrieve a user's fills by time
|
|
114
|
+
start_time_ms = 1_700_000_000_000
|
|
115
|
+
end_time_ms = start_time_ms + 86_400_000
|
|
116
|
+
fills_by_time = sdk.info.user_fills_by_time(user_address, start_time_ms, end_time_ms)
|
|
117
|
+
# => [{ "coin" => "ETH", "px" => "3000", "time" => start_time_ms }, ...]
|
|
58
118
|
|
|
59
|
-
#
|
|
119
|
+
# Query user rate limits
|
|
120
|
+
rate_limit = sdk.info.user_rate_limit(user_address)
|
|
121
|
+
# => { "nRequestsUsed" => 100, "nRequestsCap" => 10000 }
|
|
122
|
+
|
|
123
|
+
# Query order status by oid
|
|
124
|
+
order_id = 12345
|
|
125
|
+
status_by_oid = sdk.info.order_status(user_address, order_id)
|
|
126
|
+
# => { "status" => "filled", ... }
|
|
127
|
+
|
|
128
|
+
# Query order status by cloid
|
|
129
|
+
cloid = "client-order-id-123"
|
|
130
|
+
status_by_cloid = sdk.info.order_status_by_cloid(user_address, cloid)
|
|
131
|
+
# => { "status" => "cancelled", ... }
|
|
132
|
+
|
|
133
|
+
# L2 order book snapshot
|
|
60
134
|
book = sdk.info.l2_book("BTC")
|
|
61
135
|
# => { "coin" => "BTC", "levels" => [[asks], [bids]], "time" => ... }
|
|
62
136
|
|
|
63
|
-
#
|
|
64
|
-
candles = sdk.info.candles_snapshot("BTC", "1h",
|
|
137
|
+
# Candle snapshot
|
|
138
|
+
candles = sdk.info.candles_snapshot("BTC", "1h", start_time_ms, end_time_ms)
|
|
65
139
|
# => [{ "t" => ..., "o" => "50000", "h" => "51000", "l" => "49000", "c" => "50500", "v" => "100" }]
|
|
140
|
+
|
|
141
|
+
# Check builder fee approval
|
|
142
|
+
builder_address = "0x..."
|
|
143
|
+
fee_approval = sdk.info.max_builder_fee(user_address, builder_address)
|
|
144
|
+
# => { "approved" => true, ... }
|
|
145
|
+
|
|
146
|
+
# Retrieve a user's historical orders
|
|
147
|
+
hist_orders = sdk.info.historical_orders(user_address)
|
|
148
|
+
# => [{ "oid" => 123, "coin" => "BTC", ... }]
|
|
149
|
+
hist_orders_ranged = sdk.info.historical_orders(user_address, start_time_ms, end_time_ms)
|
|
150
|
+
# => []
|
|
151
|
+
|
|
152
|
+
# Retrieve a user's TWAP slice fills
|
|
153
|
+
twap_fills = sdk.info.user_twap_slice_fills(user_address)
|
|
154
|
+
# => [{ "sliceId" => 1, "coin" => "ETH", "sz" => "1.0" }, ...]
|
|
155
|
+
twap_fills_ranged = sdk.info.user_twap_slice_fills(user_address, start_time_ms, end_time_ms)
|
|
156
|
+
# => []
|
|
157
|
+
|
|
158
|
+
# Retrieve a user's subaccounts
|
|
159
|
+
subaccounts = sdk.info.user_subaccounts(user_address)
|
|
160
|
+
# => ["0x1111...", ...]
|
|
161
|
+
|
|
162
|
+
# Retrieve details for a vault
|
|
163
|
+
vault_addr = "0x..."
|
|
164
|
+
vault = sdk.info.vault_details(vault_addr)
|
|
165
|
+
# => { "vaultAddress" => vault_addr, ... }
|
|
166
|
+
vault_with_user = sdk.info.vault_details(vault_addr, user_address)
|
|
167
|
+
# => { "vaultAddress" => vault_addr, "user" => user_address, ... }
|
|
168
|
+
|
|
169
|
+
# Retrieve a user's vault deposits
|
|
170
|
+
vault_deposits = sdk.info.user_vault_equities(user_address)
|
|
171
|
+
# => [{ "vaultAddress" => "0x...", "equity" => "123.45" }, ...]
|
|
172
|
+
|
|
173
|
+
# Query a user's role
|
|
174
|
+
role = sdk.info.user_role(user_address)
|
|
175
|
+
# => { "role" => "tradingUser" }
|
|
176
|
+
|
|
177
|
+
# Query a user's portfolio
|
|
178
|
+
portfolio = sdk.info.portfolio(user_address)
|
|
179
|
+
# => [["day", { "pnlHistory" => [...], "vlm" => "0.0" }], ...]
|
|
180
|
+
|
|
181
|
+
# Query a user's referral information
|
|
182
|
+
referral = sdk.info.referral(user_address)
|
|
183
|
+
# => { "referredBy" => { "referrer" => "0x..." }, ... }
|
|
184
|
+
|
|
185
|
+
# Query a user's fees
|
|
186
|
+
fees = sdk.info.user_fees(user_address)
|
|
187
|
+
# => { "userAddRate" => "0.0001", "feeSchedule" => { ... } }
|
|
188
|
+
|
|
189
|
+
# Query a user's staking delegations
|
|
190
|
+
delegations = sdk.info.delegations(user_address)
|
|
191
|
+
# => [{ "validator" => "0x...", "amount" => "100.0" }, ...]
|
|
192
|
+
|
|
193
|
+
# Query a user's staking summary
|
|
194
|
+
summary = sdk.info.delegator_summary(user_address)
|
|
195
|
+
# => { "delegated" => "12060.16529862", ... }
|
|
196
|
+
|
|
197
|
+
# Query a user's staking history
|
|
198
|
+
history = sdk.info.delegator_history(user_address)
|
|
199
|
+
# => [{ "time" => 1_736_726_400_073, "delta" => { ... } }, ...]
|
|
200
|
+
|
|
201
|
+
# Query a user's staking rewards
|
|
202
|
+
rewards = sdk.info.delegator_rewards(user_address)
|
|
203
|
+
# => [{ "time" => 1_736_726_400_073, "source" => "delegation", "totalAmount" => "0.123" }, ...]
|
|
66
204
|
```
|
|
67
205
|
|
|
68
|
-
|
|
206
|
+
Note: `l2_book` and `candles_snapshot` work for both Perpetuals and Spot. For spot, use `"{BASE}/USDC"` when available (e.g., `"PURR/USDC"`). Otherwise, use the index alias `"@{index}"` from `spot_meta["universe"]`.
|
|
207
|
+
|
|
208
|
+
##### Examples: Perpetuals
|
|
69
209
|
|
|
70
210
|
```ruby
|
|
71
|
-
|
|
211
|
+
# Retrieve all perpetual DEXs
|
|
212
|
+
perp_dexs = sdk.info.perp_dexs
|
|
213
|
+
# => [nil, { "name" => "test", "full_name" => "test dex", ... }]
|
|
72
214
|
|
|
73
|
-
#
|
|
74
|
-
|
|
75
|
-
# =>
|
|
215
|
+
# Retrieve perpetuals metadata (optionally for a specific perp dex)
|
|
216
|
+
meta = sdk.info.meta
|
|
217
|
+
# => { "universe" => [...] }
|
|
218
|
+
meta = sdk.info.meta(dex: "perp-dex-name")
|
|
219
|
+
# => { "universe" => [...] }
|
|
76
220
|
|
|
77
|
-
#
|
|
78
|
-
|
|
79
|
-
# =>
|
|
221
|
+
# Retrieve perpetuals asset contexts (includes mark price, current funding, open interest, etc.)
|
|
222
|
+
meta_ctxs = sdk.info.meta_and_asset_ctxs
|
|
223
|
+
# => { "universe" => [...], "assetCtxs" => [...] }
|
|
80
224
|
|
|
81
|
-
#
|
|
225
|
+
# Retrieve user's perpetuals account summary (optionally for a specific perp dex)
|
|
82
226
|
state = sdk.info.user_state(user_address)
|
|
83
227
|
# => { "assetPositions" => [...], "marginSummary" => {...} }
|
|
228
|
+
state = sdk.info.user_state(user_address, dex: "perp-dex-name")
|
|
229
|
+
# => { "assetPositions" => [...], "marginSummary" => {...} }
|
|
230
|
+
|
|
231
|
+
# Retrieve a user's funding history or non-funding ledger updates (optional end_time)
|
|
232
|
+
funding = sdk.info.user_funding(user_address, start_time)
|
|
233
|
+
# => [{ "delta" => { "type" => "funding", ... }, "time" => ... }]
|
|
234
|
+
funding = sdk.info.user_funding(user_address, start_time, end_time)
|
|
235
|
+
# => [{ "delta" => { "type" => "funding", ... }, "time" => ... }]
|
|
236
|
+
|
|
237
|
+
# Retrieve historical funding rates
|
|
238
|
+
hist = sdk.info.funding_history("ETH", start_time)
|
|
239
|
+
# => [{ "coin" => "ETH", "fundingRate" => "...", "time" => ... }]
|
|
240
|
+
|
|
241
|
+
# Retrieve predicted funding rates for different venues
|
|
242
|
+
pred = sdk.info.predicted_fundings
|
|
243
|
+
# => [["AVAX", [["HlPerp", { "fundingRate" => "0.0000125", "nextFundingTime" => ... }], ...]], ...]
|
|
244
|
+
|
|
245
|
+
# Query perps at open interest caps
|
|
246
|
+
oi_capped = sdk.info.perps_at_open_interest_cap
|
|
247
|
+
# => ["BADGER", "CANTO", ...]
|
|
248
|
+
|
|
249
|
+
# Retrieve information about the Perp Deploy Auction
|
|
250
|
+
auction = sdk.info.perp_deploy_auction_status
|
|
251
|
+
# => { "startTimeSeconds" => ..., "durationSeconds" => ..., "startGas" => "500.0", ... }
|
|
252
|
+
|
|
253
|
+
# Retrieve User's Active Asset Data
|
|
254
|
+
aad = sdk.info.active_asset_data(user_address, "APT")
|
|
255
|
+
# => { "user" => user_address, "coin" => "APT", "leverage" => { "type" => "cross", "value" => 3 }, ... }
|
|
256
|
+
|
|
257
|
+
# Retrieve Builder-Deployed Perp Market Limits
|
|
258
|
+
limits = sdk.info.perp_dex_limits("builder-dex")
|
|
259
|
+
# => { "totalOiCap" => "10000000.0", "oiSzCapPerPerp" => "...", ... }
|
|
260
|
+
```
|
|
261
|
+
|
|
262
|
+
##### Examples: Spot
|
|
263
|
+
|
|
264
|
+
```ruby
|
|
265
|
+
# Retrieve spot metadata
|
|
266
|
+
spot_meta = sdk.info.spot_meta
|
|
267
|
+
# => { "tokens" => [...], "universe" => [...] }
|
|
84
268
|
|
|
85
|
-
#
|
|
86
|
-
|
|
87
|
-
# => { "
|
|
269
|
+
# Retrieve spot asset contexts
|
|
270
|
+
spot_meta_ctxs = sdk.info.spot_meta_and_asset_ctxs
|
|
271
|
+
# => [ { "tokens" => [...], "universe" => [...] }, [ { "midPx" => "...", ... } ] ]
|
|
272
|
+
|
|
273
|
+
# Retrieve a user's token balances
|
|
274
|
+
balances = sdk.info.spot_balances(user_address)
|
|
275
|
+
# => { "balances" => [{ "coin" => "USDC", "token" => 0, "total" => "..." }, ...] }
|
|
276
|
+
|
|
277
|
+
# Retrieve information about the Spot Deploy Auction
|
|
278
|
+
deploy_state = sdk.info.spot_deploy_state(user_address)
|
|
279
|
+
# => { "states" => [...], "gasAuction" => { ... } }
|
|
280
|
+
|
|
281
|
+
# Retrieve information about the Spot Pair Deploy Auction
|
|
282
|
+
pair_status = sdk.info.spot_pair_deploy_auction_status
|
|
283
|
+
# => { "startTimeSeconds" => ..., "durationSeconds" => ..., "startGas" => "...", ... }
|
|
284
|
+
|
|
285
|
+
# Retrieve information about a token by onchain id in 34-character hexadecimal format
|
|
286
|
+
details = sdk.info.token_details("0x00000000000000000000000000000000")
|
|
287
|
+
# => { "name" => "TEST", "maxSupply" => "...", "midPx" => "...", ... }
|
|
88
288
|
```
|
|
89
289
|
|
|
90
290
|
### Configuration
|
|
@@ -154,34 +354,6 @@ Available error classes:
|
|
|
154
354
|
- `Hyperliquid::NetworkError` - Connection issues
|
|
155
355
|
- `Hyperliquid::TimeoutError` - Request timeouts
|
|
156
356
|
|
|
157
|
-
## API Reference
|
|
158
|
-
|
|
159
|
-
### Hyperliquid.new(options = {})
|
|
160
|
-
|
|
161
|
-
Creates a new SDK instance.
|
|
162
|
-
|
|
163
|
-
**Parameters:**
|
|
164
|
-
- `testnet` (Boolean) - Use testnet instead of mainnet (default: false)
|
|
165
|
-
- `timeout` (Integer) - Request timeout in seconds (default: 30)
|
|
166
|
-
- `retry_enabled` (Boolean) - Enable automatic retry logic for transient failures (default: false)
|
|
167
|
-
|
|
168
|
-
### Info API Methods
|
|
169
|
-
|
|
170
|
-
All Info methods return parsed JSON responses from the Hyperliquid API.
|
|
171
|
-
|
|
172
|
-
#### Market Data Methods
|
|
173
|
-
- `all_mids()` - Get all market mid prices
|
|
174
|
-
- `meta()` - Get asset metadata
|
|
175
|
-
- `meta_and_asset_ctxs()` - Get extended asset metadata
|
|
176
|
-
- `l2_book(coin)` - Get L2 order book for a coin
|
|
177
|
-
- `candles_snapshot(coin, interval, start_time, end_time)` - Get candlestick data
|
|
178
|
-
|
|
179
|
-
#### User Data Methods
|
|
180
|
-
- `open_orders(user)` - Get user's open orders
|
|
181
|
-
- `user_fills(user)` - Get user's fill history
|
|
182
|
-
- `user_state(user)` - Get user's trading state
|
|
183
|
-
- `order_status(user, oid)` - Get order status
|
|
184
|
-
|
|
185
357
|
## Development
|
|
186
358
|
|
|
187
359
|
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
|
@@ -208,11 +380,11 @@ rake rubocop
|
|
|
208
380
|
|
|
209
381
|
## Roadmap
|
|
210
382
|
|
|
211
|
-
|
|
383
|
+
The latest version implements read-only Info API support. Future versions will include:
|
|
212
384
|
|
|
213
|
-
-
|
|
214
|
-
-
|
|
215
|
-
-
|
|
385
|
+
- Trading API (place orders, cancel orders, etc.)
|
|
386
|
+
- WebSocket support for real-time data
|
|
387
|
+
- Advanced trading features
|
|
216
388
|
|
|
217
389
|
## Contributing
|
|
218
390
|
|
data/lib/hyperliquid/info.rb
CHANGED
|
@@ -7,6 +7,10 @@ module Hyperliquid
|
|
|
7
7
|
@client = client
|
|
8
8
|
end
|
|
9
9
|
|
|
10
|
+
# ============================
|
|
11
|
+
# Info
|
|
12
|
+
# ============================
|
|
13
|
+
|
|
10
14
|
# Get all market mid prices
|
|
11
15
|
# @return [Hash] Hash containing mid prices for all markets
|
|
12
16
|
def all_mids
|
|
@@ -15,9 +19,22 @@ module Hyperliquid
|
|
|
15
19
|
|
|
16
20
|
# Get a user's open orders
|
|
17
21
|
# @param user [String] Wallet address
|
|
22
|
+
# @param dex [String, nil] Optional perp dex name
|
|
18
23
|
# @return [Array] Array of open orders for the user
|
|
19
|
-
def open_orders(user)
|
|
20
|
-
|
|
24
|
+
def open_orders(user, dex: nil)
|
|
25
|
+
body = { type: 'openOrders', user: user }
|
|
26
|
+
body[:dex] = dex if dex
|
|
27
|
+
@client.post(Constants::INFO_ENDPOINT, body)
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
# Get a user's open orders with additional frontend info
|
|
31
|
+
# @param user [String] Wallet address
|
|
32
|
+
# @param dex [String, nil] Optional perp dex name
|
|
33
|
+
# @return [Array]
|
|
34
|
+
def frontend_open_orders(user, dex: nil)
|
|
35
|
+
body = { type: 'frontendOpenOrders', user: user }
|
|
36
|
+
body[:dex] = dex if dex
|
|
37
|
+
@client.post(Constants::INFO_ENDPOINT, body)
|
|
21
38
|
end
|
|
22
39
|
|
|
23
40
|
# Get a user's fill history
|
|
@@ -27,6 +44,24 @@ module Hyperliquid
|
|
|
27
44
|
@client.post(Constants::INFO_ENDPOINT, { type: 'userFills', user: user })
|
|
28
45
|
end
|
|
29
46
|
|
|
47
|
+
# Get a user's fills within a time range
|
|
48
|
+
# @param user [String] Wallet address
|
|
49
|
+
# @param start_time [Integer] Start timestamp in milliseconds
|
|
50
|
+
# @param end_time [Integer, nil] Optional end timestamp in milliseconds
|
|
51
|
+
# @return [Array]
|
|
52
|
+
def user_fills_by_time(user, start_time, end_time = nil)
|
|
53
|
+
body = { type: 'userFillsByTime', user: user, startTime: start_time }
|
|
54
|
+
body[:endTime] = end_time if end_time
|
|
55
|
+
@client.post(Constants::INFO_ENDPOINT, body)
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
# Query user rate limits and usage
|
|
59
|
+
# @param user [String] Wallet address
|
|
60
|
+
# @return [Hash]
|
|
61
|
+
def user_rate_limit(user)
|
|
62
|
+
@client.post(Constants::INFO_ENDPOINT, { type: 'userRateLimit', user: user })
|
|
63
|
+
end
|
|
64
|
+
|
|
30
65
|
# Get order status by order ID
|
|
31
66
|
# @param user [String] Wallet address
|
|
32
67
|
# @param oid [Integer] Order ID
|
|
@@ -35,23 +70,12 @@ module Hyperliquid
|
|
|
35
70
|
@client.post(Constants::INFO_ENDPOINT, { type: 'orderStatus', user: user, oid: oid })
|
|
36
71
|
end
|
|
37
72
|
|
|
38
|
-
# Get
|
|
73
|
+
# Get order status by client order ID (cloid)
|
|
39
74
|
# @param user [String] Wallet address
|
|
40
|
-
# @
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
# Get metadata for all assets
|
|
46
|
-
# @return [Hash] Metadata for all tradable assets
|
|
47
|
-
def meta
|
|
48
|
-
@client.post(Constants::INFO_ENDPOINT, { type: 'meta' })
|
|
49
|
-
end
|
|
50
|
-
|
|
51
|
-
# Get metadata for all assets including universe info
|
|
52
|
-
# @return [Hash] Extended metadata for all assets with universe information
|
|
53
|
-
def meta_and_asset_ctxs
|
|
54
|
-
@client.post(Constants::INFO_ENDPOINT, { type: 'metaAndAssetCtxs' })
|
|
75
|
+
# @param cloid [String] Client order ID
|
|
76
|
+
# @return [Hash] Order status information
|
|
77
|
+
def order_status_by_cloid(user, cloid)
|
|
78
|
+
@client.post(Constants::INFO_ENDPOINT, { type: 'orderStatus', user: user, cloid: cloid })
|
|
55
79
|
end
|
|
56
80
|
|
|
57
81
|
# Get L2 order book for a coin
|
|
@@ -78,5 +102,262 @@ module Hyperliquid
|
|
|
78
102
|
}
|
|
79
103
|
})
|
|
80
104
|
end
|
|
105
|
+
|
|
106
|
+
# Check builder fee approval
|
|
107
|
+
# @param user [String] Wallet address
|
|
108
|
+
# @param builder [String] Builder address
|
|
109
|
+
# @return [Hash]
|
|
110
|
+
def max_builder_fee(user, builder)
|
|
111
|
+
@client.post(Constants::INFO_ENDPOINT, { type: 'maxBuilderFee', user: user, builder: builder })
|
|
112
|
+
end
|
|
113
|
+
|
|
114
|
+
# Retrieve a user's historical orders
|
|
115
|
+
# @param user [String] Wallet address
|
|
116
|
+
# @param start_time [Integer, nil] Optional start timestamp in milliseconds
|
|
117
|
+
# @param end_time [Integer, nil] Optional end timestamp in milliseconds
|
|
118
|
+
# @return [Array]
|
|
119
|
+
def historical_orders(user, start_time = nil, end_time = nil)
|
|
120
|
+
body = { type: 'historicalOrders', user: user }
|
|
121
|
+
body[:startTime] = start_time if start_time
|
|
122
|
+
body[:endTime] = end_time if end_time
|
|
123
|
+
@client.post(Constants::INFO_ENDPOINT, body)
|
|
124
|
+
end
|
|
125
|
+
|
|
126
|
+
# Retrieve a user's TWAP slice fills
|
|
127
|
+
# @param user [String] Wallet address
|
|
128
|
+
# @param start_time [Integer, nil] Optional start timestamp in milliseconds
|
|
129
|
+
# @param end_time [Integer, nil] Optional end timestamp in milliseconds
|
|
130
|
+
# @return [Array]
|
|
131
|
+
def user_twap_slice_fills(user, start_time = nil, end_time = nil)
|
|
132
|
+
body = { type: 'userTwapSliceFills', user: user }
|
|
133
|
+
body[:startTime] = start_time if start_time
|
|
134
|
+
body[:endTime] = end_time if end_time
|
|
135
|
+
@client.post(Constants::INFO_ENDPOINT, body)
|
|
136
|
+
end
|
|
137
|
+
|
|
138
|
+
# Retrieve a user's subaccounts
|
|
139
|
+
# @param user [String]
|
|
140
|
+
# @return [Array]
|
|
141
|
+
def user_subaccounts(user)
|
|
142
|
+
@client.post(Constants::INFO_ENDPOINT, { type: 'subaccounts', user: user })
|
|
143
|
+
end
|
|
144
|
+
|
|
145
|
+
# Retrieve details for a vault
|
|
146
|
+
# @param vault_address [String] Vault address
|
|
147
|
+
# @param user [String, nil] Optional wallet address
|
|
148
|
+
# @return [Hash]
|
|
149
|
+
def vault_details(vault_address, user = nil)
|
|
150
|
+
body = { type: 'vaultDetails', vaultAddress: vault_address }
|
|
151
|
+
body[:user] = user if user
|
|
152
|
+
@client.post(Constants::INFO_ENDPOINT, body)
|
|
153
|
+
end
|
|
154
|
+
|
|
155
|
+
# Retrieve a user's vault deposits
|
|
156
|
+
# @param user [String] Wallet address
|
|
157
|
+
# @return [Array]
|
|
158
|
+
def user_vault_equities(user)
|
|
159
|
+
@client.post(Constants::INFO_ENDPOINT, { type: 'userVaultEquities', user: user })
|
|
160
|
+
end
|
|
161
|
+
|
|
162
|
+
# Query a user's role
|
|
163
|
+
# @param user [String]
|
|
164
|
+
# @return [Hash]
|
|
165
|
+
def user_role(user)
|
|
166
|
+
@client.post(Constants::INFO_ENDPOINT, { type: 'userRole', user: user })
|
|
167
|
+
end
|
|
168
|
+
|
|
169
|
+
# Query a user's portfolio time series
|
|
170
|
+
# @param user [String]
|
|
171
|
+
# @return [Array]
|
|
172
|
+
def portfolio(user)
|
|
173
|
+
@client.post(Constants::INFO_ENDPOINT, { type: 'portfolio', user: user })
|
|
174
|
+
end
|
|
175
|
+
|
|
176
|
+
# Query a user's referral information
|
|
177
|
+
# @param user [String]
|
|
178
|
+
# @return [Hash]
|
|
179
|
+
def referral(user)
|
|
180
|
+
@client.post(Constants::INFO_ENDPOINT, { type: 'referral', user: user })
|
|
181
|
+
end
|
|
182
|
+
|
|
183
|
+
# Query a user's effective fee rates and schedule
|
|
184
|
+
# @param user [String]
|
|
185
|
+
# @return [Hash]
|
|
186
|
+
def user_fees(user)
|
|
187
|
+
@client.post(Constants::INFO_ENDPOINT, { type: 'userFees', user: user })
|
|
188
|
+
end
|
|
189
|
+
|
|
190
|
+
# Query a user's staking delegations
|
|
191
|
+
# @param user [String]
|
|
192
|
+
# @return [Array]
|
|
193
|
+
def delegations(user)
|
|
194
|
+
@client.post(Constants::INFO_ENDPOINT, { type: 'delegations', user: user })
|
|
195
|
+
end
|
|
196
|
+
|
|
197
|
+
# Query a user's staking summary
|
|
198
|
+
# @param user [String]
|
|
199
|
+
# @return [Hash]
|
|
200
|
+
def delegator_summary(user)
|
|
201
|
+
@client.post(Constants::INFO_ENDPOINT, { type: 'delegatorSummary', user: user })
|
|
202
|
+
end
|
|
203
|
+
|
|
204
|
+
# Query a user's staking history
|
|
205
|
+
# @param user [String]
|
|
206
|
+
# @return [Array]
|
|
207
|
+
def delegator_history(user)
|
|
208
|
+
@client.post(Constants::INFO_ENDPOINT, { type: 'delegatorHistory', user: user })
|
|
209
|
+
end
|
|
210
|
+
|
|
211
|
+
# Query a user's staking rewards
|
|
212
|
+
# @param user [String]
|
|
213
|
+
# @return [Array]
|
|
214
|
+
def delegator_rewards(user)
|
|
215
|
+
@client.post(Constants::INFO_ENDPOINT, { type: 'delegatorRewards', user: user })
|
|
216
|
+
end
|
|
217
|
+
|
|
218
|
+
# ============================
|
|
219
|
+
# Info: Perpetuals
|
|
220
|
+
# ============================
|
|
221
|
+
|
|
222
|
+
# Retrieve all perpetual dexs
|
|
223
|
+
# @return [Array]
|
|
224
|
+
def perp_dexs
|
|
225
|
+
@client.post(Constants::INFO_ENDPOINT, { type: 'perpDexs' })
|
|
226
|
+
end
|
|
227
|
+
|
|
228
|
+
# Get metadata for all assets
|
|
229
|
+
# @return [Hash] Metadata for all tradable assets
|
|
230
|
+
# @param dex [String, nil] Optional perp dex name (defaults to first perp dex when not provided)
|
|
231
|
+
def meta(dex: nil)
|
|
232
|
+
body = { type: 'meta' }
|
|
233
|
+
body[:dex] = dex if dex
|
|
234
|
+
@client.post(Constants::INFO_ENDPOINT, body)
|
|
235
|
+
end
|
|
236
|
+
|
|
237
|
+
# Get metadata for all assets including universe info
|
|
238
|
+
# @return [Hash] Extended metadata for all assets with universe information
|
|
239
|
+
def meta_and_asset_ctxs
|
|
240
|
+
@client.post(Constants::INFO_ENDPOINT, { type: 'metaAndAssetCtxs' })
|
|
241
|
+
end
|
|
242
|
+
|
|
243
|
+
# Get user's trading state
|
|
244
|
+
# @param user [String] Wallet address
|
|
245
|
+
# @param dex [String, nil] Optional perp dex name
|
|
246
|
+
# @return [Hash] User's trading state including positions and balances
|
|
247
|
+
def user_state(user, dex: nil)
|
|
248
|
+
body = { type: 'clearinghouseState', user: user }
|
|
249
|
+
body[:dex] = dex if dex
|
|
250
|
+
@client.post(Constants::INFO_ENDPOINT, body)
|
|
251
|
+
end
|
|
252
|
+
|
|
253
|
+
# Retrieve predicted funding rates for different venues
|
|
254
|
+
# @return [Array]
|
|
255
|
+
def predicted_fundings
|
|
256
|
+
@client.post(Constants::INFO_ENDPOINT, { type: 'predictedFundings' })
|
|
257
|
+
end
|
|
258
|
+
|
|
259
|
+
# Query perps at open interest caps
|
|
260
|
+
# @return [Array]
|
|
261
|
+
def perps_at_open_interest_cap
|
|
262
|
+
@client.post(Constants::INFO_ENDPOINT, { type: 'perpsAtOpenInterestCap' })
|
|
263
|
+
end
|
|
264
|
+
|
|
265
|
+
# Retrieve information about the Perp Deploy Auction
|
|
266
|
+
# @return [Hash]
|
|
267
|
+
def perp_deploy_auction_status
|
|
268
|
+
@client.post(Constants::INFO_ENDPOINT, { type: 'perpDeployAuctionStatus' })
|
|
269
|
+
end
|
|
270
|
+
|
|
271
|
+
# Retrieve User's Active Asset Data
|
|
272
|
+
# @param user [String]
|
|
273
|
+
# @param coin [String]
|
|
274
|
+
# @return [Hash]
|
|
275
|
+
def active_asset_data(user, coin)
|
|
276
|
+
@client.post(Constants::INFO_ENDPOINT, { type: 'activeAssetData', user: user, coin: coin })
|
|
277
|
+
end
|
|
278
|
+
|
|
279
|
+
# Retrieve Builder-Deployed Perp Market Limits
|
|
280
|
+
# @param dex [String]
|
|
281
|
+
# @return [Hash]
|
|
282
|
+
def perp_dex_limits(dex)
|
|
283
|
+
@client.post(Constants::INFO_ENDPOINT, { type: 'perpDexLimits', dex: dex })
|
|
284
|
+
end
|
|
285
|
+
|
|
286
|
+
# Retrieve a user's funding history
|
|
287
|
+
# @param user [String]
|
|
288
|
+
# @param start_time [Integer]
|
|
289
|
+
# @param end_time [Integer, nil]
|
|
290
|
+
# @return [Array]
|
|
291
|
+
def user_funding(user, start_time, end_time = nil)
|
|
292
|
+
body = { type: 'userFunding', user: user, startTime: start_time }
|
|
293
|
+
body[:endTime] = end_time if end_time
|
|
294
|
+
@client.post(Constants::INFO_ENDPOINT, body)
|
|
295
|
+
end
|
|
296
|
+
|
|
297
|
+
# Retrieve a user's non-funding ledger updates
|
|
298
|
+
# @param user [String]
|
|
299
|
+
# @param start_time [Integer]
|
|
300
|
+
# @param end_time [Integer, nil]
|
|
301
|
+
# @return [Array]
|
|
302
|
+
def user_non_funding_ledger_updates(user, start_time, end_time = nil)
|
|
303
|
+
body = { type: 'userNonFundingLedgerUpdates', user: user, startTime: start_time }
|
|
304
|
+
body[:endTime] = end_time if end_time
|
|
305
|
+
@client.post(Constants::INFO_ENDPOINT, body)
|
|
306
|
+
end
|
|
307
|
+
|
|
308
|
+
# Retrieve historical funding rates
|
|
309
|
+
# @param coin [String]
|
|
310
|
+
# @param start_time [Integer]
|
|
311
|
+
# @param end_time [Integer, nil]
|
|
312
|
+
# @return [Array]
|
|
313
|
+
def funding_history(coin, start_time, end_time = nil)
|
|
314
|
+
body = { type: 'fundingHistory', coin: coin, startTime: start_time }
|
|
315
|
+
body[:endTime] = end_time if end_time
|
|
316
|
+
@client.post(Constants::INFO_ENDPOINT, body)
|
|
317
|
+
end
|
|
318
|
+
|
|
319
|
+
# ============================
|
|
320
|
+
# Info: Spot
|
|
321
|
+
# ============================
|
|
322
|
+
|
|
323
|
+
# Get spot metadata
|
|
324
|
+
# @return [Hash] Spot tokens and universe metadata
|
|
325
|
+
def spot_meta
|
|
326
|
+
@client.post(Constants::INFO_ENDPOINT, { type: 'spotMeta' })
|
|
327
|
+
end
|
|
328
|
+
|
|
329
|
+
# Get spot metadata and asset contexts
|
|
330
|
+
# @return [Array] [spot_meta, spot_asset_ctxs]
|
|
331
|
+
def spot_meta_and_asset_ctxs
|
|
332
|
+
@client.post(Constants::INFO_ENDPOINT, { type: 'spotMetaAndAssetCtxs' })
|
|
333
|
+
end
|
|
334
|
+
|
|
335
|
+
# Get a user's spot token balances
|
|
336
|
+
# @param user [String] Wallet address
|
|
337
|
+
# @return [Hash] Object containing balances array
|
|
338
|
+
def spot_balances(user)
|
|
339
|
+
@client.post(Constants::INFO_ENDPOINT, { type: 'spotClearinghouseState', user: user })
|
|
340
|
+
end
|
|
341
|
+
|
|
342
|
+
# Get Spot Deploy Auction state for a user
|
|
343
|
+
# @param user [String] Wallet address
|
|
344
|
+
# @return [Hash] Spot deploy state
|
|
345
|
+
def spot_deploy_state(user)
|
|
346
|
+
@client.post(Constants::INFO_ENDPOINT, { type: 'spotDeployState', user: user })
|
|
347
|
+
end
|
|
348
|
+
|
|
349
|
+
# Get Spot Pair Deploy Auction status
|
|
350
|
+
# @return [Hash] Auction timing and gas parameters
|
|
351
|
+
def spot_pair_deploy_auction_status
|
|
352
|
+
@client.post(Constants::INFO_ENDPOINT, { type: 'spotPairDeployAuctionStatus' })
|
|
353
|
+
end
|
|
354
|
+
|
|
355
|
+
# Get token details by tokenId
|
|
356
|
+
# @param token_id [String] 34-character hexadecimal token id
|
|
357
|
+
# @return [Hash] Token details
|
|
358
|
+
def token_details(token_id)
|
|
359
|
+
@client.post(Constants::INFO_ENDPOINT, { type: 'tokenDetails', tokenId: token_id })
|
|
360
|
+
end
|
|
81
361
|
end
|
|
362
|
+
# rubocop:enable Metrics/ClassLength
|
|
82
363
|
end
|
data/lib/hyperliquid/version.rb
CHANGED