DydxRawHttpClient

Struct DydxRawHttpClient 

Source
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

Source

pub fn cancel_all_requests(&self)

Cancel all pending HTTP requests.

Source

pub fn cancellation_token(&self) -> &CancellationToken

Get the cancellation token for this client.

Source

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.

Source

pub const fn is_testnet(&self) -> bool

Check if this client is configured for testnet.

Source

pub fn base_url(&self) -> &str

Get the base URL being used by this client.

Source

pub async fn send_request<T>( &self, method: Method, endpoint: &str, query_params: Option<&str>, ) -> Result<T, DydxHttpError>

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

pub async fn send_post_request<T, B>( &self, endpoint: &str, body: &B, ) -> Result<T, DydxHttpError>

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

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.

Source

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

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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

Source§

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

Formats the value using the given formatter. Read more
Source§

impl Default for DydxRawHttpClient

Source§

fn default() -> Self

Returns the “default value” for a type. 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
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> IntoRequest<T> for T

§

fn into_request(self) -> Request<T>

Wrap the input message T in a tonic::Request
§

impl<T> IntoRequest<T> for T

§

fn into_request(self) -> Request<T>

Wrap the input message T in a tonic::Request
§

impl<L> LayerExt<L> for L

§

fn named_layer<S>(&self, service: S) -> Layered<<L as Layer<S>>::Service, S>
where L: Layer<S>,

Applies the layer to a service and wraps it in [Layered].
§

impl<L> LayerExt<L> for L

§

fn named_layer<S>(&self, service: S) -> Layered<<L as Layer<S>>::Service, S>
where L: Layer<S>,

Applies the layer to a service and wraps it in [Layered].
§

impl<T> Pointable for T

§

const ALIGN: usize

The alignment of pointer.
§

type Init = T

The type for initializers.
§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
§

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

§

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
§

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

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
§

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