Skip to main content

TimeInForce

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:

TypePartial FillsRests on BookRequires 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_only flag
  • All types: Must not be Unspecified in valid orders

Variants§

§

Gtt

Good Till Time - order expires at specified timestamp.

GTT orders remain active in the order book until either:

  1. They are completely filled through matching
  2. They reach their specified expiry timestamp
  3. They are manually canceled

§Requirements

  • Must specify expiry_timestamp in 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_only flag (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_only flag (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

pub fn is_persistant(&self) -> bool

Trait Implementations§

§

impl Clone for TimeInForce

§

fn clone(&self) -> TimeInForce

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 TimeInForce

§

impl Debug for TimeInForce

§

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

Formats the value using the given formatter. Read more
§

impl Default for TimeInForce

§

fn default() -> TimeInForce

Returns the “default value” for a type. Read more
§

impl<'de> Deserialize<'de> for TimeInForce

§

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

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

impl Display for TimeInForce

§

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

Formats the value using the given formatter. Read more
§

impl Eq for TimeInForce

§

impl PartialEq for TimeInForce

§

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

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

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

Inequality operator !=. Read more
§

impl Serialize for TimeInForce

§

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 TimeInForce

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,

§

impl<T> Clear for T
where T: InitializableFromZeroed + ?Sized,

§

fn clear(&mut self)

Completely overwrites this value.
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> InitializableFromZeroed for T
where T: Default,

§

unsafe fn initialize(place: *mut T)

Called to initialize a place to a valid value, after it is set to all-bits-zero. Read more
§

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
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. 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