Skip to main content

OrderError

Enum OrderError 

pub enum OrderError {
Show 23 variants ClientOrderIdAlreadyInUse, ExpiryTimestampInThePast, PostOnlyOrderWouldTrade, FokOrderCannotBeFullyFilled, InvalidReduceOnly, InsufficientMargin, OrderSelfTrading, ConditionalInvalidPercentageQuantity, ConditionalNoLastTradedPriceYet, ConditionalNoMarkPriceYet, ConditionalNoIndexPriceYet, TradingModeViolationSuspended, TradingModeViolationSettled, TradingModeViolationPostOnly, TradingModeViolationReduceOnly, TradingModeViolationPlatformRestricted, TradingModeViolationPlatformOffline, AccountTradingDisabled, PriceBoundStopped, OpenInterestLimitStopped, ConditionalLinkedOrderNotFound, ConditionalLinkedOrderNeverTraded, WouldBankruptIsolatedPosition,
}
Expand description

Specific error conditions that can cause order rejection during processing.

This enum provides detailed error codes for various order validation and execution failures. Each variant represents a specific condition that prevents an order from being accepted or executed by the matching engine.

§Error Categories

§Validation Errors

  • ClientOrderIdAlreadyInUse: Duplicate client order ID
  • ExpiryTimestampInThePast: Invalid expiry time

§Execution Errors

  • PostOnlyOrderWouldTrade: Post-only order would execute immediately
  • FokOrderCannotBeFullyFilled: Fill-or-Kill order cannot be completed
  • InvalidReduceOnly: Reduce-only order would increase position

§Account Errors

  • InsufficientMargin: Insufficient balance or margin for order

§Usage

These errors are typically returned during order submission or processing to indicate why an order was rejected. Each error provides specific context about the failure reason, enabling appropriate client-side handling.

§Examples

use types::common::OrderError;

// Handle different error types
fn handle_order_error(error: OrderError) {
    match error {
        OrderError::ClientOrderIdAlreadyInUse => {
            println!("Client order ID is not unique");
        }
        OrderError::InsufficientMargin => {
            println!("Not enough balance to place order");
        }
        OrderError::PostOnlyOrderWouldTrade => {
            println!("Post-only order would execute immediately");
        }
        _ => println!("Other order error: {:?}", error),
    }
}

§JSON Representation

Serialized as the variant name, for every variant — the enum body below is the complete list, and it is considerably longer than the six sampled here:

"ClientOrderIdAlreadyInUse"
"ExpiryTimestampInThePast"
"PostOnlyOrderWouldTrade"
"FokOrderCannotBeFullyFilled"
"InvalidReduceOnly"
"InsufficientMargin"

Variants§

§

ClientOrderIdAlreadyInUse

The provided client order ID is already in use by another active order.

Client order IDs must be unique per account. This error occurs when attempting to submit an order with a client_order_id that is already associated with an existing active order for the same account.

§Resolution

  • Use a different, unique client order ID
  • Cancel or wait for completion of the existing order with the same ID
  • Implement proper client-side ID generation to ensure uniqueness

§Common Causes

  • Duplicate order submissions
  • Client-side ID generation conflicts
  • Retry logic using the same ID without checking order status
§

ExpiryTimestampInThePast

The order’s expiry timestamp is in the past relative to current time.

GTT (Good Till Time) orders require a future expiry timestamp. This error occurs when the provided expiry_timestamp is less than or equal to the current system time.

§Resolution

  • Provide a future timestamp for GTT orders
  • Check system clock synchronization
  • Account for network latency in timestamp calculations

§Common Causes

  • Clock skew between client and server
  • Using seconds instead of milliseconds for timestamp
  • Delayed order submission after timestamp calculation
§

PostOnlyOrderWouldTrade

A post-only order would execute immediately against existing orders.

Post-only orders are designed to only add liquidity (maker orders) and must not execute immediately. This error occurs when a post-only order’s price would match against existing orders on the book.

§Resolution

  • Adjust the order price to ensure it goes on the book
  • Remove the post-only flag if immediate execution is acceptable
  • Check current market prices before submitting post-only orders

