Files
StockSharp/MatchingEngine/MatchingEngineSettings.cs
mika@stocksharp.com 47fcbdf055 Match orders against the book, and leave inventing one to emulation
The engine's job is to reconcile real orders against a real book. It was also making
the book up, and what it made up was wrong in ways that cost money.

A quote states where the market is. Each one was written in as a level and the ones
before it kept, so a market walking one way left every price it had ever quoted
resting in the book while the touch stayed where the walk began: three falling quotes
and the book held a bid above its own ask. Past the trim depth the stale side froze
there for good while the other tracked away without bound.

A print says a trade happened. It was written in as a resting level, on a side guessed
when the feed did not say, at a volume of one when the print carried none; on an empty
book a single trade conjured both sides of a market with the far side a made-up spread
away; and a print at or through the touch was written opposite at the price of the
print, which crosses the book on purpose. Then it trimmed - and the trim could not tell
an invented level from one the venue had stated, sparing only levels holding a client's
own order, so every print cut the venue's real book to five levels a side. The matcher
subscribes to ticks, so that is what the live book has been doing.

An order asking for more than the whole opposite side got the book extended past its
worst level, a step apart, doubling volume each time, and traded through it: five lots
offered, fifty asked for, fifty filled. That is replay, and the emulation asks for it
by name; the engine had it on by default and the venue never turned it off.

A resting order the market moved through was filled for its whole balance with no
level consumed and no counterparty.

An instrument whose venue never states a price step has one guessed from the first
price quoted. The guess was written into the security definition the venue sent - kept
by reference, so in the venue it is the feeder's own object - and it was written
whether or not the venue had stated a step, because the gate was "have we guessed yet"
rather than "were we told".

All of it goes. What a quote still tells the engine is whether the instrument may be
traded; what a print still does is check the stops waiting on that price; extending a
book happens only when asked. Building a book out of quotes and prints was already the
emulation's own work, done correctly there - it moves the level instead of leaving the
old one behind - and filling a resting order without a counterparty joins it. The
knobs that bounded and spaced what the engine invented go with it, along with a trim
that had no caller.

What stays is matching: folding an incremental feed into the book the engine holds,
keeping client orders across a venue snapshot, stops, margin, and refusing an order
the book cannot price - which after this is the only thing separating "there is no
market" from "this order is free".

The two tests standing watch over the emulated book asked only that it stay under a
level count. It always did: a book pinned to the first price it ever saw is one level
deep. They ask now that the touch be the last thing quoted and that the sides have not
crossed.
2026-08-25 03:33:59 +03:00

42 lines
1.2 KiB
C#

namespace StockSharp.MatchingEngine;
/// <summary>
/// Settings for <see cref="MatchingEngineAdapter"/>.
/// </summary>
public class MatchingEngineSettings
{
/// <summary>
/// Check money balance before order registration.
/// </summary>
public bool CheckMoney { get; set; }
/// <summary>
/// Check trading state (session hours).
/// </summary>
public bool CheckTradingState { get; set; }
/// <summary>
/// The number, starting at which identifiers for orders will be generated.
/// </summary>
public long InitialOrderId { get; set; }
/// <summary>
/// The number, starting at which identifiers for trades will be generated.
/// </summary>
public long InitialTradeId { get; set; }
/// <summary>
/// Extend the book past its worst level when an order asks for more volume than the market
/// holds, so that the order can be filled in full.
/// </summary>
/// <remarks>
/// The levels this adds were never quoted by anyone: it is emulation, for replaying history
/// where an order has to go through whatever the record shows. A venue matching real orders
/// leaves it off, and an order larger than the market is filled by as much market as there is.
/// </remarks>
public bool IncreaseDepthVolume { get; set; }
}