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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a800dda349fdca23a3e13c4b49020a3c17d506934f7f80b9859d760a95fb1a23
4
- data.tar.gz: 518ae3c035ba3018ccb27d80552dd2f08b7b64d126b58f9828ce2db7d84052f6
3
+ metadata.gz: ce12eae948710ac0527586206ef346535631855e2e99e5d858bbcbfab0440826
4
+ data.tar.gz: 58cfa00339c797844b38a1744392a4589c97a9d7c61b3d6782411a1f4a2adc05
5
5
  SHA512:
6
- metadata.gz: 64ecd6d0060040e6f98143535c05ed0d4a3035e72fa9e0eba0faf4865b14496172463eecd1d57f664c9e5c9df35f0517cfd53b40d3bd34d1325625e1526c64e4
7
- data.tar.gz: 1700985bc702806ea068c180327ae6ee5fc2ac0d8d5c801e85a61dc044a30c298a3130c840d44b9a132dddbc55c00262ff2137635a03b2139279b0ed0522890a
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 - a read-only implementation focusing on the Info API endpoints for market data, user information, and order book data.
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).
@@ -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
- # TODO:
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
- def initialize(base_url:, timeout: Constants::DEFAULT_TIMEOUT)
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
 
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Hyperliquid
4
- VERSION = '0.1.0'
4
+ VERSION = '0.1.1'
5
5
  end
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
- def initialize(testnet: false, timeout: Constants::DEFAULT_TIMEOUT)
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
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hyperliquid
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - carter2099