Beispiel #1
0
        public void PlaceOrder(Order order)
        {
            if (_strategy.IsPrimaryStoppingStarted())
            {
                return;
            }

            if (_isOrderRegistering)
            {
                return;
            }

            _isOrderRegistering = true;

            _strategy.AddWarningLog($"TRY TO PLACE ORDER {order}, {_strategy.Name}: {_strategy.ProcessState}");

            _currentOrder = order;

            if (_currentOrder == null)
            {
                IsAnyOrdersInWork   = false;
                _isOrderRegistering = false;
                throw new ArgumentNullException(nameof(_currentOrder));
            }

            _currentOrder.WhenRegistered(_strategy.Connector)
            .Do(() =>
            {
                _strategy.AddWarningLog($"NOTE THAT ORDER REGISTERED {order}, {_strategy.Name}: {_strategy.ProcessState}");
                _eventWaiter.Set();
            })
            .Once()
            .Apply(_strategy);

            _strategy.RegisterOrder(_currentOrder);

            ContinueOrTimeout(() =>
            {
                IsAnyOrdersInWork   = true;
                _isOrderRegistering = false;
            });
        }
Beispiel #2
0
        public OrderSynchronizer(PrimaryStrategy strategy)
        {
            Timeout = 1000;

            _currentOrder       = null;
            IsAnyOrdersInWork   = false;
            _isOrderRegistering = false;
            _isOrderCanceling   = false;
            _strategy           = strategy;

            _strategy.WhenStopping()
            .Or(_strategy.WhenStopped())
            .Do(s =>
            {
                _strategy.AddWarningLog($"trying to stop {_strategy.Name}: {_strategy.ProcessState}");
                _eventWaiter.Set();
            })
            .Apply(_strategy);
        }