Ejemplo n.º 1
0
			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);
			}
Ejemplo n.º 2
0
		public StudioRegistryConnector(IConnector studioConnector)
		{
			EntityFactory = new StudioConnectorEntityFactory();

			_adapter = new PassThroughMessageAdapter(TransactionIdGenerator);
			Adapter.InnerAdapters.Add(_adapter.ToChannel(this));

			_entityRegistry = ConfigManager.GetService<IStudioEntityRegistry>();
			_entityRegistry.Securities.Added += s => _adapter.SendOutMessage(s.ToMessage(GetSecurityId(s)));
			_entityRegistry.Portfolios.Added += p => _adapter.SendOutMessage(p.ToMessage());

			var cmdSvc = ConfigManager.GetService<IStudioCommandService>();

			//cmdSvc.Register<LookupSecuritiesCommand>(this, cmd => LookupSecurities(cmd.Criteria));
			cmdSvc.Register<RequestPortfoliosCommand>(this, false, cmd => Portfolios.ForEach(pf => new PortfolioCommand(pf, true).Process(this)));

			NewPortfolios += portfolios => portfolios.ForEach(pf => new PortfolioCommand(pf, true).Process(this));
			//NewPositions += positions => positions.ForEach(pos => new PositionCommand(pos, true).Process(this));

			// для корректной работы правил коннектор всегда должен быть реальным
			//NewSecurities += securities => securities.ForEach(s => s.Connector = studioConnector);
			NewPortfolios += portfolios => portfolios.ForEach(p => p.Connector = studioConnector);
		}