Skip to main content

OrderBuilder

Struct OrderBuilder 

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

Order builder.

Note that the price input to the OrderBuilder is in the “common” units of the perpetual/currency, not the quantized/atomic value.

Two main classes of orders in dYdX from persistence perspective are short-term and long-term (stateful) orders.

For different types of orders see also Stop-Limit Versus Stop-Loss and Perpetual order types on dYdX Chain.

Implementations§

Source§

impl OrderBuilder

Source

pub fn new( market_params: OrderMarketParams, subaccount_owner: String, subaccount_number: u32, client_id: u32, client_metadata: u32, ) -> Self

Create a new Order builder.

§Arguments
  • market_params - Market parameters for price/quantity quantization
  • subaccount_owner - The wallet address that owns the subaccount
  • subaccount_number - The subaccount number (usually 0)
  • client_id - The primary client order ID (u32)
  • client_metadata - Metadata for bidirectional ClientOrderId encoding
Source

pub fn market(self, side: OrderSide, size: Decimal) -> Self

Set as Market order.

An instruction to immediately buy or sell an asset at the best available price when the order is placed. dYdX implements market orders as IOC limit orders with a slippage-adjusted worst-case price.

Source

pub fn limit(self, side: OrderSide, price: Decimal, size: Decimal) -> Self

Set as Limit order.

With a limit order, a trader specifies the price at which they’re willing to buy or sell an asset. Unlike market orders, limit orders don’t go into effect until the market price hits a trader’s “limit price.”

Source

pub fn stop_limit( self, side: OrderSide, price: Decimal, trigger_price: Decimal, size: Decimal, ) -> Self

Set as Stop Limit order.

Stop-limit orders use a stop trigger_price and a limit price to give investors greater control over their trades.

Source

pub fn stop_market( self, side: OrderSide, trigger_price: Decimal, size: Decimal, ) -> Self

Set as Stop Market order.

When using a stop order, the trader sets a trigger_price to trigger a buy or sell order on their exchange.

Source

pub fn take_profit_limit( self, side: OrderSide, price: Decimal, trigger_price: Decimal, size: Decimal, ) -> Self

Set as Take Profit Limit order.

The order enters in force if the price reaches trigger_price and is executed at price after that.

Source

pub fn take_profit_market( self, side: OrderSide, trigger_price: Decimal, size: Decimal, ) -> Self

Set as Take Profit Market order.

The order enters in force if the price reaches trigger_price and converts to an ordinary market order.

Source

pub fn long_term(self) -> Self

Set order as a long-term order.

Source

pub fn short_term(self) -> Self

Set order as a short-term order.

Source

pub fn conditional(self) -> Self

Set order as a conditional order, triggered using trigger_price.

Source

pub fn price(self, price: Decimal) -> Self

Set the limit price for Limit orders.

Source

pub fn size(self, size: Decimal) -> Self

Set position size.

Source

pub fn time_in_force(self, tif: OrderTimeInForce) -> Self

Source

pub fn reduce_only(self, reduce: bool) -> Self

Set an order as reduce-only.

Source

pub fn until(self, gtof: OrderGoodUntil) -> Self

Set order’s expiration.

Source

pub fn build(self) -> Result<Order, Error>

Build the order.

§Errors

Returns an error if the order parameters are invalid.

Trait Implementations§

Source§

impl Clone for OrderBuilder

Source§

fn clone(&self) -> OrderBuilder

Returns a duplicate of the value. Read more
1.0.0 · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Debug for OrderBuilder

Source§

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

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

impl Default for OrderBuilder

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> CloneToUninit for T
where T: Clone,

Source§

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

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

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

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

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

Uses borrowed data to replace owned data, usually by cloning. Read more
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> Allocation for T
where T: RefUnwindSafe + Send + Sync,

§

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