hyperliquid 0.4.1 → 0.6.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 184e215d2d80056cb19bd6a20b273134d9997979d160d154318c5e155cdf02bb
4
- data.tar.gz: 1f2bd8b08ef2e99e3732bd7775eeb70fe00ad7c2f4210312d07d237d28e670ed
3
+ metadata.gz: 324ff762cbf5edcea7fc532f853b7295ffcd34476f6273fdef4e03bcc0f9eaee
4
+ data.tar.gz: 98b1b88b378bb8ae010301c656c833282cd406822fa0c8a7d6c134911b0f2cce
5
5
  SHA512:
6
- metadata.gz: 1b8645b6f40ae9163343fbc6d7d5c814417643469d75ac320073546243d601055c26f92e1ecb272baf9d839dc4b983b19d56be01cc2bcf4709de9f0e6bf81116
7
- data.tar.gz: 462b64553e8ee0939bf0284b0647ec602f9be2f3b2389144e64188813cf52d1bca1daf3feb233eab1167fb1337bda7028208acc38398e55a6279e2593ab26181
6
+ metadata.gz: fe9e447e5500312f98e8f8e602071372847963daacfd51475e92d4db5a7bc988546e4cf106479a9c899bcecf113612c2aa9ebe0dd50a5384bd438bb0d6429865
7
+ data.tar.gz: 7cd7d2e048c4bf25e128dd7fd41814621bd95305d613199cb4c41abdf1901fdc4c665635000112aafeb7c395dbf01dae81cba74042557d86643c6ac169e3d201
data/.rubocop.yml CHANGED
@@ -4,6 +4,7 @@ AllCops:
4
4
  SuggestExtensions: false
5
5
  Exclude:
6
6
  - 'test_*.rb' # Exclude ad-hoc integration test scripts
7
+ - 'scripts/**/*' # Exclude integration test scripts
7
8
  - 'vendor/**/*' # Exclude vendored gems (CI bundles here)
8
9
 
9
10
  # Allow longer methods for complex logic
data/CHANGELOG.md CHANGED
@@ -1,6 +1,28 @@
1
1
  ## [Ruby Hyperliquid SDK Changelog]
2
2
 
3
- ## [0.4.1] - 2025-01-28
3
+ ## [0.6.0] - 2026-01-28
4
+
5
+ - Add transfers and account management to Exchange API
6
+ - USD transfers: `usd_send`, `usd_class_transfer`, `withdraw_from_bridge`
7
+ - Spot transfers: `spot_send`, `send_asset`
8
+ - Sub-accounts: `create_sub_account`, `sub_account_transfer`, `sub_account_spot_transfer`
9
+ - Vaults: `vault_transfer`
10
+ - Referrals: `set_referrer`
11
+ - Add user-signed action signing (`sign_user_signed_action`) for EIP-712 typed data with `HyperliquidSignTransaction` domain
12
+ - Add Python SDK parity test vectors for `usd_send`, `withdraw_from_bridge`, `create_sub_account`, and `sub_account_transfer`
13
+ - Reorganize integration tests into individual scripts under `scripts/` for easier debugging
14
+
15
+ ## [0.5.0] - 2026-01-28
16
+
17
+ - Add core trading features to Exchange API
18
+ - Order modification: `modify_order`, `batch_modify`
19
+ - Position management: `update_leverage`, `update_isolated_margin`, `market_close`
20
+ - Dead man's switch: `schedule_cancel`
21
+ - Add `market_close` helper for closing positions at market price with auto-detection of size and direction
22
+ - Add integration tests for leverage updates, order modification, and market close
23
+ - Add GitHub Release workflow (`.github/workflows/release.yml`)
24
+
25
+ ## [0.4.1] - 2026-01-28
4
26
 
5
27
  - Reorganize documentation for improved readability
6
28
  - Streamline README with basic setup and links to detailed docs
@@ -10,7 +32,7 @@
10
32
  - Add `docs/ERRORS.md` with error handling guide
11
33
  - Add `docs/DEVELOPMENT.md` with setup and testing instructions
