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-LYRATIMESTAMP.
Implementations§
Source§impl DeriveHttpClient
impl DeriveHttpClient
Sourcepub fn new(
base_url: impl Into<String>,
timeout_secs: Option<u64>,
proxy_url: Option<String>,
retry_config: Option<RetryConfig>,
) -> Result<Self>
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 DeriveHttpError::Transport when the underlying HTTP client
(proxy URL, TLS init) cannot be constructed.
Sourcepub fn with_credentials(
base_url: impl Into<String>,
credentials: DeriveCredentials,
timeout_secs: Option<u64>,
proxy_url: Option<String>,
retry_config: Option<RetryConfig>,
) -> Result<Self>
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 DeriveHttpError::Transport when the underlying HTTP client
cannot be constructed.
Sourcepub fn has_credentials(&self) -> bool
pub fn has_credentials(&self) -> bool
Returns true when credentials are installed.
Sourcepub async fn send_public<P, R>(&self, method: &str, params: &P) -> Result<R>
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
Propagates transport, HTTP, and JSON-RPC errors. See DeriveHttpError.
Sourcepub async fn send_private<P, R>(&self, method: &str, params: &P) -> Result<R>
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 DeriveHttpError::MissingCredentials when the client was
built without credentials. Other variants propagate from the transport
or the venue.
Sourcepub async fn send_private_once<P, R>(
&self,
method: &str,
params: &P,
) -> Result<R>
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.
§Errors
Returns DeriveHttpError::MissingCredentials when the client was
built without credentials. Other variants propagate from the transport
or the venue.
Sourcepub async fn get_instruments(
&self,
currency: &str,
instrument_type: DeriveInstrumentType,
expired: bool,
) -> Result<Vec<DeriveInstrument>>
pub async fn get_instruments( &self, currency: &str, instrument_type: DeriveInstrumentType, expired: bool, ) -> Result<Vec<DeriveInstrument>>
Fetches the venue’s listed instruments.
currency is the perpetual/option underlying (e.g. "ETH"). When
expired is true the venue includes expired option strikes.
§Errors
Propagates DeriveHttpError for transport, HTTP, and JSON-RPC failures.
Sourcepub async fn get_instrument(
&self,
instrument_name: &str,
) -> Result<DeriveInstrument>
pub async fn get_instrument( &self, instrument_name: &str, ) -> Result<DeriveInstrument>
Fetches a single instrument definition by name.
Mirrors public/get_instrument, which the venue documents as the
per-asset variant of public/get_instruments. The returned record
matches one row of the bulk endpoint.
§Errors
Propagates DeriveHttpError for transport, HTTP, and JSON-RPC failures.
Sourcepub async fn get_trade_history(
&self,
instrument_name: &str,
from_timestamp: Option<i64>,
to_timestamp: Option<i64>,
page: u32,
page_size: u32,
) -> Result<DerivePublicTradesResult>
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
Propagates DeriveHttpError for transport, HTTP, and JSON-RPC failures.
Sourcepub async fn get_funding_rate_history(
&self,
instrument_name: &str,
start_timestamp: Option<i64>,
end_timestamp: Option<i64>,
period: Option<u32>,
) -> Result<DerivePublicFundingRateHistoryResult>
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
Propagates DeriveHttpError for transport, HTTP, and JSON-RPC failures.
Sourcepub async fn get_candles(
&self,
instrument_name: &str,
start_timestamp: i64,
end_timestamp: i64,
period: u32,
) -> Result<Vec<DerivePublicCandle>>
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
Propagates DeriveHttpError for transport, HTTP, and JSON-RPC failures.
Sourcepub async fn get_tickers(
&self,
instrument_type: DeriveInstrumentType,
currency: Option<&str>,
expiry_date: Option<&str>,
) -> Result<DeriveTickersResult>
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
Propagates DeriveHttpError for transport, HTTP, and JSON-RPC failures.
Sourcepub async fn get_ticker(
&self,
instrument_name: &str,
) -> Result<DeriveTickerSnapshot>
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
Propagates DeriveHttpError for transport, HTTP, JSON-RPC failures,
or when the response omits the requested instrument.
Sourcepub async fn submit_order(
&self,
params: &DeriveOrderParams,
) -> Result<DeriveOrder>
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 DeriveHttpError::MissingCredentials when no credentials
were installed; otherwise propagates transport and venue errors.
Sourcepub async fn cancel_order(
&self,
params: &DeriveCancelParams,
) -> Result<DeriveEmptyResult>
pub async fn cancel_order( &self, params: &DeriveCancelParams, ) -> Result<DeriveEmptyResult>
Cancels a single order by venue order id.
§Errors
Returns DeriveHttpError::MissingCredentials when no credentials
were installed; otherwise propagates transport and venue errors.
Sourcepub async fn cancel_all(
&self,
params: &DeriveCancelAllParams,
) -> Result<DeriveEmptyResult>
pub async fn cancel_all( &self, params: &DeriveCancelAllParams, ) -> Result<DeriveEmptyResult>
Cancels every open order on the subaccount, optionally scoped to an instrument.
§Errors
Returns DeriveHttpError::MissingCredentials when no credentials
were installed; otherwise propagates transport and venue errors.
Sourcepub async fn cancel_by_label(
&self,
params: &DeriveCancelByLabelParams,
) -> Result<DeriveEmptyResult>
pub async fn cancel_by_label( &self, params: &DeriveCancelByLabelParams, ) -> Result<DeriveEmptyResult>
Cancels every open order for the given user label on the subaccount.
§Errors
Returns DeriveHttpError::MissingCredentials when no credentials
were installed; otherwise propagates transport and venue errors.
Sourcepub async fn replace_order(
&self,
params: &DeriveReplaceParams,
) -> Result<DeriveOrder>
pub async fn replace_order( &self, params: &DeriveReplaceParams, ) -> Result<DeriveOrder>
Submits a signed private/replace request that atomically cancels one
order and creates a new one.
params must be the fully-built typed request body.
§Errors
Returns DeriveHttpError::MissingCredentials when no credentials
were installed; otherwise propagates transport and venue errors.
Sourcepub async fn get_subaccount(
&self,
params: &DeriveGetSubaccountParams,
) -> Result<DeriveSubaccount>
pub async fn get_subaccount( &self, params: &DeriveGetSubaccountParams, ) -> Result<DeriveSubaccount>
Returns the subaccount snapshot including margin, balances, and open orders.
§Errors
Returns DeriveHttpError::MissingCredentials when no credentials
were installed; otherwise propagates transport and venue errors.
Sourcepub async fn get_open_orders(
&self,
params: &DeriveGetOpenOrdersParams,
) -> Result<DeriveOpenOrdersResult>
pub async fn get_open_orders( &self, params: &DeriveGetOpenOrdersParams, ) -> Result<DeriveOpenOrdersResult>
Returns currently open orders for the subaccount.
§Errors
Returns DeriveHttpError::MissingCredentials when no credentials
were installed; otherwise propagates transport and venue errors.
Sourcepub async fn get_trigger_orders(
&self,
params: &DeriveGetTriggerOrdersParams,
) -> Result<DeriveOpenOrdersResult>
pub async fn get_trigger_orders( &self, params: &DeriveGetTriggerOrdersParams, ) -> Result<DeriveOpenOrdersResult>
Returns currently untriggered trigger orders for the subaccount.
§Errors
Returns DeriveHttpError::MissingCredentials when no credentials
were installed; otherwise propagates transport and venue errors.
Sourcepub async fn get_order(
&self,
params: &DeriveGetOrderParams,
) -> Result<DeriveOrder>
pub async fn get_order( &self, params: &DeriveGetOrderParams, ) -> Result<DeriveOrder>
Returns a single order by venue order id.
§Errors
Returns DeriveHttpError::MissingCredentials when no credentials
were installed; otherwise propagates transport and venue errors.
Sourcepub async fn get_order_history(
&self,
params: &DeriveGetOrderHistoryParams,
) -> Result<DeriveOrdersResult>
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 DeriveHttpError::MissingCredentials when no credentials
were installed; otherwise propagates transport and venue errors.
Sourcepub async fn get_private_trade_history(
&self,
params: &DeriveGetTradeHistoryParams,
) -> Result<DeriveTradesResult>
pub async fn get_private_trade_history( &self, params: &DeriveGetTradeHistoryParams, ) -> Result<DeriveTradesResult>
Returns one page of subaccount trade history.
§Errors
Returns DeriveHttpError::MissingCredentials when no credentials
were installed; otherwise propagates transport and venue errors.
Sourcepub async fn get_positions(
&self,
params: &DeriveGetPositionsParams,
) -> Result<DerivePositionsResult>
pub async fn get_positions( &self, params: &DeriveGetPositionsParams, ) -> Result<DerivePositionsResult>
Returns the positions held by the subaccount.
§Errors
Returns DeriveHttpError::MissingCredentials when no credentials
were installed; otherwise propagates transport and venue errors.
Trait Implementations§
Source§impl Clone for DeriveHttpClient
impl Clone for DeriveHttpClient
Source§fn clone(&self) -> DeriveHttpClient
fn clone(&self) -> DeriveHttpClient
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreAuto Trait Implementations§
impl !RefUnwindSafe for DeriveHttpClient
impl !UnwindSafe for DeriveHttpClient
impl Freeze for DeriveHttpClient
impl Send for DeriveHttpClient
impl Sync for DeriveHttpClient
impl Unpin for DeriveHttpClient
impl UnsafeUnpin for DeriveHttpClient
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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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