MarketEmulator
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
public MarketEmulator(ISecurityProvider securityProvider, IPortfolioProvider portfolioProvider, IExchangeInfoProvider exchangeInfoProvider, IdGenerator transactionIdGenerator)
marketEmulator = MarketEmulator(securityProvider, portfolioProvider, exchangeInfoProvider, transactionIdGenerator)
Initializes a new instance.
Properties
public override DateTime CurrentTime { get; }
value = marketEmulator.CurrentTime
Current time, which will be passed to the Time.
public IExchangeInfoProvider ExchangeInfoProvider { get; }
value = marketEmulator.ExchangeInfoProvider
Exchanges and trading boards provider.
public IncrementalIdGenerator OrderIdGenerator { get; set; }
value = marketEmulator.OrderIdGenerator
marketEmulator.OrderIdGenerator = value
Order ID generator.
public EmulatedPortfolioManager PortfolioManager { get; }
value = marketEmulator.PortfolioManager
Portfolio manager for handling portfolio state.
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.
public IEnumerable<MessageTypeInfo> PossibleSupportedMessages { get; }
value = marketEmulator.PossibleSupportedMessages
Possible supported message types.
public long ProcessedMessageCount { get; private set; }
value = marketEmulator.ProcessedMessageCount
marketEmulator.ProcessedMessageCount = value
Processed message count.
public IEmulationRandomizer RandomProvider { get; set; }
value = marketEmulator.RandomProvider
marketEmulator.RandomProvider = value
Where anything in the strategy that draws at random takes its draws from.
public ISecurityProvider SecurityProvider { get; }
value = marketEmulator.SecurityProvider
The provider of information about instruments.
public MarketEmulatorSettings Settings { get; }
value = marketEmulator.Settings
Emulator settings.
public IncrementalIdGenerator TradeIdGenerator { get; set; }
value = marketEmulator.TradeIdGenerator
marketEmulator.TradeIdGenerator = value
Trade ID generator.
public IdGenerator TransactionIdGenerator { get; }
value = marketEmulator.TransactionIdGenerator
Transaction id generator.
public bool VerifyMode { get; set; }
value = marketEmulator.VerifyMode
marketEmulator.VerifyMode = value
Extended verification mode.
Methods
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.
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.
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.
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.
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.
public ValueTask SendOutMessageAsync(Message message, CancellationToken cancellationToken)
result = marketEmulator.SendOutMessageAsync(message, cancellationToken)
Send out message.
Events
public event Func<Message, CancellationToken, ValueTask> NewOutMessageAsync
marketEmulator.NewOutMessageAsync += handler
New message event.