Enum TimeInForce
pub enum TimeInForce {
Gtt,
Gtc,
Ioc,
Fok,
Unspecified,
}Expand description
Time-in-force instructions that control order lifecycle and execution behavior.
This enum defines how long an order should remain active and under what conditions it should be automatically canceled. Time-in-force rules are fundamental to order management and directly impact execution behavior.
§Order Lifetime Categories
§Persistent Orders (remain on book)
- GTC: Good Till Cancel - persists until filled or manually canceled
- GTT: Good Till Time - persists until specific expiry timestamp
§Immediate Orders (execute now or cancel)
- IOC: Immediate or Cancel - execute available quantity immediately, cancel remainder
- FOK: Fill or Kill - execute complete quantity immediately or cancel entirely
§Execution Behavior
Each time-in-force type has distinct matching behavior:
| Type | Partial Fills | Rests on Book | Requires Complete Fill |
|---|---|---|---|
| GTC | ✓ | ✓ | ✗ |
| GTT | ✓ | ✓ | ✗ |
| IOC | ✓ | ✗ | ✗ |
| FOK | ✗ | ✗ | ✓ |
§Usage Examples
§Long-term position building (GTC)
use types::common::TimeInForce;
let gtc = TimeInForce::Gtc;
println!("Order persists: {}", gtc.is_persistant()); // true§Time-limited orders (GTT)
use types::common::TimeInForce;
// GTT orders require expiry_timestamp in SubmitOrderRequest
let gtt = TimeInForce::Gtt;
assert!(gtt.is_persistant()); // Also persistent until expiry§Immediate execution strategies (IOC/FOK)
use types::common::TimeInForce;
let ioc = TimeInForce::Ioc; // Partial fills OK
let fok = TimeInForce::Fok; // All or nothing
assert!(!ioc.is_persistant()); // Never rests on book
assert!(!fok.is_persistant()); // Never rests on book§Compatibility with Other Order Features
§Post-Only Orders
- Compatible: GTC, GTT (can rest on book)
- Incompatible: IOC, FOK (require immediate execution)
§Market Orders
- Compatible: IOC, FOK (immediate execution)
- Rejected: GTC, GTT — a market order may not be persistent, and the pair is refused before it reaches the engine
§JSON Representation
Serialized as uppercase abbreviations:
"GTC" // Good Till Cancel
"GTT" // Good Till Time
"IOC" // Immediate or Cancel
"FOK" // Fill or Kill§Validation Requirements
- GTT orders: Must include valid future
expiry_timestamp - IOC/FOK orders: Cannot use
post_onlyflag - All types: Must not be
Unspecifiedin valid orders
Variants§
Gtt
Good Till Time - order expires at specified timestamp.
GTT orders remain active in the order book until either:
- They are completely filled through matching
- They reach their specified expiry timestamp
- They are manually canceled
§Requirements
- Must specify
expiry_timestampin the order request - Expiry timestamp must be in the future
- Timestamp should account for network latency
§Behavior
- Partial fills: Allowed and common
- Rests on book: Yes, until expiry or completion
- Automatic cleanup: Yes, at expiry timestamp
§Use Cases
- Orders with specific time constraints
- End-of-session or end-of-day orders
- Campaign-based trading with deadlines
- Risk management with automatic expiry
§Example Scenarios
- “Buy 1 BTC at $45,000 if not filled by market close”
- “Sell limit order valid only for next 30 minutes”
- “Stop-loss order expires if not triggered within 24 hours”
Gtc
Good Till Cancel - order persists until manually canceled or filled.
GTC orders are the most common type, remaining active indefinitely until explicit action is taken. They provide maximum flexibility for long-term trading strategies.
§Behavior
- Partial fills: Allowed and tracked
- Rests on book: Yes, indefinitely
- Manual management: Requires explicit cancellation
§Use Cases
- Long-term position building
- Limit orders at target prices
- Standing offers in low-liquidity markets
- Set-and-forget trading strategies
§Management Considerations
- Orders remain active across sessions
- May consume margin/balance indefinitely
- Require active monitoring and management
- Can be affected by corporate actions or market events
§Example Scenarios
- “Buy 10 ETH at $2,000 when price drops”
- “Sell limit at $60,000 for profit taking”
- “Standing bid for accumulating position over time”
Ioc
Immediate or Cancel - execute available quantity immediately, cancel remainder.
IOC orders attempt immediate execution against available liquidity. Any portion that cannot be immediately matched is automatically canceled rather than resting on the order book.
§Behavior
- Immediate execution: Must execute immediately or be canceled
- Partial fills: Allowed for available liquidity
- No book resting: Unfilled portions are canceled
- Quick cleanup: Automatically resolves to final state
§Use Cases
- Market impact testing (“how much can I buy now?”)
- Liquidity sweeping strategies
- Avoiding stale order risks
- High-frequency trading patterns
- Portfolio rebalancing with immediate execution
§Execution Examples
- Order: “Buy 5 BTC IOC at $50,000”
- Available: 3 BTC at $50,000 or better
- Result: Buy 3 BTC, cancel remaining 2 BTC
§Compatibility
- Cannot use with
post_onlyflag (conflicts with immediate execution) - Works well with market orders for guaranteed execution attempt
- Suitable for limit orders when partial execution is acceptable
Fok
Fill or Kill - execute complete quantity immediately or cancel entirely.
FOK orders require complete immediate execution of the entire order quantity. If the full amount cannot be matched immediately, the entire order is canceled with no partial execution.
§Behavior
- All-or-nothing: Complete fill required or total cancellation
- Immediate execution: Must execute immediately or be canceled
- No partial fills: Either 100% filled or 0% filled
- Atomic operation: Single execution event
§Use Cases
- Large block trading where partial fills are problematic
- Arbitrage strategies requiring complete position
- Risk management requiring full hedge execution
- Algorithms that need atomic position changes
§Execution Examples
- Order: “Sell 10 ETH FOK at $3,000”
- Scenario A - Available: 12 ETH at $3,000+ → Execute 10 ETH
- Scenario B - Available: 7 ETH at $3,000+ → Cancel entire order
§Risk Considerations
- Higher rejection rate than IOC orders
- Requires sufficient liquidity for full execution
- May need price adjustment if frequently rejected
- Market impact assessment should consider full quantity
§Compatibility
- Cannot use with
post_onlyflag (conflicts with immediate execution) - Particularly useful with market orders for guaranteed attempt
- Requires careful price setting for limit orders
Unspecified
Unspecified time-in-force - invalid for actual orders.
This is what serde substitutes when a submitted request omits tif;
validation then rejects the order. It is not TimeInForce::default()
— #[default] sits on Gtc — and it is not what
SubmitOrderRequestBuilder starts from either: the builder holds
Option<TimeInForce> and build() reports a missing field.
§Behavior
- Always causes order validation to fail
- Never valid for order submission
- Should be replaced with appropriate TIF before submission
Implementations§
§impl TimeInForce
impl TimeInForce
pub fn is_persistant(&self) -> bool
Trait Implementations§
§impl Clone for TimeInForce
impl Clone for TimeInForce
§fn clone(&self) -> TimeInForce
fn clone(&self) -> TimeInForce
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 TimeInForce
§impl Debug for TimeInForce
impl Debug for TimeInForce
§impl Default for TimeInForce
impl Default for TimeInForce
§fn default() -> TimeInForce
fn default() -> TimeInForce
§impl<'de> Deserialize<'de> for TimeInForce
impl<'de> Deserialize<'de> for TimeInForce
§fn deserialize<__D>(
__deserializer: __D,
) -> Result<TimeInForce, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(
__deserializer: __D,
) -> Result<TimeInForce, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
§impl Display for TimeInForce
impl Display for TimeInForce
impl Eq for TimeInForce
§impl PartialEq for TimeInForce
impl PartialEq for TimeInForce
§impl Serialize for TimeInForce
impl Serialize for TimeInForce
§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 TimeInForce
Auto Trait Implementations§
impl Freeze for TimeInForce
impl RefUnwindSafe for TimeInForce
impl Send for TimeInForce
impl Sync for TimeInForce
impl Unpin for TimeInForce
impl UnsafeUnpin for TimeInForce
impl UnwindSafe for TimeInForce
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.