pub struct HyperliquidSignedRequestBuilder<'a> { /* private fields */ }Expand description
Builder for creating authenticated Hyperliquid exchange actions.
This builder encapsulates the EIP-712 signing workflow:
- Private key validation
- Nonce generation (millisecond timestamp)
- EIP-712 signature generation via
HyperLiquidAuth.sign_l1_action() - Request body construction with action, nonce, signature, and optional vault address
- HTTP POST request execution to
/exchangeendpoint
§Hyperliquid Signature Format
Hyperliquid uses EIP-712 typed data signing:
- Domain: HyperliquidSignTransaction
- Chain ID: 42161 (mainnet) or 421614 (testnet)
- Signature components: r (32 bytes hex), s (32 bytes hex), v (recovery id)
§Example
let hyperliquid = HyperLiquid::builder()
.private_key("0x...")
.testnet(true)
.build()?;
let action = json!({"type": "cancel", "cancels": [{"a": 0, "o": 12345}]});
let response = hyperliquid.signed_action(action)
.nonce(1234567890000) // Optional: override auto-generated nonce
.execute()
.await?;Implementations§
Source§impl<'a> HyperliquidSignedRequestBuilder<'a>
impl<'a> HyperliquidSignedRequestBuilder<'a>
Sourcepub fn new(hyperliquid: &'a HyperLiquid, action: Value) -> Self
pub fn new(hyperliquid: &'a HyperLiquid, action: Value) -> Self
Creates a new signed action builder.
§Arguments
hyperliquid- Reference to the HyperLiquid exchange instanceaction- The action JSON to be signed and executed
§Example
let hyperliquid = HyperLiquid::builder()
.private_key("0x...")
.testnet(true)
.build()
.unwrap();
let action = json!({"type": "order", "orders": [], "grouping": "na"});
let builder = HyperliquidSignedRequestBuilder::new(&hyperliquid, action);Sourcepub fn nonce(self, nonce: u64) -> Self
pub fn nonce(self, nonce: u64) -> Self
Sets a custom nonce for the request.
By default, the nonce is automatically generated from the current timestamp in milliseconds. Use this method to override the auto-generated nonce.
§Arguments
nonce- The nonce value (typically timestamp in milliseconds)
§Example
let hyperliquid = HyperLiquid::builder()
.private_key("0x...")
.testnet(true)
.build()?;
let action = json!({"type": "order", "orders": [], "grouping": "na"});
let response = hyperliquid.signed_action(action)
.nonce(1234567890000)
.execute()
.await?;Sourcepub async fn execute(self) -> Result<Value>
pub async fn execute(self) -> Result<Value>
Executes the signed action and returns the response.
This method:
- Validates that a private key is configured
- Gets or generates the nonce (millisecond timestamp)
- Signs the action using EIP-712 typed data signing
- Constructs the request body with action, nonce, signature, and optional vault address
- Executes the HTTP POST request to
/exchangeendpoint
§Hyperliquid Signature Details
- Uses EIP-712 typed data signing
- Domain: HyperliquidSignTransaction, version 1
- Chain ID: 42161 (mainnet) or 421614 (testnet)
- Signature format: { r: “0x…”, s: “0x…”, v: 27|28 }
§Returns
Returns the raw serde_json::Value response for further parsing.
§Errors
- Returns authentication error if private key is missing
- Returns network error if the request fails
- Returns exchange error if the API returns an error response
§Example
let hyperliquid = HyperLiquid::builder()
.private_key("0x...")
.testnet(true)
.build()?;
let action = json!({
"type": "order",
"orders": [{"a": 0, "b": true, "p": "50000", "s": "0.001", "r": false, "t": {"limit": {"tif": "Gtc"}}}],
"grouping": "na"
});
let response = hyperliquid.signed_action(action)
.execute()
.await?;
println!("Response: {:?}", response);Auto Trait Implementations§
impl<'a> Freeze for HyperliquidSignedRequestBuilder<'a>
impl<'a> !RefUnwindSafe for HyperliquidSignedRequestBuilder<'a>
impl<'a> Send for HyperliquidSignedRequestBuilder<'a>
impl<'a> Sync for HyperliquidSignedRequestBuilder<'a>
impl<'a> Unpin for HyperliquidSignedRequestBuilder<'a>
impl<'a> !UnwindSafe for HyperliquidSignedRequestBuilder<'a>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more