hyperliquid 0.1.0 → 0.2.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/CHANGELOG.md +9 -1
- data/README.md +29 -6
- data/lib/hyperliquid/client.rb +10 -7
- data/lib/hyperliquid/info.rb +43 -0
- data/lib/hyperliquid/version.rb +1 -1
- data/lib/hyperliquid.rb +6 -4
- 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: 6e872be045b5d2e21d4e2da9faf5ed12ef61f5d8310eeb3bb3c87afd07c43717
|
|
4
|
+
data.tar.gz: f334156a2da8a6abb437872af50b28cab0e5422174e310f867dc410852c2b24b
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: b0dbeff4e433947d992a24bf6c288a6395ed2f7b1ec81d9105140444964579e15ee618baf4082cf91b1b1f22e52997c59c0993a83cb0db787c19becc4432c9cd
|
|
7
|
+
data.tar.gz: 3a5072eb52fd23b6b3729f96eb21570d2fcf25d7424aa39b1bdf387740816a81cbec2a2614bd7a8fe45f104a3ef03beb0640391064a6cd2140bb6c42cabd596b
|
data/CHANGELOG.md
CHANGED
|
@@ -2,4 +2,12 @@
|
|
|
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
|
|
|
@@ -93,11 +93,33 @@ status = sdk.info.order_status(user_address, order_id)
|
|
|
93
93
|
# Custom timeout (default: 30 seconds)
|
|
94
94
|
sdk = Hyperliquid.new(timeout: 60)
|
|
95
95
|
|
|
96
|
+
# Enable retry logic for handling transient failures (default: disabled)
|
|
97
|
+
sdk = Hyperliquid.new(retry_enabled: true)
|
|
98
|
+
|
|
99
|
+
# Combine multiple configuration options
|
|
100
|
+
sdk = Hyperliquid.new(testnet: true, timeout: 60, retry_enabled: true)
|
|
101
|
+
|
|
96
102
|
# Check which environment you're using
|
|
97
103
|
sdk.testnet? # => false
|
|
98
104
|
sdk.base_url # => "https://api.hyperliquid.xyz"
|
|
99
105
|
```
|
|
100
106
|
|
|
107
|
+
#### Retry Configuration
|
|
108
|
+
|
|
109
|
+
By default, retry logic is **disabled** for predictable API behavior. When enabled, the SDK will automatically retry requests that fail due to:
|
|
110
|
+
|
|
111
|
+
- Network connectivity issues (connection failed, timeouts)
|
|
112
|
+
- Server errors (5xx status codes)
|
|
113
|
+
- Rate limiting (429 status codes)
|
|
114
|
+
|
|
115
|
+
**Retry Settings:**
|
|
116
|
+
- Maximum retries: 2
|
|
117
|
+
- Base interval: 0.5 seconds
|
|
118
|
+
- Backoff factor: 2x (exponential backoff)
|
|
119
|
+
- Randomness: ±50% to prevent thundering herd
|
|
120
|
+
|
|
121
|
+
**Note:** Retries are disabled by default to avoid unexpected delays in time-sensitive trading applications. Enable only when you want automatic handling of transient failures.
|
|
122
|
+
|
|
101
123
|
### Error Handling
|
|
102
124
|
|
|
103
125
|
The SDK provides comprehensive error handling:
|
|
@@ -141,6 +163,7 @@ Creates a new SDK instance.
|
|
|
141
163
|
**Parameters:**
|
|
142
164
|
- `testnet` (Boolean) - Use testnet instead of mainnet (default: false)
|
|
143
165
|
- `timeout` (Integer) - Request timeout in seconds (default: 30)
|
|
166
|
+
- `retry_enabled` (Boolean) - Enable automatic retry logic for transient failures (default: false)
|
|
144
167
|
|
|
145
168
|
### Info API Methods
|
|
146
169
|
|
|
@@ -185,11 +208,11 @@ rake rubocop
|
|
|
185
208
|
|
|
186
209
|
## Roadmap
|
|
187
210
|
|
|
188
|
-
|
|
211
|
+
The latest version is v0.2.0 with read-only Info API support. Future versions will include:
|
|
189
212
|
|
|
190
|
-
-
|
|
191
|
-
-
|
|
192
|
-
-
|
|
213
|
+
- Trading API (place orders, cancel orders, etc.)
|
|
214
|
+
- WebSocket support for real-time data
|
|
215
|
+
- Advanced trading features
|
|
193
216
|
|
|
194
217
|
## Contributing
|
|
195
218
|
|
|
@@ -197,4 +220,4 @@ Bug reports and pull requests are welcome on GitHub at https://github.com/carter
|
|
|
197
220
|
|
|
198
221
|
## License
|
|
199
222
|
|
|
200
|
-
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
|
223
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
data/lib/hyperliquid/client.rb
CHANGED
|
@@ -7,14 +7,13 @@ require 'json'
|
|
|
7
7
|
module Hyperliquid
|
|
8
8
|
# HTTP client for making requests to Hyperliquid API
|
|
9
9
|
class Client
|
|
10
|
-
#
|
|
11
|
-
# Unused for now. To be added to build_connection
|
|
10
|
+
# Default retry configuration for API requests
|
|
12
11
|
DEFAULT_RETRY_OPTIONS = {
|
|
13
12
|
max: 2,
|
|
14
13
|
interval: 0.5,
|
|
15
14
|
interval_randomness: 0.5,
|
|
16
15
|
backoff_factor: 2,
|
|
17
|
-
retry_statuses: [502, 503, 504],
|
|
16
|
+
retry_statuses: [429, 502, 503, 504],
|
|
18
17
|
exceptions: [
|
|
19
18
|
Faraday::ConnectionFailed,
|
|
20
19
|
Faraday::TimeoutError
|
|
@@ -24,7 +23,9 @@ module Hyperliquid
|
|
|
24
23
|
# Initialize a new HTTP client
|
|
25
24
|
# @param base_url [String] The base URL for the API
|
|
26
25
|
# @param timeout [Integer] Request timeout in seconds (default: Constants::DEFAULT_TIMEOUT)
|
|
27
|
-
|
|
26
|
+
# @param retry_enabled [Boolean] Whether to enable retry logic (default: false)
|
|
27
|
+
def initialize(base_url:, timeout: Constants::DEFAULT_TIMEOUT, retry_enabled: false)
|
|
28
|
+
@retry_enabled = retry_enabled
|
|
28
29
|
@connection = build_connection(base_url, timeout)
|
|
29
30
|
end
|
|
30
31
|
|
|
@@ -47,6 +48,10 @@ module Hyperliquid
|
|
|
47
48
|
end
|
|
48
49
|
|
|
49
50
|
handle_response(response)
|
|
51
|
+
rescue Faraday::RetriableResponse => e
|
|
52
|
+
# After retries are exhausted, Faraday throws a RetriableResponse
|
|
53
|
+
# Catch and handle that here to bubble up the actual network error
|
|
54
|
+
handle_response(e.response)
|
|
50
55
|
rescue Faraday::ConnectionFailed => e
|
|
51
56
|
raise NetworkError, "Connection failed: #{e.message}"
|
|
52
57
|
rescue Faraday::TimeoutError => e
|
|
@@ -59,9 +64,7 @@ module Hyperliquid
|
|
|
59
64
|
Faraday.new(url: base_url) do |conn|
|
|
60
65
|
conn.options.timeout = timeout
|
|
61
66
|
conn.options.read_timeout = Constants::DEFAULT_READ_TIMEOUT
|
|
62
|
-
|
|
63
|
-
# TODO:
|
|
64
|
-
# conn.request :retry, DEFAULT_RETRY_OPTIONS
|
|
67
|
+
conn.request :retry, DEFAULT_RETRY_OPTIONS if @retry_enabled
|
|
65
68
|
end
|
|
66
69
|
end
|
|
67
70
|
|
data/lib/hyperliquid/info.rb
CHANGED
|
@@ -78,5 +78,48 @@ module Hyperliquid
|
|
|
78
78
|
}
|
|
79
79
|
})
|
|
80
80
|
end
|
|
81
|
+
|
|
82
|
+
# ============================
|
|
83
|
+
# Spot-specific info endpoints
|
|
84
|
+
# ============================
|
|
85
|
+
|
|
86
|
+
# Get spot metadata
|
|
87
|
+
# @return [Hash] Spot tokens and universe metadata
|
|
88
|
+
def spot_meta
|
|
89
|
+
@client.post(Constants::INFO_ENDPOINT, { type: 'spotMeta' })
|
|
90
|
+
end
|
|
91
|
+
|
|
92
|
+
# Get spot metadata and asset contexts
|
|
93
|
+
# @return [Array] [spot_meta, spot_asset_ctxs]
|
|
94
|
+
def spot_meta_and_asset_ctxs
|
|
95
|
+
@client.post(Constants::INFO_ENDPOINT, { type: 'spotMetaAndAssetCtxs' })
|
|
96
|
+
end
|
|
97
|
+
|
|
98
|
+
# Get a user's spot token balances
|
|
99
|
+
# @param user [String] Wallet address
|
|
100
|
+
# @return [Hash] Object containing balances array
|
|
101
|
+
def spot_balances(user)
|
|
102
|
+
@client.post(Constants::INFO_ENDPOINT, { type: 'spotClearinghouseState', user: user })
|
|
103
|
+
end
|
|
104
|
+
|
|
105
|
+
# Get Spot Deploy Auction state for a user
|
|
106
|
+
# @param user [String] Wallet address
|
|
107
|
+
# @return [Hash] Spot deploy state
|
|
108
|
+
def spot_deploy_state(user)
|
|
109
|
+
@client.post(Constants::INFO_ENDPOINT, { type: 'spotDeployState', user: user })
|
|
110
|
+
end
|
|
111
|
+
|
|
112
|
+
# Get Spot Pair Deploy Auction status
|
|
113
|
+
# @return [Hash] Auction timing and gas parameters
|
|
114
|
+
def spot_pair_deploy_auction_status
|
|
115
|
+
@client.post(Constants::INFO_ENDPOINT, { type: 'spotPairDeployAuctionStatus' })
|
|
116
|
+
end
|
|
117
|
+
|
|
118
|
+
# Get token details by tokenId
|
|
119
|
+
# @param token_id [String] 34-character hexadecimal token id
|
|
120
|
+
# @return [Hash] Token details
|
|
121
|
+
def token_details(token_id)
|
|
122
|
+
@client.post(Constants::INFO_ENDPOINT, { type: 'tokenDetails', tokenId: token_id })
|
|
123
|
+
end
|
|
81
124
|
end
|
|
82
125
|
end
|
data/lib/hyperliquid/version.rb
CHANGED
data/lib/hyperliquid.rb
CHANGED
|
@@ -12,9 +12,10 @@ module Hyperliquid
|
|
|
12
12
|
# Create a new SDK instance
|
|
13
13
|
# @param testnet [Boolean] Whether to use testnet (default: false for mainnet)
|
|
14
14
|
# @param timeout [Integer] Request timeout in seconds (default: 30)
|
|
15
|
+
# @param retry_enabled [Boolean] Whether to enable retry logic (default: false)
|
|
15
16
|
# @return [Hyperliquid::SDK] A new SDK instance
|
|
16
|
-
def self.new(testnet: false, timeout: Constants::DEFAULT_TIMEOUT)
|
|
17
|
-
SDK.new(testnet: testnet, timeout: timeout)
|
|
17
|
+
def self.new(testnet: false, timeout: Constants::DEFAULT_TIMEOUT, retry_enabled: false)
|
|
18
|
+
SDK.new(testnet: testnet, timeout: timeout, retry_enabled: retry_enabled)
|
|
18
19
|
end
|
|
19
20
|
|
|
20
21
|
# Main SDK class
|
|
@@ -24,9 +25,10 @@ module Hyperliquid
|
|
|
24
25
|
# Initialize the SDK
|
|
25
26
|
# @param testnet [Boolean] Whether to use testnet (default: false for mainnet)
|
|
26
27
|
# @param timeout [Integer] Request timeout in seconds
|
|
27
|
-
|
|
28
|
+
# @param retry_enabled [Boolean] Whether to enable retry logic (default: false)
|
|
29
|
+
def initialize(testnet: false, timeout: Constants::DEFAULT_TIMEOUT, retry_enabled: false)
|
|
28
30
|
base_url = testnet ? Constants::TESTNET_API_URL : Constants::MAINNET_API_URL
|
|
29
|
-
client = Client.new(base_url: base_url, timeout: timeout)
|
|
31
|
+
client = Client.new(base_url: base_url, timeout: timeout, retry_enabled: retry_enabled)
|
|
30
32
|
|
|
31
33
|
@info = Info.new(client)
|
|
32
34
|
@testnet = testnet
|