Enum Side
pub enum Side {
Buy,
Sell,
Unspecified,
}Expand description
Order direction specifying whether to buy or sell the base asset.
This enum defines the fundamental direction of an order, determining whether the trader wants to purchase (buy) or dispose of (sell) the base asset in a trading pair. Side is one of the most basic but critical order parameters.
§Market Pair Interpretation
In a trading pair like “BTCUSD”:
- Base Asset: BTC (the asset being traded)
- Quote Asset: USD (the asset used for pricing/payment)
§Buy Orders
- Action: Purchase base asset (BTC)
- Payment: Using quote asset (USD)
- Result: Increase BTC position, decrease USD balance
§Sell Orders
- Action: Dispose of base asset (BTC)
- Receipt: Receive quote asset (USD)
- Result: Decrease BTC position, increase USD balance
§Position Impact
| Current Position | Buy Order | Sell Order |
|---|---|---|
| Flat (0) | Long | Short |
| Long (+) | Larger | Smaller/Short |
| Short (-) | Smaller/Long | Larger |
§Usage Examples
§Basic buy and sell orders
use types::common::Side;
// Buy 1 BTC with USD
let buy_order = Side::Buy;
// Sell 1 BTC for USD
let sell_order = Side::Sell;
// Sides can be flipped for opposite orders
assert_eq!(buy_order.flip(), Side::Sell);
assert_eq!(sell_order.flip(), Side::Buy);§Order matching logic
use types::common::Side;
// Buy orders match against sell orders at same/better price
let incoming_buy = Side::Buy; // Matches existing sells
let incoming_sell = Side::Sell; // Matches existing buys
// Order book has two sides
// Bid side: Buy orders (buyers willing to purchase)
// Ask side: Sell orders (sellers willing to sell)§Risk and Position Management
§Reduce-Only Orders
- Long position + Sell order: Reduces position (allowed)
- Long position + Buy order: Increases position (blocked if reduce-only)
- Short position + Buy order: Reduces position (allowed)
- Short position + Sell order: Increases position (blocked if reduce-only)
§Stop-Loss Applications
- Long position stop-loss: Sell order triggered on price drop
- Short position stop-loss: Buy order triggered on price rise
§Trading Strategy Context
§Directional Strategies
- Bullish: More buy orders, building long positions
- Bearish: More sell orders, building short positions
- Neutral: Balanced buy/sell for market making or arbitrage
§Market Making
- Bid orders: Buy orders below current market price
- Ask orders: Sell orders above current market price
- Spread capture: Profit from bid-ask spread
§JSON Representation
"Buy" // Purchase base asset
"Sell" // Dispose of base asset§Validation
- Must not be
Unspecifiedin valid orders - Should align with intended strategy and position management
- Consider current position when using reduce-only flag
Variants§
Buy
Buy order - purchase the base asset using the quote asset.
Buy orders express demand for the base asset and willingness to pay the quote asset. They increase long positions or reduce short positions when executed.
§Market Mechanics
- Order book side: Bid side (buyers)
- Liquidity role: Can be maker (bid below market) or taker (bid at/above market)
- Matching: Executes against existing sell orders
- Price improvement: Executes at ask price or better (lower)
§Position Effects
- From flat: Creates long position
- From long: Increases position size (adds to long)
- From short: Reduces position size (covers short)
§Execution Examples
§Limit Buy Order
- Order: Buy 1 BTC at $50,000 (limit)
- Execution: If market trades at $50,000 or lower
- Result: Acquire 1 BTC, pay ≤ $50,000
§Market Buy Order
- Order: Buy 1 BTC at market price
- Execution: Immediately at best available ask price
- Result: Acquire 1 BTC, pay current ask price
§Risk Considerations
- Price risk: May pay higher than expected (market orders)
- Liquidity risk: Large orders may impact price unfavorably
- Margin requirements: May require additional collateral
§Common Use Cases
- Opening long positions
- Covering short positions
- Dollar-cost averaging (regular buy orders)
- Breakout trading (buy on resistance breaks)
- Stop-loss for short positions
Sell
Sell order - dispose of the base asset to receive the quote asset.
Sell orders express supply of the base asset and willingness to accept the quote asset. They increase short positions or reduce long positions when executed.
§Market Mechanics
- Order book side: Ask side (sellers)
- Liquidity role: Can be maker (ask above market) or taker (ask at/below market)
- Matching: Executes against existing buy orders
- Price improvement: Executes at bid price or better (higher)
§Position Effects
- From flat: Creates short position
- From long: Reduces position size (sells long)
- From short: Increases position size (adds to short)
§Execution Examples
§Limit Sell Order
- Order: Sell 1 ETH at $3,500 (limit)
- Execution: If market trades at $3,500 or higher
- Result: Dispose 1 ETH, receive ≥ $3,500
§Market Sell Order
- Order: Sell 1 ETH at market price
- Execution: Immediately at best available bid price
- Result: Dispose 1 ETH, receive current bid price
§Risk Considerations
- Price risk: May receive less than expected (market orders)
- Liquidity risk: Large orders may depress prices
- Short selling risks: Unlimited loss potential for naked shorts
§Common Use Cases
- Closing long positions (profit taking or loss cutting)
- Opening short positions (bearish speculation)
- Stop-loss for long positions
- Rebalancing portfolios
- Arbitrage opportunities
Unspecified
Unspecified order side - invalid for actual orders.
This is what serde substitutes when a submitted request omits side;
validation then rejects the order. It is not Side::default() —
#[default] sits on Buy, so building a request with
Side::default() silently submits a buy — and it is not what
SubmitOrderRequestBuilder starts from either: the builder holds
Option<Side> and build() reports a missing field.
§Behavior
- Always causes order validation to fail
- Never valid for order submission
- Should be replaced with Buy or Sell before submission
- Will cause
flip()method to panic if used
Implementations§
Trait Implementations§
impl Copy for Side
§impl<'de> Deserialize<'de> for Side
impl<'de> Deserialize<'de> for Side
§fn deserialize<__D>(
__deserializer: __D,
) -> Result<Side, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(
__deserializer: __D,
) -> Result<Side, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
impl Eq for Side
§impl Serialize for Side
impl Serialize for Side
§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 Side
Auto Trait Implementations§
impl Freeze for Side
impl RefUnwindSafe for Side
impl Send for Side
impl Sync for Side
impl Unpin for Side
impl UnsafeUnpin for Side
impl UnwindSafe for Side
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.