12
34
 
13
- ## [0.4.0] - 2025-01-27
35
+ ## [0.4.0] - 2026-01-27
14
36
 
15
37
  - Add Exchange API for authenticated write operations (trading)
16
38
  - Order placement: `order`, `bulk_orders`, `market_order`
data/CLAUDE.md CHANGED
@@ -45,16 +45,15 @@ ruby example.rb
45
45
 
46
46
  ### Integration Testing (Testnet)
47
47
  ```bash
48
- # Run the testnet integration test (requires private key)
48
+ # Run all integration tests (requires private key)
49
49
  # Get testnet funds from: https://app.hyperliquid-testnet.xyz
50
- HYPERLIQUID_PRIVATE_KEY=0x... ruby test_integration.rb
50
+ HYPERLIQUID_PRIVATE_KEY=0x... ruby scripts/test_all.rb
51
+
52
+ # Run a single integration test
53
+ HYPERLIQUID_PRIVATE_KEY=0x... ruby scripts/test_08_usd_class_transfer.rb
51
54
  ```
52
55
 
53
- The integration test executes real trades on testnet:
54
- 1. Spot market roundtrip (buy/sell PURR/USDC)
55
- 2. Spot limit order (place and cancel)
56
- 3. Perp market roundtrip (long/close BTC)
57
- 4. Perp limit order (place short, cancel)
56
+ Integration tests live in `scripts/` as individual files. Each can be run standalone for debugging. `test_integration.rb` at the project root is a convenience wrapper that runs them all.
58
57
 
59
58
  ### Setup
