Exemple #1
0
        private void EmulationConnectorOnStateChanged()
        {
            switch (EmulationConnector.State)
            {
                case EmulationStates.Starting:
                {
                    if (_prev != EmulationStates.Stopped)
                        break;

                    _nextTime = EmulationSettings.StartTime + _progressStep;
                    CurrentProgress = 0;

                    ApplySettings();

                    //EmulationConnector.StartExport();
                    OnEmulationStarting();

                    break;
                }

                case EmulationStates.Started:
                    State = EmulationStates.Started;
                    break;

                case EmulationStates.Stopping:
                    //EmulationConnector.StopExport();
                    break;

                case EmulationStates.Stopped:
                    OnEmulationStopped();
                    break;
            }

            _prev = EmulationConnector.State;
        }
Exemple #2
0
        private void ProcessEmulationStateMessage(EmulationStates newState)
        {
            this.AddInfoLog(LocalizedStrings.Str1121Params, State, newState);

            State = newState;

            switch (newState)
            {
            case EmulationStates.Stopping:
            {
                SendEmulationState(EmulationStates.Stopped);
                break;
            }

            case EmulationStates.Stopped:
            {
                // change ConnectionState to Disconnecting
                if (ConnectionState != ConnectionStates.Disconnecting)
                {
                    Disconnect();
                }

                SendInMessage(new DisconnectMessage());
                break;
            }

            case EmulationStates.Starting:
            {
                SendEmulationState(EmulationStates.Started);
                break;
            }
            }
        }
        private void ProcessEmulationStateMessage(EmulationStates newState)
        {
            this.AddInfoLog(LocalizedStrings.Str1121Params, State, newState);

            State = newState;

            switch (newState)
            {
            case EmulationStates.Stopped:
            {
                break;
            }

            case EmulationStates.Stopping:
            {
                SendInMessage(new DisconnectMessage());
                break;
            }

            case EmulationStates.Starting:
            {
                SendEmulationState(EmulationStates.Started);
                break;
            }

            case EmulationStates.Started:
            {
                _suspendLock.PulseAll();
                break;
            }

            case EmulationStates.Suspending:
            {
                SendEmulationState(EmulationStates.Suspended);
                break;
            }

            case EmulationStates.Suspended:
            {
                State = newState;
                _suspendLock.Wait();
                break;
            }

            default:
                throw new ArgumentOutOfRangeException();
            }
        }
Exemple #4
0
        private void TryStartNextBatch()
        {
            if (!_batches.MoveNext() || _cancelEmulation)
            {
                State = EmulationStates.Stopping;
                State = EmulationStates.Stopped;
                return;
            }

            _batch = _batches.Current.ToArray();
            _currentBatch++;

            InitAdapters(_batch);

            EmulationConnector.HistoryMessageAdapter.StartDate = EmulationSettings.StartTime;
            EmulationConnector.HistoryMessageAdapter.StopDate  = EmulationSettings.StopTime;

            EmulationConnector.Connect();
        }
Exemple #5
0
        /// <summary>
        /// Start emulation.
        /// </summary>
        /// <param name="strategies">The strategies.</param>
        /// <param name="iterationCount"></param>
        public void Start(IEnumerable <Strategy> strategies, int iterationCount)
        {
            if (strategies == null)
            {
                throw new ArgumentNullException(nameof(strategies));
            }

            _progressStep = ((EmulationSettings.StopTime - EmulationSettings.StartTime).Ticks / 100).To <TimeSpan>();

            _cancelEmulation = false;
            _totalBatches    = (int)((decimal)iterationCount / EmulationSettings.BatchSize).Ceiling();
            _currentBatch    = -1;

            CurrentProgress = 0;

            State = EmulationStates.Starting;

            _batches = strategies.Batch(EmulationSettings.BatchSize).GetEnumerator();

            TryStartNextBatch();
        }