§Common Causes

  • Aggressive pricing on post-only orders
  • Market movement between price calculation and order submission
  • Misunderstanding of post-only behavior
§

FokOrderCannotBeFullyFilled

A Fill-or-Kill order cannot be completely filled at submission.

FOK orders require complete immediate execution or rejection. This error occurs when there is insufficient liquidity to fill the entire order quantity at the specified price or better.

§Resolution

  • Reduce the order quantity to match available liquidity
  • Use IOC (Immediate or Cancel) instead to allow partial fills
  • Check market depth before placing large FOK orders
  • Adjust price to access more liquidity

§Common Causes

  • Large order size relative to available liquidity
  • Restrictive price limits on limit orders
  • Low liquidity market conditions
§

InvalidReduceOnly

A reduce-only order would increase the position size instead of reducing it.

Reduce-only orders are restricted to only decrease the absolute position size. This error occurs when executing the order would increase the position or open a position in the opposite direction.

§Resolution

  • Remove the reduce-only flag if position increase is intended
  • Verify current position size and direction
  • Adjust order quantity to stay within position reduction limits
  • Use appropriate order side (buy to reduce short, sell to reduce long)

§Common Causes

  • Incorrect order side for current position
  • Order quantity exceeds current position size
  • Position changes between order calculation and submission
§

InsufficientMargin

Insufficient balance or margin to place the order.

The account lacks sufficient funds to cover the order’s margin requirements or the full purchase amount. This includes both initial margin for new positions and additional margin for position increases.

§Resolution

  • Deposit additional funds to the account
  • Reduce the order quantity to fit available balance
  • Close other positions to free up margin
  • Use reduce-only orders that don’t require additional margin

§Common Causes

  • Insufficient account balance
  • Excessive leverage or position size
  • Unrealized losses reducing available margin
  • Multiple orders consuming available margin simultaneously
§

OrderSelfTrading

Order would trade against another order from the same account.

This error prevents self-trading, where an account’s buy order would match against the same account’s sell order. Self-trading is typically prohibited to prevent wash trading and market manipulation.

§Resolution

  • Adjust order price to avoid crossing own orders
  • Cancel existing orders on the opposite side
  • Use different accounts for opposing positions
  • Wait for other market participants to provide liquidity

§Common Causes

  • Placing limit orders on both sides of the book
  • Algorithmic trading errors
  • Quick order reversals without cancelling previous orders
  • Market making with insufficient price separation

§Prevention

Many trading systems provide self-trade prevention (STP) modes that automatically handle this situation by cancelling one or both orders rather than rejecting the new order.

§

ConditionalInvalidPercentageQuantity

Conditional order with percentage quantity has invalid position.

This error occurs when a conditional order uses a percentage-based quantity calculation (PercentageOfPositionAtSubmission or PercentageOfPositionAtTrigger) but the account has no position (position = 0) or the calculated quantity rounds to zero.

§Resolution

  • Ensure the account has an open position before using percentage quantities
  • Use absolute quantity instead of percentage for conditional orders
  • Increase the percentage value to avoid rounding to zero
  • Open a position first, then submit the conditional order

§Common Causes

  • Submitting percentage-based conditional without existing position
  • Position closed between submission and trigger
  • Very small percentage values that round to zero
  • Position size too small for meaningful percentage calculations

§Timing

This error can occur at two points:

  • At submission: For PercentageOfPositionAtSubmission when position is 0
  • At trigger: For either percentage type when calculated quantity is 0
§

ConditionalNoLastTradedPriceYet

conditional order cannot trigger yet because no last traded price is available.

this error occurs when a conditional order uses the last trade price as its reference price (ReferencePrice::LastTrade), but no trades have executed yet in this market. this typically happens during market initialization or for newly listed pairs before the first trade occurs.

§Resolution

  • wait for the first trade to execute in the market
  • consider using a different reference price (Index or Mark)
  • retry the conditional order submission after trading activity begins
  • check if the market is properly initialized and has trading activity

§Common Causes

  • market just opened with no trades yet
  • newly listed trading pair before first trade
  • system restart before any trades occur
  • attempting to place orders on inactive markets

§Timing

this error occurs at conditional order submission time when the system checks if the reference price is available for monitoring.

