Enum OrderType
pub enum OrderType {
Limit,
Market,
Unspecified,
}Expand description
Order execution type determining how orders interact with the market.
This enum defines the fundamental execution behavior of orders, controlling how they interact with existing liquidity and what prices they can execute at. Order type is one of the most important parameters affecting execution outcomes.
§Execution Behavior
§Price Discovery vs Price Taking
- Limit orders: Specify maximum/minimum acceptable prices
- Market orders: Accept current market prices for immediate execution
§Liquidity Interaction
- Limit orders: Can add liquidity (maker) or take liquidity (taker)
- Market orders: Always take liquidity (taker behavior only)
§Order Type Characteristics
| Type | Price Control | Execution Speed | Liquidity Role | Price Risk |
|---|---|---|---|---|
| Limit | High | Variable | Maker/Taker | Low |
| Market | Low | Immediate | Taker Only | High |
§Usage Examples
§Limit orders for price control
use types::common::OrderType;
let limit_order = OrderType::Limit;
assert!(limit_order.is_persistant()); // Can rest on book
// Requires limit_price in SubmitOrderRequest
// Executes at specified price or better§Market orders for immediate execution
use types::common::OrderType;
let market_order = OrderType::Market;
assert!(!market_order.is_persistant()); // Never rests on book
// No limit_price allowed
// Executes immediately at best available prices§Validation Requirements
§Limit Orders
- Must specify
limit_price - Price must be positive and within market bounds
- Compatible with all time-in-force options
- Can use
post_onlyflag
§Market Orders
- Must NOT specify
limit_price - Cannot use
post_onlyflag (always takes liquidity) - Must use IOC or FOK time-in-force; a GTC or GTT market order is rejected
§Risk Considerations
§Limit Order Risks
- Execution risk: May not fill if price doesn’t reach limit
- Opportunity cost: Missing moves while waiting for target price
- Stale orders: Prices may move away from limit over time
§Market Order Risks
- Price risk: Execution price unknown until filled
- Slippage: Large orders may execute at multiple price levels
- Market impact: Can move prices unfavorably, especially in thin markets
§JSON Representation
"Limit" // Limit order execution
"Market" // Market order executionVariants§
Limit
Limit order - executes only at specified price or better.
Limit orders provide precise price control by specifying the exact price at which the order should execute. They will only execute at the limit price or at a more favorable price.
§Price Behavior
- Buy limits: Execute at limit price or lower (better)
- Sell limits: Execute at limit price or higher (better)
- No worse prices: Never execute at worse than limit price
§Execution Characteristics
- Conditional execution: May or may not execute
- Queue position: Earlier orders have priority at same price
- Partial fills: Common as liquidity becomes available
- Book resting: Can remain on book until filled or canceled
§Liquidity Role
- Maker: When limit price doesn’t cross existing orders
- Taker: When limit price matches or crosses existing orders
- Mixed: Can be maker initially, then taker as market moves
§Use Cases
- Target entry prices: “Buy only if price drops to $45,000”
- Profit targets: “Sell when price reaches $55,000”
- Budget constraints: “Don’t pay more than $3,000 per ETH”
- Fee optimization: Maker orders often have lower fees
§Requirements
- Must specify
limit_pricefield - Price must be positive and valid for the market
- Compatible with post-only flag for guaranteed maker behavior
Market
Market order - executes immediately at best available prices.
Market orders prioritize execution speed over price control, accepting whatever prices are currently available in the market. They provide guaranteed execution attempt but uncertain execution prices.
§Price Behavior
- Best available: Executes at current best bid/offer prices
- Price taking: Accepts existing prices, doesn’t set new ones
- Multiple levels: Large orders may execute across price levels
- No price limits: Will execute at any available price
§Execution Characteristics
- Immediate execution: Attempts to execute immediately
- Guaranteed attempt: Will always try to execute (subject to liquidity)
- No book resting: Never remains on order book
- Taker only: Always consumes existing liquidity
§Slippage Considerations
Large market orders may experience slippage:
- Expected: Execute at best bid/offer
- Reality: May execute across multiple price levels
- Impact: Larger orders have higher slippage risk
§Use Cases
- Urgent execution: When speed matters more than price
- Liquidity testing: Discovering available market depth
- Stop-loss execution: Exiting positions quickly
- Market opens: Getting filled at market reopening
§Restrictions
- Cannot specify
limit_pricefield - Cannot use
post_onlyflag (incompatible with taker-only behavior) - Must use IOC or FOK time-in-force; GTC and GTT are rejected
§Risk Management
- Consider market depth before large market orders
- Monitor for low liquidity periods
- Use limit orders when price control is important
- Consider IOC limits as alternative to pure market orders
Unspecified
Unspecified order type - invalid for actual orders.
This is what serde substitutes when a submitted request omits
order_type; validation then rejects the order. It is not
OrderType::default() — #[default] sits on Limit — and it is not
what SubmitOrderRequestBuilder starts from either: the builder holds
Option<OrderType> and build() reports a missing field.
§Behavior
- Always causes order validation to fail
- Never valid for order submission
- Should be replaced with Limit or Market before submission
Implementations§
§impl OrderType
impl OrderType
pub fn is_persistant(&self) -> bool
Trait Implementations§
impl Copy for OrderType
§impl<'de> Deserialize<'de> for OrderType
impl<'de> Deserialize<'de> for OrderType
§fn deserialize<__D>(
__deserializer: __D,
) -> Result<OrderType, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(
__deserializer: __D,
) -> Result<OrderType, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
impl Eq for OrderType
§impl Serialize for OrderType
impl Serialize for OrderType
§fn serialize<__S>(
&self,
__serializer: __S,
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>where
__S: Serializer,
fn serialize<__S>(
&self,
__serializer: __S,
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>where
__S: Serializer,
impl StructuralPartialEq for OrderType
Auto Trait Implementations§
impl Freeze for OrderType
impl RefUnwindSafe for OrderType
impl Send for OrderType
impl Sync for OrderType
impl Unpin for OrderType
impl UnsafeUnpin for OrderType
impl UnwindSafe for OrderType
Blanket Implementations§
§impl<U> As for U
impl<U> As for U
§fn as_<T>(self) -> Twhere
T: CastFrom<U>,
U: Sized,
fn as_<T>(self) -> Twhere
T: CastFrom<U>,
U: Sized,
self to type T. The semantics of numeric casting with the as operator are followed, so <T as As>::as_::<U> can be used in the same way as T as U for numeric conversions. Read more§impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
§impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
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<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§impl<T> Conv for T
impl<T> Conv for T
impl<T> DeserializeOwned for Twhere
T: for<'de> Deserialize<'de>,
§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
§impl<T> InitializableFromZeroed for Twhere
T: Default,
impl<T> InitializableFromZeroed for Twhere
T: Default,
§unsafe fn initialize(place: *mut T)
unsafe fn initialize(place: *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> ⓘ
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 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<T> MaybeSend for Twhere
T: Send,
§impl<T> Pipe for Twhere
T: ?Sized,
impl<T> Pipe for Twhere
T: ?Sized,
§fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> Rwhere
Self: Sized,
fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> Rwhere
Self: Sized,
§fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> Rwhere
R: 'a,
fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> Rwhere
R: 'a,
self and passes that borrow into the pipe function. Read more§fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> Rwhere
R: 'a,
fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> Rwhere
R: 'a,
self and passes that borrow into the pipe function. Read more§fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> R
fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> R
§fn pipe_borrow_mut<'a, B, R>(
&'a mut self,
func: impl FnOnce(&'a mut B) -> R,
) -> R
fn pipe_borrow_mut<'a, B, R>( &'a mut self, func: impl FnOnce(&'a mut B) -> R, ) -> R
§fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R
fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R
self, then passes self.as_ref() into the pipe function.§fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> R
fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> R
self, then passes self.as_mut() into the pipe
function.§fn pipe_deref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R
fn pipe_deref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R
self, then passes self.deref() into the pipe function.impl<T> Read<Exclusive, BecauseExclusive> for Twhere
T: ?Sized,
§impl<T> Tap for T
impl<T> Tap for T
§fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Self
fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Self
Borrow<B> of a value. Read more§fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Self
fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Self
BorrowMut<B> of a value. Read more§fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Self
fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Self
AsRef<R> view of a value. Read more§fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Self
fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Self
AsMut<R> view of a value. Read more§fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Self
fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Self
Deref::Target of a value. Read more§fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Self
fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Self
Deref::Target of a value. Read more§fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self
fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self
.tap() only in debug builds, and is erased in release builds.§fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self
fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self
.tap_mut() only in debug builds, and is erased in release
builds.§fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Self
fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Self
.tap_borrow() only in debug builds, and is erased in release
builds.§fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Self
fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Self
.tap_borrow_mut() only in debug builds, and is erased in release
builds.§fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Self
fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Self
.tap_ref() only in debug builds, and is erased in release
builds.§fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Self
fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Self
.tap_ref_mut() only in debug builds, and is erased in release
builds.§fn tap_deref_dbg<T>(self, func: impl FnOnce(&T)) -> Self
fn tap_deref_dbg<T>(self, func: impl FnOnce(&T)) -> Self
.tap_deref() only in debug builds, and is erased in release
builds.