MarketEmulator

StockSharp.Algo.Testing.Emulation

Market emulator v2 with modular architecture. Wraps MatchingEngineAdapter and adds emulation-specific logic (random volumes, tick/L1→orderbook conversion, candle matching, commissions, price limits).

Inherits: BaseLogReceiver

Implements: IMarketEmulator, IMessageTransport, ILogSource, IDisposable

Constructors

MarketEmulator
public MarketEmulator(ISecurityProvider securityProvider, IPortfolioProvider portfolioProvider, IExchangeInfoProvider exchangeInfoProvider, IdGenerator transactionIdGenerator)
marketEmulator = MarketEmulator(securityProvider, portfolioProvider, exchangeInfoProvider, transactionIdGenerator)

Initializes a new instance.

Properties

CurrentTime
public override DateTime CurrentTime { get; }
value = marketEmulator.CurrentTime

Current time, which will be passed to the Time.

ExchangeInfoProvider
public IExchangeInfoProvider ExchangeInfoProvider { get; }
value = marketEmulator.ExchangeInfoProvider

Exchanges and trading boards provider.

OrderIdGenerator
public IncrementalIdGenerator OrderIdGenerator { get; set; }
value = marketEmulator.OrderIdGenerator
marketEmulator.OrderIdGenerator = value

Order ID generator.

PortfolioManager
public EmulatedPortfolioManager PortfolioManager { get; }
value = marketEmulator.PortfolioManager

Portfolio manager for handling portfolio state.

PortfolioProvider
public IPortfolioProvider PortfolioProvider { get; }
value = marketEmulator.PortfolioProvider

The portfolio to be used to register orders. If value is not given, the portfolio with default name Simulator will be created.

PossibleSupportedMessages
public IEnumerable<MessageTypeInfo> PossibleSupportedMessages { get; }
value = marketEmulator.PossibleSupportedMessages

Possible supported message types.

ProcessedMessageCount
public long ProcessedMessageCount { get; private set; }
value = marketEmulator.ProcessedMessageCount
marketEmulator.ProcessedMessageCount = value

Processed message count.

RandomProvider
public IEmulationRandomizer RandomProvider { get; set; }
value = marketEmulator.RandomProvider
marketEmulator.RandomProvider = value

Where anything in the strategy that draws at random takes its draws from.

SecurityProvider
public ISecurityProvider SecurityProvider { get; }
value = marketEmulator.SecurityProvider

The provider of information about instruments.

Settings
public MarketEmulatorSettings Settings { get; }
value = marketEmulator.Settings

Emulator settings.

TradeIdGenerator
public IncrementalIdGenerator TradeIdGenerator { get; set; }
value = marketEmulator.TradeIdGenerator
marketEmulator.TradeIdGenerator = value

Trade ID generator.

TransactionIdGenerator
public IdGenerator TransactionIdGenerator { get; }
value = marketEmulator.TransactionIdGenerator

Transaction id generator.

VerifyMode
public bool VerifyMode { get; set; }
value = marketEmulator.VerifyMode
marketEmulator.VerifyMode = value

Extended verification mode.

Methods

ApplyCommissionsAsync
private ValueTask ApplyCommissionsAsync(List<Message> messages, CancellationToken cancellationToken)
result = marketEmulator.ApplyCommissionsAsync(messages, cancellationToken)

Price every trade in this batch. Called once, where the batch leaves the emulator.

CheckLimitOrders
private void CheckLimitOrders(SecurityId securityId, decimal? tradePrice, DateTime time, List<Message> results)
marketEmulator.CheckLimitOrders(securityId, tradePrice, time, results)

Re-evaluate resting limit orders against the current order book and execute the ones the market has moved through. Unlike stop orders, limit orders are otherwise matched only at registration time, so a tick/quote trading through a resting limit would leave it sitting in the book and later fill at a price the market has left behind.

GetSecurityState
public SecurityState GetSecurityState(SecurityId securityId)
result = marketEmulator.GetSecurityState(securityId)

State the emulation keeps for one security: its book, its orders and its definition.

securityId
Security to read.

Returns: The state.

ReleaseStoredCandles
private void ReleaseStoredCandles(DateTime time, List<Message> results)
marketEmulator.ReleaseStoredCandles(time, results)

Hand over every bar still held whose close falls no later than , each at its own close and in order.

ReplayCandle
private void ReplayCandle(SecurityId securityId, SecurityEmulator emulator, CandleMessage candle, DateTime time, List<Message> results)
marketEmulator.ReplayCandle(securityId, emulator, candle, time, results)

Replay a closed candle as the prices it recorded, in the order it recorded them.

SendOutMessageAsync
public ValueTask SendOutMessageAsync(Message message, CancellationToken cancellationToken)
result = marketEmulator.SendOutMessageAsync(message, cancellationToken)

Send out message.

Events

NewOutMessageAsync
public event Func<Message, CancellationToken, ValueTask> NewOutMessageAsync
marketEmulator.NewOutMessageAsync += handler

New message event.