Skip to main content

Client

Struct Client 

Source
pub struct Client<H> { /* private fields */ }
Expand description

Papertrade client over one transport. Cheap to clone when the transport is.

Implementations§

Source§

impl<H: Http + Clone> Client<H>

Source

pub async fn session( &self, store: &impl Store, owner: Address, ) -> Result<Option<SessionRecord>, Error>

The session key stored for owner, if readable.

Source

pub async fn key_state( &self, store: &impl Store, owner: Address, account: Option<&Account>, ) -> Result<KeyState, Error>

Where owner’s stored key stands, given the account as last streamed.

Source

pub async fn new_session( &self, store: &impl Store, owner: Address, ) -> Result<SessionRecord, Error>

Makes and stores a session key for owner, unless the stored one is still usable.

Source

pub async fn register( &self, store: &impl Store, wallet: &impl Wallet, ) -> Result<SessionRecord, Error>

Has the wallet register the stored session key (made first if none is usable) and posts the registration to the relayer once.

Source

pub async fn enable( &self, store: &impl Store, wallet: &impl Wallet, account: Option<&Account>, ) -> Result<KeyState, Error>

Enables trading: makes a session key if needed and registers it unless it is ready. At most one wallet prompt.

Source

pub async fn session_key( &self, store: &impl Store, owner: Address, account: Option<&Account>, ) -> Result<SessionKey, Error>

owner’s session key as a signer, or Error::NeedsKey with the step to take first.

Source§

impl<H: Http + Clone> Client<H>

Source

pub async fn trading_state(&self) -> Result<TradingState, Error>

Every market’s parameters, open interest and caps, and which intents the relayer accepts now.

Source

pub async fn summary(&self) -> Result<Summary, Error>

TVL, LP, queue, fees, and PAPER’s supply and curve.

Source

pub async fn volumes(&self) -> Result<Vec<(u32, u128)>, Error>

Each market’s notional over the last day, by instrument id.

Source

pub async fn queue(&self) -> Result<QueueSummary, Error>

The payout queue: total owed to queued winners, count, and its largest and front entries.

Source

pub async fn recent_trades(&self) -> Result<Vec<Trade>, Error>

The latest trades across the venue, newest first.

Source

pub async fn queue_rank(&self, owner: Address) -> Result<QueueRank, Error>

Where owner’s queued intents stand in the relayer’s queue.

Source

pub async fn quote(&self, asset_index: u32) -> Result<Quote, Error>

The market’s BBO from the oracle’s on-chain source (asset_index is Hyperliquid’s perp index). An intent sent now executes at its mid, give or take a block.

Source

pub async fn deposit_address(&self, owner: Address) -> Result<Address, Error>

owner’s deposit address, derived on chain. USDC sent to it on HyperCore is swept into the venue and credited to owner.

Source

pub async fn pending_reward(&self, owner: Address) -> Result<u128, Error>

USDC staking rewards distributed to owner and not yet paid, in collateral units.

Source

pub async fn win_fee_rate(&self) -> Result<u128, Error>

The Exchange contract’s current win fee, an 18-decimal fraction.

Source

pub fn stream_url(&self, owner: Address) -> String

URL of owner’s account stream (server-sent events liveness, wallet, heartbeat). Each wallet event’s data folds into the account with Account::apply.

Source§

impl<H: Http + Clone> Client<H>

Source

pub fn new(http: H, config: Config) -> Self

Source

pub const fn config(&self) -> &Config

Source

pub const fn http(&self) -> &H

Source

pub fn relayer(&self) -> Relayer<H>

Source§

impl<H: Http + Clone> Client<H>

Source

pub async fn cancel( &self, store: &impl Store, owner: Address, account: Option<&Account>, intent_id: [u8; 32], ) -> Result<Accepted, Error>

Cancels a queued intent (intent_id) before the relayer sends it. The relayer’s answer is returned as is, without checking that it kept the cancel.

Source§

impl<H: Http + Clone> Client<H>

Source

pub async fn close( &self, store: &impl Store, owner: Address, account: Option<&Account>, ids: &[u128], ) -> Result<Vec<Accepted>, Error>

Closes whole positions by id, at most 12 per intent, with one answer per intent. A failure after the first leaves the rest unsent.

Source§

impl<H: Http + Clone> Client<H>

Source

pub async fn open( &self, store: &impl Store, owner: Address, account: &Account, open: Open, mark: Option<u128>, ) -> Result<Accepted, Error>

Opens a position for owner, signed by the session key, at the BBO mid of the relayer’s batch. It is first checked against a fresh trading state, account as last streamed, and mark (the current mid, raw) for the side’s open-interest cap.

Source§

impl<H: Http + Clone> Client<H>

Source

pub async fn stake( &self, store: &impl Store, wallet: &impl Wallet, amount: u128, ) -> Result<Accepted, Error>

Stakes amount PAPER (18 decimals) immediately. The wallet signs.

Source

pub async fn unstake( &self, store: &impl Store, wallet: &impl Wallet, amount: u128, ) -> Result<Accepted, Error>

Unstakes amount PAPER (18 decimals) immediately. Distributed rewards stay claimable. The wallet signs.

Source

pub async fn claim( &self, store: &impl Store, wallet: &impl Wallet, ) -> Result<Accepted, Error>

Claims every distributed USDC reward into the account’s balance. The wallet signs.

Source§

impl<H: Http + Clone> Client<H>

Source

pub async fn take_nonce( &self, store: &impl Store, owner: Address, lane: Lane, ) -> Result<u128, Error>

Returns lane’s next nonce for owner and stores the one after it. An unused lane starts at a random point.

Source§

impl<H: Http + Clone> Client<H>

Source

pub async fn withdraw( &self, store: &impl Store, wallet: &impl Wallet, account: Option<&Account>, usdc: u128, ) -> Result<Accepted, Error>

Withdraws usdc (6 decimals, at least 10 USDC) of the available balance to the wallet’s own HyperCore spot account, never anywhere else. The wallet signs.

Source§

impl<H: Http + Clone> Client<H>

Source

pub async fn register_deposit(&self, owner: Address) -> Result<Address, Error>

Registers owner’s deposit address with the relayer’s sweeper and returns it.

Source

pub async fn plan_deposit( &self, owner: Address, usdc: u64, source: Source, mode: Mode, ) -> Result<Deposit, Error>

Plans a deposit of usdc (6 decimals, at least 10 USDC) from source, after registering the address and checking it against the one derived on chain. When the address has no HyperCore account, its first send also pays ACTIVATION_FEE_USDC from the source balance; a perp balance moves to spot first, fee included.

Source

pub async fn send_deposit( &self, wallet: &impl Wallet, deposit: &Deposit, ) -> Result<(), Error>

Has the wallet sign each send in order and posts it to Hyperliquid once. A failed send leaves the later ones unsent; an HTTP status other than 2xx is TransportError::Status.

Trait Implementations§

Source§

impl<H: Clone> Clone for Client<H>

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<H: Debug> Debug for Client<H>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<H> Freeze for Client<H>
where H: Freeze,

§

impl<H> RefUnwindSafe for Client<H>
where H: RefUnwindSafe,

§

impl<H> Send for Client<H>
where H: Send,

§

impl<H> Sync for Client<H>
where H: Sync,

§

impl<H> Unpin for Client<H>
where H: Unpin,

§

impl<H> UnsafeUnpin for Client<H>
where H: UnsafeUnpin,

§

impl<H> UnwindSafe for Client<H>
where H: UnwindSafe,

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

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

Source§

type Error = !

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

fn try_from(value: U) -> Result<T, !>

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.