Skip to main content

DeriveHttpClient

Struct DeriveHttpClient 

Source
pub struct DeriveHttpClient { /* private fields */ }
Expand description

HTTP client for the Derive REST API.

The client carries an atomic id counter so every request frame has a unique correlator; the REST transport ships only params on the wire but the id is preserved for logs and reused by the upcoming WebSocket client. Each call routes through a [RetryManager] that re-signs auth headers on every attempt, so retries never replay a stale X-DeriveTimestamp.

Implementations§

Source§

impl DeriveHttpClient

Source

pub fn new( base_url: impl Into<String>, timeout_secs: Option<u64>, proxy_url: Option<String>, retry_config: Option<RetryConfig>, ) -> Result<Self>

Creates a public-only client.

retry_config defaults to [http_retry_config(3, 100, 5_000)] when None.

§Errors

Returns an error if the underlying HTTP client (proxy URL, TLS init) cannot be constructed.

Source

pub fn with_credentials( base_url: impl Into<String>, credentials: DeriveCredentials, timeout_secs: Option<u64>, proxy_url: Option<String>, retry_config: Option<RetryConfig>, ) -> Result<Self>

Creates a client with credentials installed for send_private calls.

§Errors

Returns an error if the underlying HTTP client cannot be constructed.

Source

pub fn base_url(&self) -> &str

Returns the configured base URL (no trailing slash).

Source

pub fn has_credentials(&self) -> bool

Returns true when credentials are installed.

Source

pub async fn send_public<P, R>(&self, method: &str, params: &P) -> Result<R>

Sends an unauthenticated request and decodes the JSON-RPC envelope.

Public endpoints are idempotent reads; this path retries transient failures via the configured [RetryManager].

§Errors

Returns an error if transport, HTTP, or JSON-RPC processing fails.

Source

pub async fn send_private<P, R>(&self, method: &str, params: &P) -> Result<R>

Sends an authenticated idempotent request (private reads).

Used for private/get_* endpoints whose responses are pure reads of venue state. Transient failures retry via the configured [RetryManager].

§Errors

Returns an error if the client was built without credentials. Other variants propagate from the transport or the venue.

Source

pub async fn send_private_once<P, R>( &self, method: &str, params: &P, ) -> Result<R>

Sends an authenticated request exactly once (no retry).

Used for state-changing endpoints (private/order, private/cancel, private/cancel_all, private/cancel_by_label, private/replace) where a transport-level failure leaves the venue’s view of the signed action ambiguous: the request may have been accepted before the network broke. Automatic replay would either double-submit (when the venue accepted) or trigger a duplicate-nonce rejection (which the caller would surface as OrderRejected even though the original is live). Callers are expected to resolve ambiguous outcomes via reconciliation rather than retry here.

Instrument pacing uses the typed wrapper’s instrument or the body’s instrument_name field. Requests without an instrument consume only their wallet request budgets.

§Errors

Returns an error if the client was built without credentials. Other variants propagate from the transport or the venue.

Source

pub async fn get_instruments( &self, currency: &str, instrument_type: DeriveInstrumentType, expired: bool, ) -> Result<Vec<DeriveInstrument>>

Fetches the venue’s listed instruments.

Fetches every page for currency and instrument_type. For options, expired selects either live (false) or expired (true) listings. Perpetuals and spot ignore expired.

§Errors

Returns an error if transport, HTTP, or JSON-RPC processing fails. Returns a decode error for invalid pagination counts or a page count that exceeds the collection limit.

Source

pub async fn get_instrument( &self, instrument_name: &str, ) -> Result<DeriveInstrument>

Fetches a single instrument definition by name.

Expired options remain queryable by name. Settlement prices appear here before they appear in the bulk listing.

§Errors

Returns an error if transport, HTTP, or JSON-RPC processing fails. Returns a decode error when the response names a different instrument.

Source

pub async fn get_trade_history( &self, instrument_name: &str, from_timestamp: Option<i64>, to_timestamp: Option<i64>, page: u32, page_size: u32, ) -> Result<DerivePublicTradesResult>

Fetches a page of public trade history for the instrument.

from_timestamp / to_timestamp are UNIX milliseconds and bound the returned window. page is 1-indexed; page_size is capped by the venue at 1000.

§Errors

Returns an error if transport, HTTP, or JSON-RPC processing fails.

Source

pub async fn get_funding_rate_history( &self, instrument_name: &str, start_timestamp: Option<i64>, end_timestamp: Option<i64>, period: Option<u32>, ) -> Result<DerivePublicFundingRateHistoryResult>

Fetches the public funding rate history for the instrument.

start_timestamp / end_timestamp are UNIX milliseconds. period, if provided, selects the sample interval in seconds.

§Errors

Returns an error if transport, HTTP, or JSON-RPC processing fails.

Source

pub async fn get_candles( &self, instrument_name: &str, start_timestamp: i64, end_timestamp: i64, period: u32, ) -> Result<Vec<DerivePublicCandle>>

Fetches OHLCV candles via public/get_tradingview_chart_data.

start_timestamp / end_timestamp are UNIX seconds and bound the returned window. period is the bucket size in seconds; the venue accepts 60, 300, 900, 1800, 3600, 14400, 28800, 86400, and 604800. The venue ships result as a flat array; the client decodes it directly into Vec<DerivePublicCandle>.