§

ConditionalNoMarkPriceYet

§

ConditionalNoIndexPriceYet

§

TradingModeViolationSuspended

order rejected: the market is Suspended and only cancellations are accepted.

§

TradingModeViolationSettled

order rejected: the market is Settled (terminal state) and no further trading is allowed.

§

TradingModeViolationPostOnly

order rejected: the market is PostOnly and the order is not a post-only order.

§

TradingModeViolationReduceOnly

order rejected: the market is ReduceOnly and the order is neither reduce-only nor a market maker’s post-only order.

§

TradingModeViolationPlatformRestricted

order rejected: the platform is in Restricted mode and the account is not a registered market maker.

§

TradingModeViolationPlatformOffline

order rejected: the platform is Offline — no orders are accepted.

§

AccountTradingDisabled

order rejected because the account’s can_trade flag is disabled.

the account has been flagged to disallow trading. this is set on-chain and prevents any new order submissions for this account.

§

PriceBoundStopped

order partially or fully stopped because matching would trade outside the price bound.

the trading bound is a configurable % distance from the mark price. aggressive orders are stopped before trading outside this range.

§

OpenInterestLimitStopped

order partially or fully stopped because matching would breach the market’s open interest limit. the market enters reduce-only mode when this occurs.

§

ConditionalLinkedOrderNotFound

linked conditional rejected: the referenced parent order could not be found.

the conditional declared an order-linked activation (by client order id or order id) but no matching live order exists for the account and the parent was not produced by an earlier command in the same transaction. the client should resubmit the conditional without the link if the parent already filled.

§

ConditionalLinkedOrderNeverTraded

linked conditional cancelled/rejected: the parent order terminated without trading.

the linked parent reached a terminal state (rejected, cancelled, expired, liquidated) with zero filled quantity, so the dormant conditional is removed — there is no position for it to protect.

§

WouldBankruptIsolatedPosition

the order’s fills would leave an isolated position underwater: its order-net equity — the collateral it keeps once its resting orders are cancelled, plus unrealised pnl — negative, or, for fills that close it out entirely, the pool it hands back to the cross balance negative.

a fill on an isolated position moves collateral between the cross balance and the position’s pool by the whole entry-margin change while the realised pnl stays with the pool, so a partial close can leave a remainder carrying the loss of the whole position, and a full close at a bad enough price leaves nothing to hand back but debt. the account is not short of margin — the refund is its own money — but the position left behind cannot stand on its own and would be liquidated at a price far from mark, or its debt would land on the cross balance with no bankruptcy proceedings.

§Resolution

  • close less, leaving a remainder large enough to carry the loss, or close at a better price
  • a position already underwater exits through liquidation, not through its own orders

Trait Implementations§

§

impl Clone for OrderError

§

fn clone(&self) -> OrderError

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

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

Performs copy-assignment from source. Read more
§

impl Copy for OrderError

§

impl Debug for OrderError

§

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

Formats the value using the given formatter. Read more
§

impl<'de> Deserialize<'de> for OrderError

§

fn deserialize<__D>( __deserializer: __D, ) -> Result<OrderError, <__D as Deserializer<'de>>::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
§

impl Eq for OrderError

§

impl PartialEq for OrderError

§

fn eq(&self, other: &OrderError) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
§

impl Serialize for OrderError

§

fn serialize<__S>( &self, __serializer: __S, ) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
§

impl StructuralPartialEq for OrderError

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
§

impl<U> As for U

§

fn as_<T>(self) -> T
where T: CastFrom<U>, U: Sized,

Casts 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<T> AsOut<T> for T
where T: Copy,

§

fn as_out(&mut self) -> Out<'_, T>

Returns an out reference to self.
§

impl<'a, T, E> AsTaggedExplicit<'a, E> for T
where T: 'a,

§

fn explicit(self, class: Class, tag: u32) -> TaggedParser<'a, Explicit, Self, E>

§

impl<'a, T, E> AsTaggedImplicit<'a, E> for T
where T: 'a,

§

fn implicit( self, class: Class, constructed: bool, tag: u32, ) -> TaggedParser<'a, Implicit, Self, E>

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
§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

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
§

