Class Order

java.lang.Object
eds.model.Order
All Implemented Interfaces:
ISimulationEntity

public class Order extends Object implements ISimulationEntity
Represents a trading order flowing through the simulation.

An order contains both immutable attributes defined at submission and mutable state that changes during execution.

  • Immutable attributes: side, type, price, original size, arrival time
  • Mutable state: remaining size, execution status, and conclusion time

Lifecycle:

NEW → PARTIAL → FILLED
          ↘
          CANCELLED
  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Class
    Description
    static enum 
    The side of the order.
    static enum 
    Current execution status of the order.
    static enum 
    The type of order.
  • Constructor Summary

    Constructors
    Constructor
    Description
    Order(Order.Side side, Order.Type type, double price, int size, double arrivalTime)
    Creates a new order instance.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    cancel(double currentTime)
    Cancels the order if it is still active.
    double
    Returns the simulation timestamp when the order arrived.
    double
    Returns the simulation timestamp when the order finished execution.
    Returns the unique identifier of this order.
    int
    Returns the original share quantity submitted with the order.
    double
    Returns the limit price of the order.
    int
    Returns the remaining shares yet to be executed.
    Returns the side of the order.
    Returns the current execution status of the order.
    Returns the order type.
    boolean
    Determines whether the order is still active in the market.
    boolean
    Determines whether the order has been fully executed.
    void
    reduceShareSize(int qty, double currentTime)
    Reduces the remaining share size after a trade execution.
    Returns a formatted string representation of the order.

    Methods inherited from class Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
  • Constructor Details

    • Order

      public Order(Order.Side side, Order.Type type, double price, int size, double arrivalTime)
      Creates a new order instance.
      Parameters:
      side - the order side (BUY or SELL)
      type - the order type (MARKET or LIMIT)
      price - the limit price; ignored for MARKET orders
      size - the number of shares in the order
      arrivalTime - the simulation timestamp when the order arrived
  • Method Details

    • getId

      public String getId()
      Returns the unique identifier of this order.
      Returns:
      the order ID
    • getSide

      public Order.Side getSide()
      Returns the side of the order.
      Returns:
      the order side
    • getType

      public Order.Type getType()
      Returns the order type.
      Returns:
      the order type
    • getPrice

      public double getPrice()
      Returns the limit price of the order.

      For Order.Type.MARKET orders this value is ignored by the matching engine.

      Returns:
      the order price
    • getOriginalShareSize

      public int getOriginalShareSize()
      Returns the original share quantity submitted with the order.
      Returns:
      the original order size
    • getRemainingShareSize

      public int getRemainingShareSize()
      Returns the remaining shares yet to be executed.
      Returns:
      the remaining share size
    • getStatus

      public Order.Status getStatus()
      Returns the current execution status of the order.
      Returns:
      the order status
    • getArrivalTime

      public double getArrivalTime()
      Returns the simulation timestamp when the order arrived.
      Returns:
      the arrival time
    • getConclusionTime

      public double getConclusionTime()
      Returns the simulation timestamp when the order finished execution.

      If the order has not yet completed, this value will be Double.NaN.

      Returns:
      the conclusion time
    • isActive

      public boolean isActive()
      Determines whether the order is still active in the market.
      Returns:
      true if the order status is Order.Status.NEW or Order.Status.PARTIAL, otherwise false
    • isFilled

      public boolean isFilled()
      Determines whether the order has been fully executed.
      Returns:
      true if the status is Order.Status.FILLED
    • reduceShareSize

      public void reduceShareSize(int qty, double currentTime)
      Reduces the remaining share size after a trade execution.

      If shares remain after the reduction, the order transitions to Order.Status.PARTIAL. If no shares remain, the order transitions to Order.Status.FILLED and the conclusion time is recorded.

      Parameters:
      qty - the number of shares executed
      currentTime - the simulation timestamp of the execution
      Throws:
      IllegalArgumentException - if the quantity is non-positive
      IllegalArgumentException - if the quantity exceeds remaining shares
      IllegalStateException - if the order is not active
    • cancel

      public void cancel(double currentTime)
      Cancels the order if it is still active.

      The order status becomes Order.Status.CANCELLED and the conclusion time is recorded.

      Parameters:
      currentTime - the simulation timestamp of the cancellation
    • toString

      public String toString()
      Returns a formatted string representation of the order.
      Overrides:
      toString in class Object
      Returns:
      a human-readable representation of the order state