§Errors

Returns an error if transport, HTTP, or JSON-RPC processing fails.

Source

pub async fn get_tickers( &self, instrument_type: DeriveInstrumentType, currency: Option<&str>, expiry_date: Option<&str>, ) -> Result<DeriveTickersResult>

Fetches current ticker snapshots.

currency is the underlying ("ETH", "BTC", etc.). Options require both currency and expiry_date; perps and ERC-20 spot pairs reject expiry_date.

§Errors

Returns an error if transport, HTTP, or JSON-RPC processing fails.

Source

pub async fn get_ticker( &self, instrument_name: &str, ) -> Result<DeriveTickerSnapshot>

Fetches the current ticker snapshot for one instrument.

This is a single-instrument convenience wrapper over public/get_tickers, which replaced Derive’s deprecated public/get_ticker RPC.

§Errors

Returns an error if transport, HTTP, or JSON-RPC processing fails, or the response omits the requested instrument.

Source

pub async fn submit_order( &self, params: &DeriveOrderParams, ) -> Result<DeriveOrder>

Submits a signed order to the venue.

params must be the fully-built signed private/order body.

§Errors

Returns an error if no credentials were installed; otherwise propagates transport and venue errors.

Source

pub async fn cancel_order( &self, params: &DeriveCancelParams, ) -> Result<DeriveEmptyResult>

Cancels a single order by venue order id.

§Errors

Returns an error if no credentials were installed; otherwise propagates transport and venue errors.

Source

pub async fn cancel_all( &self, params: &DeriveCancelAllParams, ) -> Result<DeriveEmptyResult>

Cancels every open order on the subaccount, optionally scoped to an instrument.

§Errors

Returns an error if no credentials were installed; otherwise propagates transport and venue errors.

Source

pub async fn cancel_by_label( &self, params: &DeriveCancelByLabelParams, ) -> Result<DeriveCancelByLabelResult>

Cancels every open order for the given user label on the subaccount.

§Errors

Returns an error if no credentials were installed; otherwise propagates transport and venue errors.

Source

pub async fn replace_order( &self, params: &DeriveReplaceParams, ) -> Result<DeriveReplaceOutcome>

Submits a signed private/replace request that cancels one order before creating its replacement.

params must be the fully-built typed request body.

§Errors

Returns an error if no credentials were installed; otherwise propagates transport and venue errors.

Source

pub async fn get_subaccount( &self, params: &DeriveGetSubaccountParams, ) -> Result<DeriveSubaccount>

Returns the subaccount snapshot including margin, balances, and open orders.

§Errors

Returns an error if no credentials were installed; otherwise propagates transport and venue errors. Returns a decode error if a response subaccount ID differs from the request.

Source

pub async fn get_open_orders( &self, params: &DeriveGetOpenOrdersParams, ) -> Result<DeriveOpenOrdersResult>

Returns currently open orders for the subaccount.

§Errors

Returns an error if no credentials were installed; otherwise propagates transport and venue errors. Returns a decode error if a response subaccount ID differs from the request.

Source

pub async fn get_trigger_orders( &self, params: &DeriveGetTriggerOrdersParams, ) -> Result<DeriveOpenOrdersResult>

Returns currently untriggered trigger orders for the subaccount.

§Errors

Returns an error if no credentials were installed; otherwise propagates transport and venue errors. Returns a decode error if a response subaccount ID differs from the request.

Source

pub async fn get_order( &self, params: &DeriveGetOrderParams, ) -> Result<DeriveOrder>

Returns a single order by venue order id.

§Errors

Returns an error if no credentials were installed; otherwise propagates transport and venue errors. Returns a decode error if a response subaccount ID differs from the request.

Source

pub async fn get_order_history( &self, params: &DeriveGetOrderHistoryParams, ) -> Result<DeriveOrdersResult>

Returns one page of order history for the subaccount, optionally scoped to an instrument and time window.

from_timestamp / to_timestamp are UNIX milliseconds. page is 1-indexed and page_size is capped by the venue at 1000.

§Errors

Returns an error if no credentials were installed; otherwise propagates transport and venue errors. Returns a decode error if a response subaccount ID differs from the request.

Source

pub async fn get_private_trade_history( &self, params: &DeriveGetTradeHistoryParams, ) -> Result<DeriveTradesResult>

Returns one page of subaccount trade history.

§Errors

Returns an error if no credentials were installed; otherwise propagates transport and venue errors. Returns a decode error if a response subaccount ID differs from the request.

Source

pub async fn get_positions( &self, params: &DeriveGetPositionsParams, ) -> Result<DerivePositionsResult>

Returns the positions held by the subaccount.

§Errors

Returns an error if no credentials were installed; otherwise propagates transport and venue errors. Returns a decode error if a response subaccount ID differs from the request.

Trait Implementations§

Source§

impl Clone for DeriveHttpClient

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 Debug for DeriveHttpClient

Source§

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

Formats the value using the given formatter. Read more

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
§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

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.

§

impl<T> Instrument for T

§

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

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

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

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
§

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

§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Sized + 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
§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Sized + 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
§

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

§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Sized + 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
§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Sized + 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
§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

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

impl<T> Ungil for T
where T: Send,

§

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

§

fn vzip(self) -> V

§

impl<T> WithSubscriber for T

§

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
§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

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