HyperliquidSignedRequestBuilder

Struct HyperliquidSignedRequestBuilder 

Source
pub struct HyperliquidSignedRequestBuilder<'a> { /* private fields */ }
Expand description

Builder for creating authenticated Hyperliquid exchange actions.

This builder encapsulates the EIP-712 signing workflow:

  1. Private key validation
  2. Nonce generation (millisecond timestamp)
  3. EIP-712 signature generation via HyperLiquidAuth.sign_l1_action()
  4. Request body construction with action, nonce, signature, and optional vault address
  5. HTTP POST request execution to /exchange endpoint

§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>

Source

pub fn new(hyperliquid: &'a HyperLiquid, action: Value) -> Self

Creates a new signed action builder.

§Arguments
  • hyperliquid - Reference to the HyperLiquid exchange instance
  • action - 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);
Source

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?;
Source

pub async fn execute(self) -> Result<Value>

Executes the signed action and returns the response.

This method:

  1. Validates that a private key is configured
  2. Gets or generates the nonce (millisecond timestamp)
  3. Signs the action using EIP-712 typed data signing
  4. Constructs the request body with action, nonce, signature, and optional vault address
  5. Executes the HTTP POST request to /exchange endpoint
§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§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more