pub struct OrderSubmitter { /* private fields */ }Expand description
Order submission facade for dYdX v4.
Provides a clean API for order submission, internally coordinating:
TransactionManager: Owns wallet, handles sequence + signingTxBroadcaster: Handles gRPC broadcast with retryOrderMessageBuilder: Constructs proto messages
§Wallet Ownership
The wallet is owned by TransactionManager (passed at construction via private_key).
This eliminates the need to pass &wallet to every method.
§Block Time Monitor
block_time_monitor provides current block height and dynamic block time estimation.
Updated externally by WebSocket, read by order methods.
§Thread Safety
All methods are safe to call from multiple tasks concurrently.
Implementations§
Source§impl OrderSubmitter
impl OrderSubmitter
Sourcepub fn new(
grpc_client: DydxGrpcClient,
http_client: DydxHttpClient,
private_key: &str,
wallet_address: String,
subaccount_number: u32,
chain_id: ChainId,
block_time_monitor: Arc<BlockTimeMonitor>,
) -> Result<Self, DydxError>
pub fn new( grpc_client: DydxGrpcClient, http_client: DydxHttpClient, private_key: &str, wallet_address: String, subaccount_number: u32, chain_id: ChainId, block_time_monitor: Arc<BlockTimeMonitor>, ) -> Result<Self, DydxError>
Creates a new order submitter with wallet owned internally.
§Arguments
grpc_client- gRPC client for chain queries and broadcastinghttp_client- HTTP client (provides market params cache)private_key- Private key (hex-encoded) - wallet created internallywallet_address- Main account address (may differ from derived address for permissioned keys)subaccount_number- dYdX subaccount number (typically 0)chain_id- dYdX chain IDblock_time_monitor- Block time monitor (provides current height and dynamic block time)
§Errors
Returns error if wallet creation from private key fails.
Sourcepub fn from_components(
tx_manager: Arc<TransactionManager>,
broadcaster: Arc<TxBroadcaster>,
order_builder: Arc<OrderMessageBuilder>,
block_time_monitor: Arc<BlockTimeMonitor>,
) -> Self
pub fn from_components( tx_manager: Arc<TransactionManager>, broadcaster: Arc<TxBroadcaster>, order_builder: Arc<OrderMessageBuilder>, block_time_monitor: Arc<BlockTimeMonitor>, ) -> Self
Creates a new order submitter from pre-built components.
Use this when you already have initialized components (e.g., from DydxExecutionClient).
Sourcepub fn current_block_height(&self) -> u32
pub fn current_block_height(&self) -> u32
Returns the current block height.
Sourcepub fn block_time_monitor(&self) -> &BlockTimeMonitor
pub fn block_time_monitor(&self) -> &BlockTimeMonitor
Returns a reference to the block time monitor.
Sourcepub fn wallet_address(&self) -> &str
pub fn wallet_address(&self) -> &str
Returns the wallet address.
Sourcepub fn order_builder(&self) -> &OrderMessageBuilder
pub fn order_builder(&self) -> &OrderMessageBuilder
Returns a reference to the order builder.
Sourcepub fn tx_manager(&self) -> &TransactionManager
pub fn tx_manager(&self) -> &TransactionManager
Returns a reference to the transaction manager.
Sourcepub async fn submit_market_order(
&self,
instrument_id: InstrumentId,
client_order_id: u32,
client_metadata: u32,
side: OrderSide,
quantity: Quantity,
) -> Result<String, DydxError>
pub async fn submit_market_order( &self, instrument_id: InstrumentId, client_order_id: u32, client_metadata: u32, side: OrderSide, quantity: Quantity, ) -> Result<String, DydxError>
Sourcepub async fn submit_limit_order(
&self,
instrument_id: InstrumentId,
client_order_id: u32,
client_metadata: u32,
side: OrderSide,
price: Price,
quantity: Quantity,
time_in_force: TimeInForce,
post_only: bool,
reduce_only: bool,
expire_time: Option<i64>,
) -> Result<String, DydxError>
pub async fn submit_limit_order( &self, instrument_id: InstrumentId, client_order_id: u32, client_metadata: u32, side: OrderSide, price: Price, quantity: Quantity, time_in_force: TimeInForce, post_only: bool, reduce_only: bool, expire_time: Option<i64>, ) -> Result<String, DydxError>
Sourcepub async fn submit_limit_orders_batch(
&self,
orders: Vec<LimitOrderParams>,
) -> Result<Vec<String>, DydxError>
pub async fn submit_limit_orders_batch( &self, orders: Vec<LimitOrderParams>, ) -> Result<Vec<String>, DydxError>
Submits a batch of limit orders.
§Protocol Constraints
- Short-term orders cannot be batched: If any order is short-term (IOC, FOK, or expire_time within 60s), each order is submitted in a separate transaction.
- Long-term orders can be batched: All orders in a single transaction.
§Returns
A vector of transaction hashes (one per transaction).
§Errors
Returns DydxError if any submission fails.
Sourcepub async fn cancel_order(
&self,
instrument_id: InstrumentId,
client_order_id: u32,
time_in_force: TimeInForce,
expire_time_ns: Option<UnixNanos>,
) -> Result<String, DydxError>
pub async fn cancel_order( &self, instrument_id: InstrumentId, client_order_id: u32, time_in_force: TimeInForce, expire_time_ns: Option<UnixNanos>, ) -> Result<String, DydxError>
Sourcepub async fn cancel_orders_batch(
&self,
orders: &[(InstrumentId, u32, TimeInForce, Option<UnixNanos>)],
) -> Result<String, DydxError>
pub async fn cancel_orders_batch( &self, orders: &[(InstrumentId, u32, TimeInForce, Option<UnixNanos>)], ) -> Result<String, DydxError>
Cancels multiple orders in a single blockchain transaction.
Batches all cancellation messages into one transaction for efficiency.
§Arguments
orders- Slice of (instrument_id, client_order_id, time_in_force, expire_time_ns) tuples
§Returns
The transaction hash on success.
§Errors
Returns DydxError if transaction broadcast fails or market params not found.
Sourcepub async fn submit_stop_market_order(
&self,
instrument_id: InstrumentId,
client_order_id: u32,
client_metadata: u32,
side: OrderSide,
trigger_price: Price,
quantity: Quantity,
reduce_only: bool,
expire_time: Option<i64>,
) -> Result<String, DydxError>
pub async fn submit_stop_market_order( &self, instrument_id: InstrumentId, client_order_id: u32, client_metadata: u32, side: OrderSide, trigger_price: Price, quantity: Quantity, reduce_only: bool, expire_time: Option<i64>, ) -> Result<String, DydxError>
Sourcepub async fn submit_stop_limit_order(
&self,
instrument_id: InstrumentId,
client_order_id: u32,
client_metadata: u32,
side: OrderSide,
trigger_price: Price,
limit_price: Price,
quantity: Quantity,
time_in_force: TimeInForce,
post_only: bool,
reduce_only: bool,
expire_time: Option<i64>,
) -> Result<String, DydxError>
pub async fn submit_stop_limit_order( &self, instrument_id: InstrumentId, client_order_id: u32, client_metadata: u32, side: OrderSide, trigger_price: Price, limit_price: Price, quantity: Quantity, time_in_force: TimeInForce, post_only: bool, reduce_only: bool, expire_time: Option<i64>, ) -> Result<String, DydxError>
Sourcepub async fn submit_take_profit_market_order(
&self,
instrument_id: InstrumentId,
client_order_id: u32,
client_metadata: u32,
side: OrderSide,
trigger_price: Price,
quantity: Quantity,
reduce_only: bool,
expire_time: Option<i64>,
) -> Result<String, DydxError>
pub async fn submit_take_profit_market_order( &self, instrument_id: InstrumentId, client_order_id: u32, client_metadata: u32, side: OrderSide, trigger_price: Price, quantity: Quantity, reduce_only: bool, expire_time: Option<i64>, ) -> Result<String, DydxError>
Sourcepub async fn submit_take_profit_limit_order(
&self,
instrument_id: InstrumentId,
client_order_id: u32,
client_metadata: u32,
side: OrderSide,
trigger_price: Price,
limit_price: Price,
quantity: Quantity,
time_in_force: TimeInForce,
post_only: bool,
reduce_only: bool,
expire_time: Option<i64>,
) -> Result<String, DydxError>
pub async fn submit_take_profit_limit_order( &self, instrument_id: InstrumentId, client_order_id: u32, client_metadata: u32, side: OrderSide, trigger_price: Price, limit_price: Price, quantity: Quantity, time_in_force: TimeInForce, post_only: bool, reduce_only: bool, expire_time: Option<i64>, ) -> Result<String, DydxError>
Sourcepub async fn submit_conditional_order(
&self,
instrument_id: InstrumentId,
client_order_id: u32,
client_metadata: u32,
order_type: ConditionalOrderType,
side: OrderSide,
trigger_price: Price,
limit_price: Option<Price>,
quantity: Quantity,
time_in_force: Option<TimeInForce>,
post_only: bool,
reduce_only: bool,
expire_time: Option<i64>,
) -> Result<String, DydxError>
pub async fn submit_conditional_order( &self, instrument_id: InstrumentId, client_order_id: u32, client_metadata: u32, order_type: ConditionalOrderType, side: OrderSide, trigger_price: Price, limit_price: Option<Price>, quantity: Quantity, time_in_force: Option<TimeInForce>, post_only: bool, reduce_only: bool, expire_time: Option<i64>, ) -> Result<String, DydxError>
Trait Implementations§
Auto Trait Implementations§
impl Freeze for OrderSubmitter
impl !RefUnwindSafe for OrderSubmitter
impl Send for OrderSubmitter
impl Sync for OrderSubmitter
impl Unpin for OrderSubmitter
impl UnsafeUnpin for OrderSubmitter
impl !UnwindSafe for OrderSubmitter
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<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].