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
impl Clone for OrderError
§fn clone(&self) -> OrderError
fn clone(&self) -> OrderError
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreimpl Copy for OrderError
§impl Debug for OrderError
impl Debug for OrderError
§impl<'de> Deserialize<'de> for OrderError
impl<'de> Deserialize<'de> for OrderError
§fn deserialize<__D>(
__deserializer: __D,
) -> Result<OrderError, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(
__deserializer: __D,
) -> Result<OrderError, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
impl Eq for OrderError
§impl PartialEq for OrderError
impl PartialEq for OrderError
§impl Serialize for OrderError
impl Serialize for OrderError
§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 OrderError
Auto Trait Implementations§
impl Freeze for OrderError
impl RefUnwindSafe for OrderError
impl Send for OrderError
impl Sync for OrderError
impl Unpin for OrderError
impl UnsafeUnpin for OrderError
impl UnwindSafe for OrderError
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> 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.