impl<T> Conv for T

§

fn conv<T>(self) -> T
where Self: Into<T>,

Converts self into T using Into<T>. Read more
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

Source§

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

Source§

fn __clone_box(&self, _: Private) -> *mut ()

§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

§

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

§

fn from_ref(input: &T) -> T

Converts to this type from a reference to the input type.
§

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<T> IntoRequest<T> for T

§

fn into_request(self) -> Request<T>

Wrap the input message T in a 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> MaybeSend for T
where T: Send,

§

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

§

fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> R
where Self: Sized,

Pipes by value. This is generally the method you want to use. Read more
§

fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> R
where R: 'a,

Borrows 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) -> R
where R: 'a,

Mutably borrows 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
where Self: Borrow<B>, B: 'a + ?Sized, R: 'a,

Borrows self, then passes self.borrow() into the pipe function. Read more
§

fn pipe_borrow_mut<'a, B, R>( &'a mut self, func: impl FnOnce(&'a mut B) -> R, ) -> R
where Self: BorrowMut<B>, B: 'a + ?Sized, R: 'a,

Mutably borrows self, then passes self.borrow_mut() into the pipe function. Read more
§

fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R
where Self: AsRef<U>, U: 'a + ?Sized, R: 'a,

Borrows 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
where Self: AsMut<U>, U: 'a + ?Sized, R: 'a,

Mutably borrows 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
where Self: Deref<Target = T>, T: 'a + ?Sized, R: 'a,

Borrows self, then passes self.deref() into the pipe function.
§

fn pipe_deref_mut<'a, T, R>( &'a mut self, func: impl FnOnce(&'a mut T) -> R, ) -> R
where Self: DerefMut<Target = T> + Deref, T: 'a + ?Sized, R: 'a,

Mutably borrows self, then passes self.deref_mut() into the pipe function.
§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
§

impl<T> Tap for T

§

fn tap(self, func: impl FnOnce(&Self)) -> Self

Immutable access to a value. Read more
§

fn tap_mut(self, func: impl FnOnce(&mut Self)) -> Self

Mutable access to a value. Read more
§

fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Self
where Self: Borrow<B>, B: ?Sized,

Immutable access to the Borrow<B> of a value. Read more
§

fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Self
where Self: BorrowMut<B>, B: ?Sized,

Mutable access to the BorrowMut<B> of a value. Read more
§

fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Self
where Self: AsRef<R>, R: ?Sized,

Immutable access to the AsRef<R> view of a value. Read more
§

fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Self
where Self: AsMut<R>, R: ?Sized,

Mutable access to the AsMut<R> view of a value. Read more
§

fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Self
where Self: Deref<Target = T>, T: ?Sized,

Immutable access to the Deref::Target of a value. Read more
§

fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Self
where Self: DerefMut<Target = T> + Deref, T: ?Sized,

Mutable access to the Deref::Target of a value. Read more
§

fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self

Calls .tap() only in debug builds, and is erased in release builds.
§

fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self

Calls .tap_mut() only in debug builds, and is erased in release builds.
§

fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Self
where Self: Borrow<B>, B: ?Sized,

Calls .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
where Self: BorrowMut<B>, B: ?Sized,

Calls .tap_borrow_mut() only in debug builds, and is erased in release builds.
§

fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Self
where Self: AsRef<R>, R: ?Sized,

Calls .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
where Self: AsMut<R>, R: ?Sized,

Calls .tap_ref_mut() only in debug builds, and is erased in release builds.
§

fn tap_deref_dbg<T>(self, func: impl FnOnce(&T)) -> Self
where Self: Deref<Target = T>, T: ?Sized,

Calls .tap_deref() only in debug builds, and is erased in release builds.
§

fn tap_deref_mut_dbg<T>(self, func: impl FnOnce(&mut T)) -> Self
where Self: DerefMut<Target = T> + Deref, T: ?Sized,

Calls .tap_deref_mut() only in debug builds, and is erased in release builds.
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
§

impl<T> TryConv for T

§

fn try_conv<T>(self) -> Result<T, Self::Error>
where Self: TryInto<T>,

Attempts to convert self into T using TryInto<T>. 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