mirror of
https://github.com/StockSharp/StockSharp.git
synced 2026-12-04 16:41:19 +00:00
The decomposed matching engine synthesizes an order book from ticks/Level1 when there is no real order-book history (MatchingEngineAdapter.ProcessTick/ProcessLevel1 -> OrderBook.UpdateLevel). It added a new level per distinct price and never removed stale ones, so replaying a long varied price stream - as a tick backtest does - grew the book without bound (hundreds of thousands of OrderBookLevelImpl plus the downstream ExecutionMessages they drive), accumulating into multi-GB heap growth that eventually exhausted memory and crashed the test host near the end of the full suite. Restore the MaxDepth cap the monolith MarketEmulatorOld already applied: OrderBook.TrimSynthesizedDepth drops the farthest synthetic levels beyond MaxDepth after each synthesized UpdateLevel, and never removes levels that hold real registered user orders - only their synthetic MarketVolume is cleared. MatchingEngineSettings gets a MaxDepth (default 5) mirroring MarketEmulatorSettings, and MarketEmulator syncs it into the engine. Add tests asserting the tick- and Level1-synthesized book stays within MaxDepth; the fill-price tests (fills near the current price, not a stale extreme) stay green.
44 lines
1.3 KiB
C#
44 lines
1.3 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>
|
|
/// To add the additional volume into order book at registering orders with greater volume.
|
|
/// </summary>
|
|
public bool IncreaseDepthVolume { get; set; } = true;
|
|
|
|
/// <summary>
|
|
/// The size of spread in price increments for generation of order book from tick trades.
|
|
/// </summary>
|
|
public int SpreadSize { get; set; } = 2;
|
|
|
|
/// <summary>
|
|
/// The maximal depth of order book synthesized from ticks/Level1 when there is no order book history.
|
|
/// Stale synthesized levels beyond this depth are pruned so the book cannot grow unbounded. Default is 5.
|
|
/// </summary>
|
|
public int MaxDepth { get; set; } = 5;
|
|
}
|