A request to buy or sell on a market — input to the engine.
An Order is a request, not a result. PaperEx.Engine.apply_order/4
consumes an Order and produces a PaperEx.Execution and possibly a
PaperEx.Position. This module is the request struct plus shape
validation; the engine that acts on it lives in PaperEx.Engine.
Fields
:id— caller-assignable identifier (any term). Useful for cross-referencing the order from anExecutionor aPosition.nilis allowed; the engine round-trips whatever you set (and uses it to tag pending remainders).:market_id(required) — exchange-specific market identifier. The package keeps this opaque (any term); the exchange adapter translates it.:side(required) —:buyor:sell.:order_type(required) —:limitor:market.:size— number of units (shares). For:limitorders this is the offered quantity; for:marketorders the engine usually derives it from:amountafter fill.:amount— currency spend budget for a market BUY only: the "spend at most $N" cap the engine converts to shares as it walks the book. A market SELL should use:size(the number of shares to sell) — its:amountis not a dollar budget and the engine ignores it. For:limitorders:amountis informational.:price— limit price per unit. Required for:limit; ignored for:market.:strategy— optional binary tag for grouping orders by strategy / signal source.:metadata— free-form map for caller-provided context. The engine never inspects this; it only round-trips it onto downstreamExecutionandPositionrecords.:placed_at—DateTime.t()when the order was submitted to the engine. Defaults toDateTime.utc_now/0if omitted.
Required-field semantics
new/1 requires :market_id, :side, and :order_type. For
:limit orders it additionally requires :price and :size. For
:market orders it additionally requires either :size or
:amount. Validation is shape-only — economic policy
(price-range checks, size limits, etc.) is the engine's job and
lives in PaperEx.Engine.
Summary
Functions
Builds an Order from a map or keyword list.
Types
@type id() :: term() | nil
@type market_id() :: term()
@type order_type() :: :limit | :market
@type side() :: :buy | :sell
@type t() :: %PaperEx.Order{ amount: number() | nil, id: id(), market_id: market_id(), metadata: map(), order_type: order_type(), placed_at: DateTime.t(), price: number() | nil, side: side(), size: number() | nil, strategy: String.t() | nil }
Functions
Builds an Order from a map or keyword list.
Required keys: :market_id, :side, :order_type. For :limit
orders also :price and :size. For :market orders also at
least one of :size or :amount.
Raises ArgumentError on shape violations.