コード例 #1
0
ファイル: QuikLuaDialect.cs プロジェクト: jsonbao/StockSharp
		public QuikLuaDialect(string senderCompId, string targetCompId, Stream stream, IncrementalIdGenerator idGenerator, TimeSpan heartbeatInterval, bool isResetCounter, string login, SecureString password, Func<OrderCondition> createOrderCondition)
			: base(senderCompId, targetCompId, stream, idGenerator, heartbeatInterval, isResetCounter, login, password, TimeHelper.Moscow, createOrderCondition)
		{
			SecurityLookup = true;
			PortfolioLookup = true;
			OrderLookup = true;
		}
コード例 #2
0
        /// <summary>
        /// Initialize <see cref="InMemoryMessageAdapterProvider"/>.
        /// </summary>
        /// <param name="currentAdapters">All currently available adapters.</param>
        public InMemoryMessageAdapterProvider(IEnumerable <IMessageAdapter> currentAdapters)
        {
            var idGenerator = new IncrementalIdGenerator();

            PossibleAdapters = Extensions.Adapters.Select(type => type.CreateAdapter(idGenerator)).ToArray();
            CurrentAdapters  = currentAdapters ?? throw new ArgumentNullException(nameof(currentAdapters));
        }
        public void CreateUnsignedId_Initially_ShouldReturnExpectedResult()
        {
            var generator = new IncrementalIdGenerator();

            var id = generator.CreateUnsignedId();

            Assert.Equal(1UL, id);
        }
コード例 #4
0
 public LuaDialect(string senderCompId, string targetCompId, Stream stream, IncrementalIdGenerator idGenerator, TimeSpan heartbeatInterval, bool isResetCounter, string login, SecureString password, Func <OrderCondition> createOrderCondition)
     : base(senderCompId, targetCompId, stream, idGenerator, heartbeatInterval, isResetCounter, login, password, TimeHelper.Moscow, createOrderCondition)
 {
     SecurityLookup         = true;
     PortfolioLookup        = true;
     OrderLookup            = true;
     SecuritiesSinglePacket = true;
 }
コード例 #5
0
        /// <summary>
        /// Initializes a new instance of the <see cref="OrderLogGenerator"/>.
        /// </summary>
        /// <param name="securityId">The identifier of the instrument, for which data shall be generated.</param>
        /// <param name="tradeGenerator">Tick trades generator using random method.</param>
        public OrderLogGenerator(SecurityId securityId, TradeGenerator tradeGenerator)
            : base(securityId)
        {
            //_lastOrderPrice = startPrice;

            TradeGenerator = tradeGenerator ?? throw new ArgumentNullException(nameof(tradeGenerator));
            IdGenerator    = new IncrementalIdGenerator();
        }
コード例 #6
0
            private void ApplySettings(EmulationMessageAdapter adapter, IncrementalIdGenerator tradeIdGenerator, IncrementalIdGenerator orderIdGenerator)
            {
                adapter.InMessageProcessor  = new NonThreadMessageProcessor();
                adapter.OutMessageProcessor = new NonThreadMessageProcessor();

                adapter.Emulator.Settings.Load(_settings.Save());
                ((MarketEmulator)adapter.Emulator).TradeIdGenerator = tradeIdGenerator;
                ((MarketEmulator)adapter.Emulator).OrderIdGenerator = orderIdGenerator;
            }
コード例 #7
0
        /// <summary>
        /// Initialize <see cref="InMemoryConfigurationMessageAdapterProvider"/>.
        /// </summary>
        public InMemoryConfigurationMessageAdapterProvider()
        {
            var idGenerator = new IncrementalIdGenerator();

            foreach (var type in Extensions.Adapters)
            {
                _adapters.Add(type.CreateInstance <IMessageAdapter>(idGenerator));
            }
        }
        public void CreateUnsignedId_InParallel_ShouldReturnDistinctResults()
        {
            var generator = new IncrementalIdGenerator();

            var results = new ConcurrentQueue <ulong>();

            Parallel.For(0, 100, _ => results.Enqueue(generator.CreateUnsignedId()));

            Assert.Equal(results.Count, results.Distinct().Count());
        }
コード例 #9
0
        /// <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();

            EntityFactory = new EmulationEntityFactory(securityProvider, portfolios);

            RiskManager = null;

            SupportBasketSecurities = true;

            InMessageChannel  = new HistoryEmulationMessageChannel(this);
            OutMessageChannel = new PassThroughMessageChannel();

            Adapter = new HistoryBasketMessageAdapter(this);
            Adapter.InnerAdapters.Add(EmulationAdapter);
            Adapter.InnerAdapters.Add(new HistoryMessageAdapter(TransactionIdGenerator, securityProvider)
            {
                StorageRegistry = storageRegistry
            });

            Adapter.LatencyManager    = null;
            Adapter.CommissionManager = null;
            Adapter.PnLManager        = null;
            Adapter.SlippageManager   = null;

            // при тестировании по свечкам, время меняется быстрее и таймаут должен быть больше 30с.
            //ReConnectionSettings.TimeOutInterval = TimeSpan.MaxValue;

            //MaxMessageCount = 1000;

            TradesKeepCount = 0;

            Adapter.SupportCandlesCompression            = false;
            Adapter.SupportBuildingFromOrderLog          = false;
            Adapter.SupportPartialDownload               = false;
            Adapter.SupportLookupTracking                = false;
            Adapter.SupportOrderBookTruncate             = false;
            Adapter.ConnectDisconnectEventOnFirstAdapter = false;
        }
