Design a Price-Triggered Limit Order Domain
Model normal and price-triggered stock-order creation with clear request contracts, workflow selection, and retry-safe submission.
Design the low-level core of a broker's good-till-triggered (GTT) order feature. A user can say, for example, "If stock ABC falls to 2400 or below, submit a limit BUY for 10 shares at 2405." Trigger price and limit price have different meanings: meeting the trigger causes order submission; it does not promise a fill.
The service also accepts normal limit BUY orders that are submitted immediately. Discuss separate versus shared creation endpoints and request models, how an API request identifies its order kind, how the selected workflow runs, and which patterns fit.
Write common-controller pseudocode and explain how a Strategy-based version selects and invokes a workflow.
For this exercise, assume an authenticated account can create and inspect only its own orders. Each create includes an account-scoped request ID; an exact retry returns the same order, and changed content under that ID is a conflict.
Quantities are positive integers; prices are positive integer minor units in one fixed currency. Normal orders have no trigger; GTT orders have a trigger price and use only the price-at-or-below condition. A GTT starts watching after creation is durably accepted.
A monotonic per-symbol price sequence is captured at acceptance; only later sequence numbers are eligible. Duplicate or older feed messages must not produce extra submissions. Once a GTT triggers, it must create at most one logical downstream order even if matching prices arrive concurrently or a process restarts.
The broker adapter accepts a stable submission key, replays the same key without creating another order, and supports lookup by that key. Definitive acceptance returns a broker order ID; definitive rejection ends submission.
A timeout may hide acceptance, so keep an unresolved submission pending and recover it with lookup or a retry using the same key. No code for the exchange or price-feed transport is required. Model the objects, states, contracts, collaboration, and focused controller pseudocode.
Trade execution after broker acceptance, cancellation, expiry, SELL and market orders, portfolio balances, payments, and regulatory reporting are outside scope.