/// <summary> /// Initializes a new instance of the <see cref="BaseEmulationConnector"/>. /// </summary> /// <param name="emulationAdapter">Emulation message adapter.</param> /// <param name="securityProvider">The provider of information about instruments.</param> /// <param name="portfolioProvider">The portfolio to be used to register orders. If value is not given, the portfolio with default name Simulator will be created.</param> public BaseEmulationConnector(EmulationMessageAdapter emulationAdapter, ISecurityProvider securityProvider, IPortfolioProvider portfolioProvider) { Adapter.InnerAdapters.Add(emulationAdapter ?? throw new ArgumentNullException(nameof(emulationAdapter))); Adapter.ApplyHeartbeat(EmulationAdapter, EmulationAdapter.OwnInnerAdapter); TimeChange = false; EntityFactory = new StorageEntityFactory(securityProvider ?? throw new ArgumentNullException(nameof(securityProvider)), portfolioProvider ?? throw new ArgumentNullException(nameof(portfolioProvider))); }
/// <summary> /// Initializes a new instance of the <see cref="BaseEmulationConnector"/>. /// </summary> /// <param name="emulationAdapter">Emulation message adapter.</param> /// <param name="applyHeartbeat">Apply on/off heartbeat mode for the specified adapter.</param> public BaseEmulationConnector(EmulationMessageAdapter emulationAdapter, bool applyHeartbeat) { Adapter.InnerAdapters.Add(emulationAdapter ?? throw new ArgumentNullException(nameof(emulationAdapter))); Adapter.ApplyHeartbeat(EmulationAdapter, applyHeartbeat); TimeChange = false; EntityFactory = new StorageEntityFactory(emulationAdapter.Emulator.SecurityProvider, emulationAdapter.Emulator.PortfolioProvider); }
/// <summary> /// Initializes a new instance of the <see cref="BaseEmulationConnector"/>. /// </summary> /// <param name="emulationAdapter">Emulation message adapter.</param> /// <param name="applyHeartbeat">Apply on/off heartbeat mode for the specified adapter.</param> protected BaseEmulationConnector(EmulationMessageAdapter emulationAdapter, bool applyHeartbeat) : base( new InMemorySecurityStorage(emulationAdapter.CheckOnNull().Emulator.SecurityProvider), new InMemoryPositionStorage(emulationAdapter.Emulator.PortfolioProvider), emulationAdapter.Emulator.ExchangeInfoProvider) { Adapter.InnerAdapters.Add(emulationAdapter ?? throw new ArgumentNullException(nameof(emulationAdapter))); Adapter.ApplyHeartbeat(EmulationAdapter, applyHeartbeat); TimeChange = false; // sync transaction ids with underlying adapter TransactionIdGenerator = emulationAdapter.TransactionIdGenerator; }
/// <summary> /// Создать <see cref="HistoryEmulationConnector"/>. /// </summary> /// <param name="securityProvider">Поставщик информации об инструментах.</param> /// <param name="portfolios">Портфели, с которыми будет вестись работа.</param> /// <param name="storageRegistry">Хранилище данных.</param> public HistoryEmulationConnector(ISecurityProvider securityProvider, IEnumerable <Portfolio> portfolios, IStorageRegistry storageRegistry) { if (securityProvider == null) { throw new ArgumentNullException("securityProvider"); } if (portfolios == null) { throw new ArgumentNullException("portfolios"); } if (storageRegistry == null) { throw new ArgumentNullException("storageRegistry"); } // чтобы каждый раз при повторной эмуляции получать одинаковые номера транзакций TransactionIdGenerator = new IncrementalIdGenerator(); _initialMoney = portfolios.ToDictionary(pf => pf, pf => pf.BeginValue); EntityFactory = new EmulationEntityFactory(securityProvider, _initialMoney.Keys); OutMessageChannel = new PassThroughMessageChannel(); _emulationAdapter = new EmulationMessageAdapter(TransactionIdGenerator); _historyAdapter = new HistoryMessageAdapter(TransactionIdGenerator, securityProvider) { StorageRegistry = storageRegistry }; _historyChannel = new InMemoryMessageChannel("History Out", SendOutError); Adapter = new HistoryBasketMessageAdapter(this); Adapter.InnerAdapters.Add(_emulationAdapter); Adapter.InnerAdapters.Add(new ChannelMessageAdapter(_historyAdapter, new InMemoryMessageChannel("History In", SendOutError), _historyChannel)); // при тестировании по свечкам, время меняется быстрее и таймаут должен быть больше 30с. ReConnectionSettings.TimeOutInterval = TimeSpan.MaxValue; MaxMessageCount = 1000; TradesKeepCount = 0; }
/// <summary> /// Инициализировать <see cref="BaseEmulationConnector"/>. /// </summary> protected BaseEmulationConnector() { var adapter = new EmulationMessageAdapter(new MarketEmulator(), TransactionIdGenerator); Adapter.InnerAdapters.Add(adapter.ToChannel(this)); }
/// <summary> /// Initialize <see cref="BaseEmulationConnector"/>. /// </summary> protected BaseEmulationConnector() { EmulationAdapter = new EmulationMessageAdapter(TransactionIdGenerator); }
//protected override void CreateInnerAdapters() //{ // var tradeIdGenerator = new IncrementalIdGenerator(); // var orderIdGenerator = new IncrementalIdGenerator(); // foreach (var session in SessionHolder.InnerSessions) // { // if (!session.IsTransactionEnabled) // continue; // var adapter = (EmulationMessageAdapter)session.CreateTransactionAdapter(); // ApplySettings(adapter, tradeIdGenerator, orderIdGenerator); // AddInnerAdapter(adapter, SessionHolder.InnerSessions[session]); // } //} private void ApplySettings(EmulationMessageAdapter adapter, IncrementalIdGenerator tradeIdGenerator, IncrementalIdGenerator orderIdGenerator) { adapter.Emulator.Settings.Load(_settings.Save()); ((MarketEmulator)adapter.Emulator).TradeIdGenerator = tradeIdGenerator; ((MarketEmulator)adapter.Emulator).OrderIdGenerator = orderIdGenerator; }
/// <summary> /// »нициализировать <see cref="BaseEmulationConnector"/>. /// </summary> protected BaseEmulationConnector() { TransactionAdapter = _adapter = new EmulationMessageAdapter(new MarketEmulator(), new PassThroughSessionHolder(TransactionIdGenerator)); }
/// <summary> /// Initialize <see cref="BaseEmulationConnector"/>. /// </summary> protected BaseEmulationConnector() { EmulationAdapter = new EmulationMessageAdapter(TransactionIdGenerator); TimeChange = false; }
/// <summary> /// Инициализировать <see cref="BaseEmulationConnector"/>. /// </summary> protected BaseEmulationConnector() { var adapter = new EmulationMessageAdapter(new MarketEmulator(), TransactionIdGenerator); Adapter.InnerAdapters.Add(adapter.ToChannel(this)); }
/// <summary> /// Создать <see cref="HistoryEmulationConnector"/>. /// </summary> /// <param name="securityProvider">Поставщик информации об инструментах.</param> /// <param name="portfolios">Портфели, с которыми будет вестись работа.</param> /// <param name="storageRegistry">Хранилище данных.</param> public HistoryEmulationConnector(ISecurityProvider securityProvider, IEnumerable<Portfolio> portfolios, IStorageRegistry storageRegistry) { if (securityProvider == null) throw new ArgumentNullException("securityProvider"); if (portfolios == null) throw new ArgumentNullException("portfolios"); if (storageRegistry == null) throw new ArgumentNullException("storageRegistry"); // чтобы каждый раз при повторной эмуляции получать одинаковые номера транзакций TransactionIdGenerator = new IncrementalIdGenerator(); _initialMoney = portfolios.ToDictionary(pf => pf, pf => pf.BeginValue); EntityFactory = new EmulationEntityFactory(securityProvider, _initialMoney.Keys); OutMessageChannel = new PassThroughMessageChannel(); _emulationAdapter = new EmulationMessageAdapter(TransactionIdGenerator); _historyAdapter = new HistoryMessageAdapter(TransactionIdGenerator, securityProvider) { StorageRegistry = storageRegistry }; _historyChannel = new InMemoryMessageChannel("History Out", SendOutError); Adapter = new HistoryBasketMessageAdapter(this); Adapter.InnerAdapters.Add(_emulationAdapter); Adapter.InnerAdapters.Add(new ChannelMessageAdapter(_historyAdapter, new InMemoryMessageChannel("History In", SendOutError), _historyChannel)); // при тестировании по свечкам, время меняется быстрее и таймаут должен быть больше 30с. ReConnectionSettings.TimeOutInterval = TimeSpan.MaxValue; MaxMessageCount = 1000; }