60
59
  ```bash
data/README.md CHANGED
@@ -1,5 +1,9 @@
1
1
  # Hyperliquid Ruby SDK
2
2
 
3
+ [![Gem Version](https://badge.fury.io/rb/hyperliquid.svg)](https://rubygems.org/gems/hyperliquid)
4
+ [![Downloads](https://img.shields.io/gem/dt/hyperliquid.svg)](https://rubygems.org/gems/hyperliquid)
5
+ [![CI](https://github.com/carter2099/hyperliquid/actions/workflows/main.yml/badge.svg)](https://github.com/carter2099/hyperliquid/actions)
6
+
3
7
  A Ruby SDK for interacting with the Hyperliquid decentralized exchange API.
4
8
 
5
9
  The SDK supports both read operations (Info API) and authenticated write operations (Exchange API) for trading.
@@ -54,14 +58,6 @@ exchange = trading_sdk.exchange
54
58
  - [Error Handling](docs/ERRORS.md) - Error types and handling
55
59
  - [Development](docs/DEVELOPMENT.md) - Contributing and running tests
56
60
 
57
- ## Roadmap
58
-
59
- The SDK now supports both Info API (read) and Exchange API (trading). Future versions will include:
60
-
61
- - WebSocket support for real-time data
62
- - Additional exchange operations (leverage, margin adjustments, transfers)
63
- - Advanced trading features (TWAP, etc.)
64
-
65
61
  ## Contributing
66
62
 
67
63
  Bug reports and pull requests are welcome on GitHub at https://github.com/carter2099/hyperliquid.
data/SECURITY.md ADDED
@@ -0,0 +1,7 @@
1
+ # Security Policy
2
+
3
+ ## For Issues in Hyperliquid
4
+
5
+ If you have discovered a vulnerability or security issue related to the Hyperliquid service (e.g., buffer overflow, SQL
6
+ injection, cross-site scripting, etc.), please refer to the
7
+ [Hyperliquid Security Policy](https://github.com/hyperliquid-dex/hyperliquid-python-sdk/blob/master/SECURITY.md).
data/docs/API.md CHANGED
@@ -59,16 +59,49 @@ Read-only methods for querying market data and user information.
59
59
 
60
60
  **Note:** Exchange methods require initializing the SDK with a `private_key`.
61
61
 
62
+ ### Order Placement
63
+
62
64
  - `order(coin:, is_buy:, size:, limit_px:, ...)` - Place a single limit order
63
65
  - `bulk_orders(orders:, grouping:, ...)` - Place multiple orders in a batch
64
66
  - `market_order(coin:, is_buy:, size:, slippage:, ...)` - Place a market order with slippage
67
+
68
+ ### Order Modification
69
+
70
+ - `modify_order(oid:, coin:, is_buy:, size:, limit_px:, ...)` - Modify an existing order by oid or cloid
71
+ - `batch_modify(modifies:, ...)` - Modify multiple orders at once
72
+
73
+ ### Order Cancellation
74
+
65
75
  - `cancel(coin:, oid:, ...)` - Cancel an order by order ID
66
76
  - `cancel_by_cloid(coin:, cloid:, ...)` - Cancel an order by client order ID
67
77
  - `bulk_cancel(cancels:, ...)` - Cancel multiple orders by order ID
68
78
  - `bulk_cancel_by_cloid(cancels:, ...)` - Cancel multiple orders by client order ID
79
+ - `schedule_cancel(time:, ...)` - Auto-cancel all orders at a given time
80
+
81
+ ### Position Management
82
+
83
+ - `market_close(coin:, size:, slippage:, ...)` - Close a position at market price (auto-detects position size)
84
+ - `update_leverage(coin:, leverage:, is_cross:, ...)` - Set cross or isolated leverage for a coin
85
+ - `update_isolated_margin(coin:, amount:, ...)` - Add or remove isolated margin for a position
86
+
87
+ ### Transfers & Account Management
88
+
89
+ - `usd_send(amount:, destination:)` - Transfer USDC to another address
90
+ - `spot_send(amount:, destination:, token:)` - Transfer a spot token to another address
91
+ - `usd_class_transfer(amount:, to_perp:)` - Move USDC between perp and spot accounts
92
+ - `withdraw_from_bridge(amount:, destination:)` - Withdraw USDC via the bridge
93
+ - `send_asset(destination:, source_dex:, destination_dex:, token:, amount:)` - Move assets between DEX instances
94
+ - `create_sub_account(name:)` - Create a sub-account
95
+ - `sub_account_transfer(sub_account_user:, is_deposit:, usd:)` - Transfer USDC to/from a sub-account
96
+ - `sub_account_spot_transfer(sub_account_user:, is_deposit:, token:, amount:)` - Transfer spot tokens to/from a sub-account
97
+ - `vault_transfer(vault_address:, is_deposit:, usd:)` - Deposit or withdraw USDC to/from a vault
98
+ - `set_referrer(code:)` - Set referral code
99
+
100
+ ### Other
101
+
69
102
  - `address` - Get the wallet address associated with the private key
70
103
 
71
- All exchange methods support an optional `vault_address:` parameter for vault trading.
104
+ Order placement and management methods support an optional `vault_address:` parameter for vault trading.
72
105
 
73
106
  ### Order Types
74
107
 
data/docs/DEVELOPMENT.md CHANGED
@@ -11,13 +11,42 @@ bin/setup
11
11
  ## Running Tests
12
12
 
13
13
  ```bash
14
- # Run all tests
14
+ # Run all unit tests
15
15
  rake spec
16
16
 
17
- # Run tests and linting together (default)
17
+ # Run unit tests and linting together (default)
18
18
  rake
