public HistoryEmulationMessageChannel(HistoryMessageAdapter historyMessageAdapter, Action <Exception> errorHandler) { _historyMessageAdapter = historyMessageAdapter ?? throw new ArgumentNullException(nameof(historyMessageAdapter)); _errorHandler = errorHandler ?? throw new ArgumentNullException(nameof(errorHandler)); _messageQueue.Close(); }
/// <summary> /// Initializes a new instance of the <see cref="HistoryEmulationConnector"/>. /// </summary> /// <param name="securityProvider">The provider of information about instruments.</param> /// <param name="portfolios">Portfolios, the operation will be performed with.</param> /// <param name="storageRegistry">Market data storage.</param> public HistoryEmulationConnector(ISecurityProvider securityProvider, IEnumerable <Portfolio> portfolios, IStorageRegistry storageRegistry) { if (securityProvider == null) { throw new ArgumentNullException(nameof(securityProvider)); } if (portfolios == null) { throw new ArgumentNullException(nameof(portfolios)); } if (storageRegistry == null) { throw new ArgumentNullException(nameof(storageRegistry)); } // чтобы каждый раз при повторной эмуляции получать одинаковые номера транзакций TransactionIdGenerator = new IncrementalIdGenerator(); _initialMoney = portfolios.ToDictionary(pf => pf, pf => pf.BeginValue); EntityFactory = new EmulationEntityFactory(securityProvider, _initialMoney.Keys); RiskManager = null; SupportSubscriptionTracking = true; SupportBasketSecurities = true; HistoryMessageAdapter = new HistoryMessageAdapter(TransactionIdGenerator, securityProvider) { StorageRegistry = storageRegistry }; InMessageChannel = new HistoryEmulationMessageChannel(HistoryMessageAdapter, SendOutError); OutMessageChannel = new PassThroughMessageChannel(); Adapter = new HistoryBasketMessageAdapter(this); Adapter.InnerAdapters.Add(EmulationAdapter); Adapter.InnerAdapters.Add(HistoryMessageAdapter); Adapter.LatencyManager = null; Adapter.CommissionManager = null; Adapter.PnLManager = null; Adapter.SlippageManager = null; // при тестировании по свечкам, время меняется быстрее и таймаут должен быть больше 30с. ReConnectionSettings.TimeOutInterval = TimeSpan.MaxValue; //MaxMessageCount = 1000; TradesKeepCount = 0; RaiseConnectedOnFirstAdapter = false; }
public StrategyConnector(StrategyContainer strategy, DateTimeOffset startDate, DateTimeOffset stopDate, TimeSpan useCandlesTimeFrame, bool onlyInitialize) { if (strategy == null) throw new ArgumentNullException("strategy"); UpdateSecurityLastQuotes = false; UpdateSecurityByLevel1 = false; var entityRegistry = ConfigManager.GetService<IStudioEntityRegistry>(); _strategy = strategy; _useCandlesTimeFrame = useCandlesTimeFrame; _onlyInitialize = onlyInitialize; _sessionStrategy = entityRegistry.ReadSessionStrategyById(strategy.Strategy.Id); if (_sessionStrategy == null) throw new InvalidOperationException("sessionStrategy = null"); Id = strategy.Id; Name = strategy.Name + " Connector"; _realConnector = (StudioConnector)ConfigManager.GetService<IStudioConnector>(); _realConnector.NewMessage += RealConnectorNewMessage; EntityFactory = new StudioConnectorEntityFactory(); _securityProvider = new StudioSecurityProvider(); var storageRegistry = new StudioStorageRegistry { MarketDataSettings = strategy.MarketDataSettings }; Adapter.InnerAdapters.Add(_historyMessageAdapter = new HistoryMessageAdapter(TransactionIdGenerator, _securityProvider) { StartDate = startDate, StopDate = stopDate, StorageRegistry = storageRegistry }); //_historyMessageAdapter.UpdateCurrentTime(startDate); var transactionAdapter = new PassThroughMessageAdapter(TransactionIdGenerator); transactionAdapter.AddTransactionalSupport(); Adapter.InnerAdapters.Add(transactionAdapter); _historyMessageAdapter.MarketTimeChangedInterval = useCandlesTimeFrame; // при инициализации по свечкам, время меняется быстрее и таймаут должен быть больше 30с. ReConnectionSettings.TimeOutInterval = TimeSpan.MaxValue; _historyMessageAdapter.BasketStorage.InnerStorages.AddRange(GetExecutionStorages()); this.LookupById(strategy.Security.Id); new ChartAutoRangeCommand(true).Process(_strategy); }
/// <summary> /// Initializes a new instance of the <see cref="HistoryEmulationConnector"/>. /// </summary> /// <param name="securityProvider">The provider of information about instruments.</param> /// <param name="portfolios">Portfolios, the operation will be performed with.</param> /// <param name="storageRegistry">Market data storage.</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); InMessageChannel = new PassThroughMessageChannel(); OutMessageChannel = new PassThroughMessageChannel(); LatencyManager = null; RiskManager = null; CommissionManager = null; PnLManager = null; SlippageManager = null; _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="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); _sessionHolder = new HistorySessionHolder(TransactionIdGenerator, securityProvider); MarketDataAdapter = _marketDataAdapter = new HistoryMessageAdapter(_sessionHolder) { StorageRegistry = storageRegistry }; _sessionHolder.MarketTimeChangedInterval = TimeSpan.FromSeconds(1); // при тестировании по свечкам, время меняется быстрее и таймаут должен быть больше 30с. _sessionHolder.ReConnectionSettings.TimeOutInterval = TimeSpan.MaxValue; ApplyMessageProcessor(MessageDirections.In, true, true); ApplyMessageProcessor(MessageDirections.Out, true, true, new NonThreadMessageProcessor(TransactionAdapter.InMessageProcessor)); ((MessageAdapter <IMessageSessionHolder>)TransactionAdapter).SessionHolder = _sessionHolder; }
/// <summary> /// To release allocated resources. In particular, to disconnect from the trading system via <see cref="Connector.Disconnect"/>. /// </summary> protected override void DisposeManaged() { base.DisposeManaged(); HistoryMessageAdapter.Dispose(); }
/// <summary> /// Initializes a new instance of the <see cref="HistoryEmulationConnector"/>. /// </summary> /// <param name="securityProvider">The provider of information about instruments.</param> /// <param name="portfolios">Portfolios, the operation will be performed with.</param> /// <param name="storageRegistry">Market data storage.</param> public HistoryEmulationConnector(ISecurityProvider securityProvider, IEnumerable<Portfolio> portfolios, IStorageRegistry storageRegistry) { if (securityProvider == null) throw new ArgumentNullException(nameof(securityProvider)); if (portfolios == null) throw new ArgumentNullException(nameof(portfolios)); if (storageRegistry == null) throw new ArgumentNullException(nameof(storageRegistry)); // чтобы каждый раз при повторной эмуляции получать одинаковые номера транзакций TransactionIdGenerator = new IncrementalIdGenerator(); _initialMoney = portfolios.ToDictionary(pf => pf, pf => pf.BeginValue); EntityFactory = new EmulationEntityFactory(securityProvider, _initialMoney.Keys); InMessageChannel = new PassThroughMessageChannel(); OutMessageChannel = new PassThroughMessageChannel(); LatencyManager = null; RiskManager = null; CommissionManager = null; PnLManager = null; SlippageManager = null; HistoryMessageAdapter = 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(HistoryMessageAdapter, new InMemoryMessageChannel("History In", SendOutError), _historyChannel)); // при тестировании по свечкам, время меняется быстрее и таймаут должен быть больше 30с. ReConnectionSettings.TimeOutInterval = TimeSpan.MaxValue; MaxMessageCount = 1000; TradesKeepCount = 0; }
private void AddHistoryAdapter(string portfolio) { var session = new HistoryMessageAdapter(EmulationConnector.TransactionIdGenerator) { }; //_basketSessionHolder.InnerSessions.Add(session, 0); //_basketSessionHolder.Portfolios[portfolio] = session; }