Exemple #6
0
        private void EmulationConnectorOnStateChanged()
        {
            switch (EmulationConnector.State)
            {
            case EmulationStates.Starting:
            {
                if (_prev != EmulationStates.Stopped)
                {
                    break;
                }

                _nextTime       = EmulationSettings.StartTime + _progressStep;
                CurrentProgress = 0;

                ApplySettings();
                break;
            }

            case EmulationStates.Started:
                State = EmulationStates.Started;
                break;

            case EmulationStates.Stopping:
                break;

            case EmulationStates.Stopped:
            {
                if (!_cancelEmulation)
                {
                    CurrentProgress = 100;
                }

                OnEmulationStopped();
                break;
            }
            }

            _prev = EmulationConnector.State;
        }
        private void BasketEmulationOnStateChanged(EmulationStates oldState, EmulationStates newState)
        {
            switch (_basketEmulation.State)
            {
            case EmulationStates.Stopped:
            {
                OnEmulationStopped();

                IsInProgress = false;
                Progress     = 0;

                new ChartAutoRangeCommand(false).Process(Strategy.Strategy);

                CanStart = true;
                break;
            }

            case EmulationStates.Started:
            {
                if (oldState != EmulationStates.Starting)
                {
                    break;
                }

                _prevEmulTime   = DateTimeOffset.MinValue;
                _prevSystemTime = DateTime.Now;
                _emulDuration   = TimeSpan.Zero;

                IsInProgress = true;

                CanStop = true;

                new ChartAutoRangeCommand(true).Process(Strategy.Strategy);

                break;
            }
            }
        }
Exemple #8
0
 private void SendEmulationState(EmulationStates state)
 {
     SendInMessage(new EmulationStateMessage {
         State = state
     });
 }
		private void ProcessEmulationStateMessage(EmulationStates newState)
		{
			this.AddInfoLog(LocalizedStrings.Str1121Params, State, newState);

			State = newState;

			switch (newState)
			{
				case EmulationStates.Stopping:
				{
					SendInMessage(new DisconnectMessage());
					break;
				}

				case EmulationStates.Starting:
				{
					SendEmulationState(EmulationStates.Started);
					break;
				}
			}
		}
		private void SendEmulationState(EmulationStates state)
		{
			SendInMessage(new EmulationStateMessage { State = state });
		}
		private void TryStartNextBatch()
		{
			if (!_batches.MoveNext() || _cancelEmulation)
			{
				State = EmulationStates.Stopping;
				State = EmulationStates.Stopped;
				return;
			}

			_batch = _batches.Current.ToArray();
			_currentBatch ++;

			InitAdapters(_batch);

			EmulationConnector.HistoryMessageAdapter.StartDate = EmulationSettings.StartTime;
			EmulationConnector.HistoryMessageAdapter.StopDate = EmulationSettings.StopTime;

			EmulationConnector.Connect();
		}
		/// <summary>
		/// To start paper trading.
		/// </summary>
		public void Start(IEnumerableEx<Strategy> strategies)
		{
			if (strategies == null)
				throw new ArgumentNullException(nameof(strategies));

			_progressStep = ((EmulationSettings.StopTime - EmulationSettings.StartTime).Ticks / 100).To<TimeSpan>();
			
			_cancelEmulation = false;
			_totalBatches = (int)((decimal)strategies.Count / EmulationSettings.BatchSize).Ceiling();
			_currentBatch = -1;

			CurrentProgress = 0;
			
			State = EmulationStates.Starting;

			_batches = strategies.Batch(EmulationSettings.BatchSize).GetEnumerator();

			TryStartNextBatch();
		}
		private void EmulationConnectorOnStateChanged()
		{
			switch (EmulationConnector.State)
			{
				case EmulationStates.Starting:
				{
					if (_prev != EmulationStates.Stopped)
						break;

					_nextTime = EmulationSettings.StartTime + _progressStep;
					CurrentProgress = 0;

					ApplySettings();

					//EmulationConnector.StartExport();
					OnEmulationStarting();

					break;
				}

				case EmulationStates.Started:
					State = EmulationStates.Started;
					break;

				case EmulationStates.Stopping:
					//EmulationConnector.StopExport();
					break;

				case EmulationStates.Stopped:
					OnEmulationStopped();
					break;
			}

			_prev = EmulationConnector.State;
		}
Exemple #14
0
		private void BasketEmulationOnStateChanged(EmulationStates oldState, EmulationStates newState)
		{
			switch (_basketEmulation.State)
			{
				case EmulationStates.Stopped:
				{
					OnEmulationStopped();

					IsInProgress = false;
					Progress = 0;

					new ChartAutoRangeCommand(false).Process(Strategy.Strategy);

					CanStart = true;
					break;
				}

				case EmulationStates.Started:
				{
					if (oldState != EmulationStates.Starting)
						break;

					_prevEmulTime = DateTimeOffset.MinValue;
					_prevSystemTime = DateTime.Now;
					_emulDuration = TimeSpan.Zero;

					IsInProgress = true;

					CanStop = true;

					new ChartAutoRangeCommand(true).Process(Strategy.Strategy);

					break;
				}
			}
		}
Exemple #15
0
 private void SetEmulationState(EmulationStates state)
 {
     MarketDataAdapter.SendInMessage(new EmulationStateMessage {
         NewState = state
     });
 }