hyperliquid 0.1.0 → 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +25 -2
- data/lib/hyperliquid/client.rb +10 -7
- 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: ce12eae948710ac0527586206ef346535631855e2e99e5d858bbcbfab0440826
|
|
4
|
+
data.tar.gz: 58cfa00339c797844b38a1744392a4589c97a9d7c61b3d6782411a1f4a2adc05
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 146b89a2874c1410b470cf2e9c795af60915dc4b5b9aaaad40228823230e8c738292a7c480e873f5732a896cdd4aa502622c8df47fa21321b51894efd5948a16
|
|
7
|
+
data.tar.gz: 870019afb083c7a5864361335fc5294d941d47e4318f38f5acd548ee63bfde3f364928f8f71690bca76db5aa68255478bc205a91c79f5737bdbdb78ce77f073e
|
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
|
-
This is v0.1.0 -
|
|
5
|
+
This is v0.1.0 - an alpha-stage 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
|
|
|
@@ -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/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
|