## Sequence Diagram: GTT Order Expiry and Auction Mode Check
### Overview
This image is a technical sequence diagram illustrating the logic flow for checking the expiry of a Good-Til-Time (GTT) order and evaluating market mode changes within a trading system. The diagram tracks the system state across two discrete time ticks (`t=2699` to `t=2701`), focusing on the interaction between time progression, order expiry checks, and auction mode/uncrossing conditions. The final state highlights a rule violation where two critical events occur in the same tick.
### Components/Axes
The diagram is structured as a sequence diagram with four vertical lifelines (columns) from left to right:
1. **Time**: Represents the progression of system time in discrete ticks.
2. **GTT Expiry Check**: The component responsible for determining if a GTT order has expired.
3. **Mode/Uncross Check**: The component that evaluates whether the market should remain in auction mode or transition to an uncrossing state.
4. **State**: Represents the overall system state and outcomes.
**Initial State Box (Top Center):**
* `Initial: t = 2699, Auction Mode`
* `uncross_at= 2700, order expires_at= 2700`
* `market_extension= 1`
### Detailed Analysis
**Tick 1: `t = 2699 → 2700`**
1. **Check expiry** (Message from Time to GTT Expiry Check):
* **Condition 1:** `In auction mode?` -> Implied YES (from initial state).
* **Condition 2:** `Extend to max(2700, 2700+1) = 2701`. The expiry time is extended by the `market_extension` value of 1.
* **Condition 3:** `2700 ≥ 2701?` -> **NO**.
* **Outcome:** `Order NOT expired` (Dashed arrow to State).
2. **Check mode change** (Message from Time to Mode/Uncross Check):
* **Condition 1:** `2700 ≥ 2700?` -> **YES** (Current time `t=2700` meets the `uncross_at` time).
* **Condition 2:** `Market orders present? 2700 ≥ 2700 + 1?` -> **NO** (2700 is not ≥ 2701).
* **Outcome:** `Stay in auction` (Dashed arrow to State).
**State After Tick 1 (Center Box):**
* `After Tick 1: t = 2700, Still in auction`
**Tick 2: `t = 2700 → 2701`**
1. **Check expiry** (Message from Time to GTT Expiry Check):
* **Condition 1:** `In auction mode?` -> Implied YES.
* **Condition 2:** `Extend to max(2700, 2700+1) = 2701`.
* **Condition 3:** `2701 ≥ 2701?` -> **YES**.
* **Outcome:** `ORDER EXPIRES` (Bold, dashed arrow to State).
2. **Check mode change** (Message from Time to Mode/Uncross Check):
* **Condition 1:** `2701 ≥ 2700?` -> **YES**.
* **Condition 2:** `Market orders present? 2701 ≥ 2700 + 1?` -> **YES** (2701 ≥ 2701).
* **Outcome:** `UNCROSS` (Dashed arrow to State).
**Final State Box (Bottom Center, Pink Background):**
* `Both events occur in the same tick`
* `MIT201 violated`
### Key Observations
1. **Simultaneous Critical Events:** The core observation is that the `ORDER EXPIRES` event and the `UNCROSS` event are triggered in the same system tick (`t=2701`).
2. **Rule Violation:** The diagram explicitly labels this concurrency as a violation of rule `MIT201`.
3. **Conditional Logic:** The system uses a `market_extension` parameter (value=1) to dynamically adjust the effective expiry time during auction mode, delaying the expiry check by one tick.
4. **State Persistence:** The system remains in "Auction Mode" through Tick 1 despite meeting the initial `uncross_at` time, because the secondary condition (market orders present) was not met.
### Interpretation
This diagram serves as a formal specification or debugging trace for a trading system's order lifecycle management. It demonstrates a potential race condition or design flaw where two state-changing events—order expiration and market uncrossing—are allowed to be processed within the same atomic time step.
The violation of `MIT201` suggests this concurrency is prohibited by system rules, likely because it creates an ambiguous or inconsistent market state. For example, should an expired order participate in the uncrossing auction? The system logic as shown does not prevent this scenario.
The use of `market_extension` is a key mechanism. It appears designed to give orders in auction mode a one-tick grace period, ensuring they are not expired prematurely before the uncrossing logic can fully evaluate market conditions. However, in this specific trace, that extension leads directly to the prohibited condition where both events coincide at `t=2701`. This highlights a critical edge case in the system's temporal logic that would need to be addressed, perhaps by ensuring the expiry check and mode check are ordered or by adding a guard condition to prevent uncrossing if an order is set to expire in the same tick.