Module Trading_engine.Order

Immutable orders and their legal state transitions.

type side =
  1. | Buy
  2. | Sell
type kind =
  1. | Market
  2. | Limit of Scalar.Price.t
  3. | Stop of Scalar.Price.t
  4. | Stop_limit of {
    1. trigger_price : Scalar.Price.t;
    2. limit_price : Scalar.Price.t;
    }
type time_in_force =
  1. | Gtc
  2. | Ioc
  3. | Fok
  4. | Day of {
    1. venue_id : Id.Venue.t;
    2. calendar_id : Id.Venue_calendar.t;
    }
  5. | Gtd of Ptime.t
type origin =
  1. | Direct
  2. | Target_rebalance
  3. | Margin_liquidation
  4. | Borrow_recall
type request = private {
  1. instrument_id : Id.Instrument.t;
  2. side : side;
  3. quantity : Scalar.Quantity.t;
  4. kind : kind;
  5. time_in_force : time_in_force;
  6. origin : origin;
}
type trigger_state =
  1. | Dormant
  2. | Triggered of {
    1. triggered_at : Ptime.t;
    2. triggered_slice_sequence : int64;
    }
type status =
  1. | Working
  2. | Partially_filled
  3. | Filled
  4. | Cancelled
  5. | Rejected of string
type t = private {
  1. id : Id.Order.t;
  2. request : request;
  3. created_event_id : Id.Event.t;
  4. updated_event_id : Id.Event.t;
  5. created_sequence : int64;
  6. created_at : Ptime.t;
  7. eligible_after_slice_sequence : int64;
  8. filled_quantity : Scalar.Quantity.t;
  9. filled_notional : Scalar.Money.t;
  10. trigger_state : trigger_state option;
  11. status : status;
}
val compatibility_time_in_force : kind -> time_in_force

Preserve the pre-v8 mapping: market orders are IOC and all other kinds are GTC.

val request : instrument_id:Id.Instrument.t -> side:side -> quantity:Scalar.Quantity.t -> kind:kind -> origin:origin -> (request, string) Stdlib.result
val request_v8 : instrument_id:Id.Instrument.t -> side:side -> quantity:Scalar.Quantity.t -> kind:kind -> time_in_force:time_in_force -> origin:origin -> (request, string) Stdlib.result
val accept : id:Id.Order.t -> created_event_id:Id.Event.t -> accepted_sequence:int64 -> created_at:Ptime.t -> eligible_after_slice_sequence:int64 -> request -> (t, string) Stdlib.result
val reject : id:Id.Order.t -> created_event_id:Id.Event.t -> rejected_sequence:int64 -> created_at:Ptime.t -> eligible_after_slice_sequence:int64 -> request -> reason:string -> (t, string) Stdlib.result
val remaining_quantity : t -> Scalar.Quantity.t
val is_active : t -> bool
val is_terminal : t -> bool
val is_market : t -> bool
val is_ioc : t -> bool
val is_fok : t -> bool
val is_dormant_stop : t -> bool
val effective_kind : t -> kind option
val trigger : t -> updated_event_id:Id.Event.t -> triggered_at:Ptime.t -> triggered_slice_sequence:int64 -> (t, string) Stdlib.result
val apply_fill : t -> quantity:Scalar.Quantity.t -> notional:Scalar.Money.t -> (t, string) Stdlib.result
val cancel : t -> (t, string) Stdlib.result
val adjust_for_split : t -> updated_event_id:Id.Event.t -> numerator:int64 -> denominator:int64 -> (t, string) Stdlib.result
val side_to_string : side -> string
val kind_to_string : kind -> string
val time_in_force_to_string : time_in_force -> string
val origin_to_string : origin -> string
val status_to_string : status -> string
val pp : Stdlib.Format.formatter -> t -> unit