19
19
  ```
20
20
 
21
+ ### Integration Testing (Testnet)
22
+
23
+ Integration tests live in `scripts/` and execute real trades on testnet. No real funds are at risk. Get testnet funds from https://app.hyperliquid-testnet.xyz.
24
+
25
+ ```bash
26
+ # Run all integration tests
27
+ HYPERLIQUID_PRIVATE_KEY=0x... ruby scripts/test_all.rb
28
+
29
+ # Run a single integration test
30
+ HYPERLIQUID_PRIVATE_KEY=0x... ruby scripts/test_08_usd_class_transfer.rb
31
+ ```
32
+
33
+ The convenience wrapper `ruby test_integration.rb` also runs all tests.
34
+
35
+ Available test scripts:
36
+
37
+ | Script | Description |
38
+ |--------|-------------|
39
+ | `test_01_spot_market_roundtrip.rb` | Buy/sell PURR/USDC at market |
40
+ | `test_02_spot_limit_order.rb` | Place and cancel a spot limit order |
41
+ | `test_03_perp_market_roundtrip.rb` | Long/close BTC at market |
42
+ | `test_04_perp_limit_order.rb` | Place and cancel a perp short |
43
+ | `test_05_update_leverage.rb` | Set cross, isolated, and reset leverage |
44
+ | `test_06_modify_order.rb` | Place, modify, and cancel an order |
45
+ | `test_07_market_close.rb` | Open a position and close via `market_close` |
46
+ | `test_08_usd_class_transfer.rb` | Transfer USDC between perp and spot |
47
+ | `test_09_sub_account_lifecycle.rb` | Create sub-account, deposit, withdraw |
48
+ | `test_10_vault_transfer.rb` | Deposit/withdraw to a vault |
49
+
21
50
  ## Linting
22
51
 
23
52
  ```bash
@@ -37,18 +66,3 @@ This opens an interactive prompt with the SDK loaded for experimentation.
37
66
  ```bash
38
67
  ruby example.rb
39
68
  ```