コード例 #10
0
		/// <summary>
		/// Создать <see cref="OrderLogGenerator"/>.
		/// </summary>
		/// <param name="securityId">Идентификатор инструмента, для которого необходимо генерировать данные.</param>
		/// <param name="tradeGenerator">Генератор тиковых сделок случайным методом.</param>
		public OrderLogGenerator(SecurityId securityId, TradeGenerator tradeGenerator)
			: base(securityId)
		{
			if (tradeGenerator == null)
				throw new ArgumentNullException("tradeGenerator");

			//_lastOrderPrice = startPrice;

			TradeGenerator = tradeGenerator;
			IdGenerator = new IncrementalIdGenerator();
		}
コード例 #11
0
        /// <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;
        }
コード例 #12
0
        /// <summary>
        /// Создать <see cref="OrderLogGenerator"/>.
        /// </summary>
        /// <param name="securityId">Идентификатор инструмента, для которого необходимо генерировать данные.</param>
        /// <param name="tradeGenerator">Генератор тиковых сделок случайным методом.</param>
        public OrderLogGenerator(SecurityId securityId, TradeGenerator tradeGenerator)
            : base(securityId)
        {
            if (tradeGenerator == null)
            {
                throw new ArgumentNullException("tradeGenerator");
            }

            //_lastOrderPrice = startPrice;

            TradeGenerator = tradeGenerator;
            IdGenerator    = new IncrementalIdGenerator();
        }
コード例 #13
0
        /// <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;
        }
        public void CreateUnsignedId_Repeatedly_ShouldReturnExpectedResults()
        {
            var generator = new IncrementalIdGenerator();

            var results = new List <ulong>();

            for (var i = 0; i < 100; i++)
            {
                results.Add(generator.CreateUnsignedId());
            }

            for (var i = 0; i < results.Count; i++)
            {
                Assert.Equal(1UL + (ulong)i, results[i]);
            }
        }
コード例 #15
0
            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]);
                }
            }
コード例 #16
0
        /// <summary>
        /// Initialize <see cref="InMemoryMessageAdapterProvider"/>.
        /// </summary>
        /// <param name="currentAdapters">All currently available adapters.</param>
        public InMemoryMessageAdapterProvider(IEnumerable <IMessageAdapter> currentAdapters)
        {
            CurrentAdapters = currentAdapters ?? throw new ArgumentNullException(nameof(currentAdapters));

            var idGenerator = new IncrementalIdGenerator();

            PossibleAdapters = GetAdapters().Select(t =>
            {
                try
                {
                    return(t.CreateAdapter(idGenerator));
                }
                catch (Exception ex)
                {
                    ex.LogError();
                    return(null);
                }
            }).Where(a => a != null).ToArray();
        }
コード例 #17
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;
        }
コード例 #18
0
ファイル: TradeGenerator.cs プロジェクト: pantov/StockSharp
		/// <summary>
		/// Initialize <see cref="TradeGenerator"/>.
		/// </summary>
		/// <param name="securityId">The identifier of the instrument, for which data shall be generated.</param>
		protected TradeGenerator(SecurityId securityId)
			: base(securityId)
		{
			IdGenerator = new IncrementalIdGenerator();
		}
コード例 #19
0
		/// <summary>
		/// Create FIX protocol dialect.
		/// </summary>
		/// <param name="stream">Stream.</param>
		/// <param name="idGenerator">Sequence id generator.</param>
		/// <returns>The dialect.</returns>
		protected override IFixDialect CreateDialect(Stream stream, IncrementalIdGenerator idGenerator)
		{
			return new LuaDialect(SenderCompId, TargetCompId, stream, idGenerator, HeartbeatInterval, IsResetCounter, Login, Password, () => { throw new NotSupportedException(); });
		}
コード例 #20
0
		/// <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;
		}
コード例 #21
0
		/// <summary>
		/// Create FIX protocol dialect.
		/// </summary>
		/// <param name="stream">Stream.</param>
		/// <param name="idGenerator">Sequence id generator.</param>
		/// <returns>The dialect.</returns>
		protected override IFixDialect CreateDialect(Stream stream, IncrementalIdGenerator idGenerator)
		{
			return new QuikLuaDialect(SenderCompId, TargetCompId, stream, idGenerator, HeartbeatInterval, IsResetCounter, Login, Password, CreateOrderCondition);
		}
 public void Construct_Regularly_ShouldSucceed()
 {
     _ = new IncrementalIdGenerator();
 }
コード例 #23
0
			//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;
			}
コード例 #24
0
 /// <summary>
 /// Create FIX protocol dialect.
 /// </summary>
 /// <param name="stream">Stream.</param>
 /// <param name="idGenerator">Sequence id generator.</param>
 /// <returns>The dialect.</returns>
 protected override IFixDialect CreateDialect(Stream stream, IncrementalIdGenerator idGenerator)
 {
     return(new QuikLuaDialect(SenderCompId, TargetCompId, stream, idGenerator, HeartbeatInterval, IsResetCounter, Login, Password, () => { throw new NotSupportedException(); }));
 }
コード例 #25
0
 /// <summary>
 /// Initialize <see cref="TradeGenerator"/>.
 /// </summary>
 /// <param name="securityId">The identifier of the instrument, for which data shall be generated.</param>
 protected TradeGenerator(SecurityId securityId)
     : base(securityId)
 {
     IdGenerator = new IncrementalIdGenerator();
 }
コード例 #26
0
 /// <summary>
 /// Create FIX protocol dialect.
 /// </summary>
 /// <param name="stream">Stream.</param>
 /// <param name="idGenerator">Sequence id generator.</param>
 /// <returns>The dialect.</returns>
 protected override IFixDialect CreateDialect(Stream stream, IncrementalIdGenerator idGenerator)
 {
     return(new QuikLuaDialect(SenderCompId, TargetCompId, stream, idGenerator, HeartbeatInterval, IsResetCounter, Login, Password, CreateOrderCondition));
 }