pub struct DydxRawHttpClient { /* private fields */ }Expand description
Provides a raw HTTP client for interacting with the dYdX v4 Indexer REST API.
This client wraps the underlying HttpClient to handle functionality
specific to dYdX Indexer API, such as rate-limiting, forming request URLs,
and deserializing responses into dYdX specific data models.
Note: Unlike traditional centralized exchanges, the dYdX v4 Indexer REST API does NOT require authentication, API keys, or request signing. All endpoints are publicly accessible.
Implementations§
Source§impl DydxRawHttpClient
impl DydxRawHttpClient
Sourcepub fn cancel_all_requests(&self)
pub fn cancel_all_requests(&self)
Cancel all pending HTTP requests.
Sourcepub fn cancellation_token(&self) -> &CancellationToken
pub fn cancellation_token(&self) -> &CancellationToken
Get the cancellation token for this client.
Sourcepub fn new(
base_url: Option<String>,
timeout_secs: Option<u64>,
proxy_url: Option<String>,
is_testnet: bool,
retry_config: Option<RetryConfig>,
) -> Result<Self>
pub fn new( base_url: Option<String>, timeout_secs: Option<u64>, proxy_url: Option<String>, is_testnet: bool, retry_config: Option<RetryConfig>, ) -> Result<Self>
Creates a new DydxRawHttpClient using the default dYdX Indexer HTTP URL,
optionally overridden with a custom base URL.
Note: No credentials are required as the dYdX Indexer API is publicly accessible.
§Errors
Returns an error if the retry manager cannot be created.
Sourcepub const fn is_testnet(&self) -> bool
pub const fn is_testnet(&self) -> bool
Check if this client is configured for testnet.
Sourcepub async fn send_request<T>(
&self,
method: Method,
endpoint: &str,
query_params: Option<&str>,
) -> Result<T, DydxHttpError>where
T: DeserializeOwned,
pub async fn send_request<T>(
&self,
method: Method,
endpoint: &str,
query_params: Option<&str>,
) -> Result<T, DydxHttpError>where
T: DeserializeOwned,
Send a request to a dYdX Indexer API endpoint.
Note: dYdX Indexer API does not require authentication headers.
§Errors
Returns an error if:
- The HTTP request fails.
- The response has a non-success HTTP status code.
- The response body cannot be deserialized to type
T. - The request is canceled.
Sourcepub async fn send_post_request<T, B>(
&self,
endpoint: &str,
body: &B,
) -> Result<T, DydxHttpError>where
T: DeserializeOwned,
B: Serialize,
pub async fn send_post_request<T, B>(
&self,
endpoint: &str,
body: &B,
) -> Result<T, DydxHttpError>where
T: DeserializeOwned,
B: Serialize,
Send a POST request to a dYdX Indexer API endpoint.
Note: Most dYdX Indexer endpoints are GET-based. POST is rarely used.
§Errors
Returns an error if:
- The request body cannot be serialized to JSON.
- The HTTP request fails.
- The response has a non-success HTTP status code.
- The response body cannot be deserialized to type
T. - The request is canceled.
Sourcepub async fn get_markets(&self) -> Result<MarketsResponse, DydxHttpError>
pub async fn get_markets(&self) -> Result<MarketsResponse, DydxHttpError>
Fetch all perpetual markets from dYdX.
§Errors
Returns an error if the HTTP request fails or response parsing fails.
Sourcepub async fn fetch_instruments(
&self,
maker_fee: Option<Decimal>,
taker_fee: Option<Decimal>,
) -> Result<Vec<InstrumentAny>, DydxHttpError>
pub async fn fetch_instruments( &self, maker_fee: Option<Decimal>, taker_fee: Option<Decimal>, ) -> Result<Vec<InstrumentAny>, DydxHttpError>
Fetch all instruments and parse them into Nautilus InstrumentAny types.
This method fetches all perpetual markets from dYdX and converts them
into Nautilus instrument definitions using the parse_instrument_any function.
§Errors
Returns an error if:
- The HTTP request fails.
- The response cannot be parsed.
- Any instrument parsing fails.
Sourcepub async fn get_orderbook(
&self,
ticker: &str,
) -> Result<OrderbookResponse, DydxHttpError>
pub async fn get_orderbook( &self, ticker: &str, ) -> Result<OrderbookResponse, DydxHttpError>
Fetch orderbook for a specific market.
§Errors
Returns an error if the HTTP request fails or response parsing fails.
Sourcepub async fn get_trades(
&self,
ticker: &str,
limit: Option<u32>,
) -> Result<TradesResponse, DydxHttpError>
pub async fn get_trades( &self, ticker: &str, limit: Option<u32>, ) -> Result<TradesResponse, DydxHttpError>
Fetch recent trades for a market.
§Errors
Returns an error if the HTTP request fails or response parsing fails.
Sourcepub async fn get_candles(
&self,
ticker: &str,
resolution: DydxCandleResolution,
limit: Option<u32>,
from_iso: Option<DateTime<Utc>>,
to_iso: Option<DateTime<Utc>>,
) -> Result<CandlesResponse, DydxHttpError>
pub async fn get_candles( &self, ticker: &str, resolution: DydxCandleResolution, limit: Option<u32>, from_iso: Option<DateTime<Utc>>, to_iso: Option<DateTime<Utc>>, ) -> Result<CandlesResponse, DydxHttpError>
Fetch candles/klines for a market.
§Errors
Returns an error if the HTTP request fails or response parsing fails.
Sourcepub async fn get_subaccount(
&self,
address: &str,
subaccount_number: u32,
) -> Result<SubaccountResponse, DydxHttpError>
pub async fn get_subaccount( &self, address: &str, subaccount_number: u32, ) -> Result<SubaccountResponse, DydxHttpError>
Fetch subaccount information.
§Errors
Returns an error if the HTTP request fails or response parsing fails.
Sourcepub async fn get_fills(
&self,
address: &str,
subaccount_number: u32,
market: Option<&str>,
limit: Option<u32>,
) -> Result<FillsResponse, DydxHttpError>
pub async fn get_fills( &self, address: &str, subaccount_number: u32, market: Option<&str>, limit: Option<u32>, ) -> Result<FillsResponse, DydxHttpError>
Fetch fills for a subaccount.
§Errors
Returns an error if the HTTP request fails or response parsing fails.
Sourcepub async fn get_orders(
&self,
address: &str,
subaccount_number: u32,
market: Option<&str>,
limit: Option<u32>,
) -> Result<OrdersResponse, DydxHttpError>
pub async fn get_orders( &self, address: &str, subaccount_number: u32, market: Option<&str>, limit: Option<u32>, ) -> Result<OrdersResponse, DydxHttpError>
Fetch orders for a subaccount.
§Errors
Returns an error if the HTTP request fails or response parsing fails.
Sourcepub async fn get_transfers(
&self,
address: &str,
subaccount_number: u32,
limit: Option<u32>,
) -> Result<TransfersResponse, DydxHttpError>
pub async fn get_transfers( &self, address: &str, subaccount_number: u32, limit: Option<u32>, ) -> Result<TransfersResponse, DydxHttpError>
Fetch transfers for a subaccount.
§Errors
Returns an error if the HTTP request fails or response parsing fails.
Sourcepub async fn get_time(&self) -> Result<TimeResponse, DydxHttpError>
pub async fn get_time(&self) -> Result<TimeResponse, DydxHttpError>
Get current server time.
§Errors
Returns an error if the HTTP request fails or response parsing fails.
Sourcepub async fn get_height(&self) -> Result<HeightResponse, DydxHttpError>
pub async fn get_height(&self) -> Result<HeightResponse, DydxHttpError>
Get current blockchain height.
§Errors
Returns an error if the HTTP request fails or response parsing fails.
Trait Implementations§
Source§impl Debug for DydxRawHttpClient
impl Debug for DydxRawHttpClient
Auto Trait Implementations§
impl Freeze for DydxRawHttpClient
impl !RefUnwindSafe for DydxRawHttpClient
impl Send for DydxRawHttpClient
impl Sync for DydxRawHttpClient
impl Unpin for DydxRawHttpClient
impl !UnwindSafe for DydxRawHttpClient
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<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§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§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
T in a tonic::Request§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
T in a tonic::Request§impl<L> LayerExt<L> for L
impl<L> LayerExt<L> for L
§fn named_layer<S>(&self, service: S) -> Layered<<L as Layer<S>>::Service, S>where
L: Layer<S>,
fn named_layer<S>(&self, service: S) -> Layered<<L as Layer<S>>::Service, S>where
L: Layer<S>,
Layered].§impl<L> LayerExt<L> for L
impl<L> LayerExt<L> for L
§fn named_layer<S>(&self, service: S) -> Layered<<L as Layer<S>>::Service, S>where
L: Layer<S>,
fn named_layer<S>(&self, service: S) -> Layered<<L as Layer<S>>::Service, S>where
L: Layer<S>,
Layered].