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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a800dda349fdca23a3e13c4b49020a3c17d506934f7f80b9859d760a95fb1a23
4
- data.tar.gz: 518ae3c035ba3018ccb27d80552dd2f08b7b64d126b58f9828ce2db7d84052f6
3
+ metadata.gz: 6e872be045b5d2e21d4e2da9faf5ed12ef61f5d8310eeb3bb3c87afd07c43717
4
+ data.tar.gz: f334156a2da8a6abb437872af50b28cab0e5422174e310f867dc410852c2b24b
5
5
  SHA512:
6
- metadata.gz: 64ecd6d0060040e6f98143535c05ed0d4a3035e72fa9e0eba0faf4865b14496172463eecd1d57f664c9e5c9df35f0517cfd53b40d3bd34d1325625e1526c64e4
7
- data.tar.gz: 1700985bc702806ea068c180327ae6ee5fc2ac0d8d5c801e85a61dc044a30c298a3130c840d44b9a132dddbc55c00262ff2137635a03b2139279b0ed0522890a
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
- 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
+ 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
- This is v0.1.0 with read-only Info API support. Future versions will include:
211
+ The latest version is v0.2.0 with read-only Info API support. Future versions will include:
189
212
 
190
- - v0.2.0: Trading API (place orders, cancel orders, etc.)
191
- - v0.3.0: WebSocket support for real-time data
192
- - v0.4.0: Advanced trading features
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).
@@ -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
 
@@ -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
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Hyperliquid
4
- VERSION = '0.1.0'
4
+ VERSION = '0.2.0'
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.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - carter2099