DydxGrpcClient

Struct DydxGrpcClient 

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

gRPC client for dYdX v4 protocol operations.

This client handles:

  • Transaction signing and broadcasting.
  • Account query operations.
  • Order placement and management via Cosmos SDK messages.
  • Connection management and automatic failover to fallback nodes.

Implementations§

Source§

impl DydxGrpcClient

Source

pub async fn new(grpc_url: String) -> Result<Self, DydxError>

Create a new gRPC client with a single URL.

§Errors

Returns an error if the gRPC connection cannot be established.

Source

pub async fn new_with_fallback( grpc_urls: &[impl AsRef<str>], ) -> Result<Self, DydxError>

Create a new gRPC client with fallback support.

Attempts to connect to each URL in the provided list until a successful connection is established. This is useful for DEX environments where nodes can fail and fallback options are needed.

§Errors

Returns an error if none of the provided URLs can establish a connection.

Source

pub async fn reconnect_with_fallback( &mut self, grpc_urls: &[impl AsRef<str>], ) -> Result<(), DydxError>

Reconnect to a different gRPC node from the fallback list.

Attempts to establish a new connection to each URL in the provided list until successful. This is useful when the current node fails and you need to failover to a different validator node.

§Errors

Returns an error if none of the provided URLs can establish a connection.

Source

pub fn current_url(&self) -> &str

Get the currently connected gRPC node URL.

Source

pub fn channel(&self) -> &Channel

Get the underlying gRPC channel.

This can be used to create custom gRPC service clients.

Source

pub async fn query_address( &mut self, address: &str, ) -> Result<(u64, u64), Error>

Query account information for a given address.

Returns the account number and sequence number needed for transaction signing.

§Errors

Returns an error if the query fails or the account does not exist.

Source

pub async fn get_account(&mut self, address: &str) -> Result<BaseAccount, Error>

Query for an account by its address.

§Errors

Returns an error if the query fails or the account does not exist.

Source

pub async fn get_account_balances( &mut self, address: &str, ) -> Result<Vec<Coin>, Error>

Query for account balances by address for all denominations.

§Errors

Returns an error if the query fails.

Source

pub async fn get_node_info(&mut self) -> Result<GetNodeInfoResponse, Error>

Query for node info.

§Errors

Returns an error if the query fails.

Source

pub async fn latest_block(&mut self) -> Result<Block, Error>

Query for the latest block.

§Errors

Returns an error if the query fails.

Source

pub async fn latest_block_height(&mut self) -> Result<Height, Error>

Query for the latest block height.

§Errors

Returns an error if the query fails.

Source

pub async fn get_perpetuals(&mut self) -> Result<Vec<Perpetual>, Error>

Query for all perpetual markets.

§Errors

Returns an error if the query fails.

Source

pub async fn get_clob_pairs(&mut self) -> Result<Vec<ClobPair>, Error>

Query for all CLOB pairs.

§Errors

Returns an error if the query fails.

Source

pub async fn get_subaccount( &mut self, address: &str, number: u32, ) -> Result<SubaccountInfo, Error>

Query for subaccount information.

§Errors

Returns an error if the query fails.

Source

pub async fn simulate_tx(&mut self, tx_bytes: Vec<u8>) -> Result<u64, Error>

Simulate a transaction to estimate gas usage.

§Errors

Returns an error if simulation fails.

Source

pub async fn broadcast_tx(&mut self, tx_bytes: Vec<u8>) -> Result<TxHash, Error>

Broadcast a signed transaction.

§Errors

Returns an error if broadcasting fails.

Source

pub async fn get_tx(&mut self, hash: &str) -> Result<Tx, Error>

Query transaction by hash.

§Errors

Returns an error if the query fails.

Trait Implementations§

Source§

impl Clone for DydxGrpcClient

Source§

fn clone(&self) -> DydxGrpcClient

Returns a duplicate of the value. Read more
1.0.0§

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

Performs copy-assignment from source. Read more
Source§

impl Debug for DydxGrpcClient

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

§

impl<T> Any for T
where T: 'static + ?Sized,

§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
§

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

§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
§

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

§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
§

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

§

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
§

impl<T> From<T> for T

§

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
§

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

§

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

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

§

type Owned = T

The resulting type after obtaining ownership.
§

fn to_owned(&self) -> T

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

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

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

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

§

type Error = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
§

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

§

type Error = <U as TryFrom<T>>::Error

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

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,