40
-
41
- ## Integration Testing (Testnet)
42
-
43
- For real trading tests on testnet:
44
-
45
- ```bash
46
- # Get testnet funds from: https://app.hyperliquid-testnet.xyz
47
- HYPERLIQUID_PRIVATE_KEY=0x... ruby test_integration.rb
48
- ```
49
-
50
- The integration test executes real trades on testnet:
51
- 1. Spot market roundtrip (buy/sell PURR/USDC)
52
- 2. Spot limit order (place and cancel)
53
- 3. Perp market roundtrip (long/close BTC)
54
- 4. Perp limit order (place short, cancel)
data/docs/EXAMPLES.md CHANGED
@@ -276,6 +276,70 @@ cloid_cancels = [
276
276
  sdk.exchange.bulk_cancel_by_cloid(cancels: cloid_cancels)
277
277
  ```
278
278
 
279
+ ### Modifying Orders
280
+
281
+ ```ruby
282
+ # Modify an existing order by order ID
283
+ oid = result.dig('response', 'data', 'statuses', 0, 'resting', 'oid')
284
+ sdk.exchange.modify_order(
285
+ oid: oid,
286
+ coin: 'BTC',
287
+ is_buy: true,
288
+ size: '0.02',
289
+ limit_px: '96000'
290
+ )
291
+
292
+ # Modify an order by client order ID
293
+ cloid = Hyperliquid::Cloid.from_int(123)
294
+ sdk.exchange.modify_order(
295
+ oid: cloid,
296
+ coin: 'BTC',
297
+ is_buy: true,
298
+ size: '0.02',
299
+ limit_px: '96000'
300
+ )
301
+
302
+ # Modify multiple orders at once
303
+ modifies = [
304
+ { oid: 12345, coin: 'BTC', is_buy: true, size: '0.01', limit_px: '95000' },
305
+ { oid: 12346, coin: 'ETH', is_buy: false, size: '0.5', limit_px: '3200' }
306
+ ]
307
+ sdk.exchange.batch_modify(modifies: modifies)
308
+ ```
309
+
310
+ ### Position Management
311
+
312
+ ```ruby
313
+ # Set cross leverage (default)
314
+ sdk.exchange.update_leverage(coin: 'BTC', leverage: 5)
315
+
316
+ # Set isolated leverage
317
+ sdk.exchange.update_leverage(coin: 'BTC', leverage: 10, is_cross: false)
318
+
319
+ # Add isolated margin to a position (positive amount)
320
+ sdk.exchange.update_isolated_margin(coin: 'BTC', amount: 100.0)
321
+
322
+ # Remove isolated margin from a position (negative amount)
323
+ sdk.exchange.update_isolated_margin(coin: 'BTC', amount: -50.0)
324
+
325
+ # Close an entire position at market price (auto-detects size and direction)
326
+ sdk.exchange.market_close(coin: 'BTC')
327
+
328
+ # Close a partial position with custom slippage
329
+ sdk.exchange.market_close(coin: 'BTC', size: 0.01, slippage: 0.03)
330
+ ```
331
+
332
+ ### Schedule Cancel
333
+
334
+ ```ruby
335
+ # Schedule auto-cancel of all orders at a specific time
336
+ cancel_time = (Time.now.to_f * 1000).to_i + 60_000 # 60 seconds from now
337
+ sdk.exchange.schedule_cancel(time: cancel_time)
338
+
339
+ # Activate schedule cancel without specifying a time (server default)
340
+ sdk.exchange.schedule_cancel
341
+ ```
342
+
279
343
  ### Vault Trading
280
344
 
281
345
  ```ruby
@@ -324,6 +388,97 @@ sdk.exchange.order(
324
388
  )
325
389
  ```
326
390
 
391
+ ### Transfers & Account Management
392
+
393
+ ```ruby
394
+ # Transfer USDC to another address
395
+ sdk.exchange.usd_send(
396
+ amount: '100',
397
+ destination: '0x...'
398
+ )
399
+
400
+ # Transfer a spot token to another address
401
+ sdk.exchange.spot_send(
402
+ amount: '50',
403
+ destination: '0x...',
404
+ token: 'PURR'
405
+ )
406
+
407
+ # Move USDC between perp and spot accounts
408
+ sdk.exchange.usd_class_transfer(amount: '100', to_perp: false) # perp -> spot
409
+ sdk.exchange.usd_class_transfer(amount: '100', to_perp: true) # spot -> perp
410
+
411
+ # Withdraw USDC via the bridge
412
+ sdk.exchange.withdraw_from_bridge(
413
+ amount: '100',
414
+ destination: '0x...'
415
+ )
416
+
417
+ # Move assets between DEX instances
418
+ sdk.exchange.send_asset(
419
+ destination: '0x...',
420
+ source_dex: 'dex1',
421
+ destination_dex: 'dex2',
422
+ token: 'USDC',
423
+ amount: '100'
424
+ )
425
+ ```
426
+
427
+ ### Sub-Account Management
428
+
429
+ ```ruby
430
+ # Create a sub-account
431
+ result = sdk.exchange.create_sub_account(name: 'my-sub-account')
432
+ sub_address = result.dig('response', 'data', 'subAccountUser')
433
+
434
+ # Deposit USDC into a sub-account
435
+ sdk.exchange.sub_account_transfer(
436
+ sub_account_user: sub_address,
437
+ is_deposit: true,
438
+ usd: 100
439
+ )
440
+
441
+ # Withdraw USDC from a sub-account
442
+ sdk.exchange.sub_account_transfer(
443
+ sub_account_user: sub_address,
444
+ is_deposit: false,
445
+ usd: 50
446
+ )
447
+
448
+ # Transfer spot tokens to a sub-account
449
+ sdk.exchange.sub_account_spot_transfer(
450
+ sub_account_user: sub_address,
451
+ is_deposit: true,
452
+ token: 'PURR',
453
+ amount: '10'
454
+ )
455
+ ```
456
+
457
+ ### Vault Operations
458
+
459
+ ```ruby
460
+ # Deposit USDC into a vault
461
+ sdk.exchange.vault_transfer(
462
+ vault_address: '0x...',
463
+ is_deposit: true,
464
+ usd: 100
465
+ )
466
+
467
+ # Withdraw USDC from a vault
468
+ sdk.exchange.vault_transfer(
469
+ vault_address: '0x...',
470
+ is_deposit: false,
471
+ usd: 50
472
+ )
473
+ ```
474
+
475
+ ### Referral
476
+
477
+ ```ruby
478
+ # Set a referral code
479
+ sdk.exchange.set_referrer(code: 'MY_REFERRAL_CODE')
480
+ ```
481
+
327
482
  ### Client Order IDs (Cloid)
328
483
 
329
484
  ```ruby