The manager already indexes its stops by security for CheckPrice, but the
interface offered no way to read that index, so every caller that needs to walk
the stops of one instrument had to keep a second index of its own over the very
same objects.
GetStopIds hands out the transaction ids resting on a security, copied out under
the same lock every other operation runs under and filtered to the stops that are
still registered, since CheckPrice prunes its per-security list lazily.
The order a stop turns into when it fires was built without a transaction id, so
everything raised for it went out with an original transaction of zero: fills nobody
could attribute, which downstream either broadcast to every session or delivered to
none, and a resting limit order filed as anonymous market volume, because the book
branches on that id to tell a client order from the venue's own flow.
The derived order now continues the stop's own transaction - the only id the caller
ever issued, and therefore the only one its executions can be attributed to. With the
resulting order reporting under that id, the separate Done row the trigger used to
raise for the stop is no longer needed: the registration that follows it is the same
order's lifecycle.
A registered stop carried no watermark, so its first price became one: a sell at 95 with an offset
of 5 seeing 98 moved its stop to 93. The same stop reloaded after a restart took the watermark its
level implies and refused that price. The watermark is taken at registration now, where every path
goes through; an offset-only stop has no level to imply one and still takes the first price.
The three formulas sit together instead of one being inlined in the manager: the level from the
watermark, the watermark back from the level, and the watermark a stop starts from - which the
server asks for too, when it writes a stop down. With them the reachability rule: a sell trailing by
100 percent or more has a stop of zero or below that no price reaches, and it is refused.
A trailing stop registered at a level the market has already passed now triggers at once, as a plain
stop registered the same way does.
The server drives a single StopOrderManager concurrently — Register/Cancel/Replace on the
order-command path and CheckPrice on the feeder tick pump. Its state lived in a plain Dictionary and
per-security List with no synchronization, so a register racing a check corrupted the index (lost
stops / index-out-of-range) and two concurrent checks double-triggered the same stop. Serialize
every operation under a reentrant lock (Replace holds it across the internal Cancel + Register so the
swap stays atomic against a concurrent check). Covered by a concurrent register/check stress test in
the server stop-order module suite.
Add IPercentStopOrderCondition with three flags (IsActivationPricePercent,
IsClosePositionPricePercent, IsTrailingOffsetPercent) and carry them
through StopOrderCondition / StopOrderInfo.
StopOrderManager:
- percent limit price: resolved at trigger time against the actual
activated stop price (Buy: stop*(1+pct/100), Sell: stop*(1-pct/100))
- percent trailing offset: stop price recomputed each tick from the
high/low watermark (Sell: high*(1-pct/100), Buy: low*(1+pct/100))
Percent activation is resolved by the caller (server side) because it
requires a market-price snapshot that the matcher does not track.
Add StopOrderCondition, IStopOrderManager and StopOrderManager with support
for stop-market, stop-limit and trailing stop orders. Integrate stop order
processing into MarketEmulator (register, cancel, trigger on L1/tick prices).
Add 14 unit tests for StopOrderManager.