Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Неправильная остановка стратегии при WaitAllTrades = true #223

Closed
Sergey-Dvortsov opened this issue Apr 12, 2016 · 1 comment

Comments

@Sergey-Dvortsov
Copy link
Contributor

Если для стратегии флаг WaitAllTrades = true, и если до момента вызова метода Stop не пришло событие собственных сделок, то стратегия полностью не останавливается - зависает в состоянии Stopping.

Пример кода:

 public class SimpleStrategy : Strategy
    {

        public SimpleStrategy()
        {
            WaitAllTrades = true;
        }

        protected override void OnStarted()
        {

            if (!Connector.RegisteredSecurities.Contains(Security))
                Connector.RegisterSecurity(Security);

            Order order = null;

            this.WhenNewMyTrades().Do(trades => 
            {
                this.AddInfoLog(string.Format("Моя сделка. {0}", trades.First()));
            }).Apply(this);

            this.WhenPositionChanged().Do(position => 
            {
                this.AddInfoLog(string.Format("Изменение позиции. {0}, Позиция {1}", position, this.Position));
            }).Apply();

            while (order == null)
            {
                if (Security.BestAsk != null)
                {
                    var price = Security.BestAsk.Price;
                    order = this.BuyAtLimit(price);
                    order.WhenMatched(Connector).Do(o =>
                    {
                        this.AddInfoLog(string.Format("Заявка полностью исполнена. Позиция: {0}", Position));
                        this.Stop();
                    }).Apply(this);
                    this.RegisterOrder(order);
                }
                System.Threading.Thread.Sleep(200);
            }

            base.OnStarted();

        }

        protected override void OnStopped()
        {
            base.OnStarted();
        }

        protected override void OnStopped()
        {
            this.AddInfoLog("Стратегия остановлена.");
        }

        protected override void OnStopping()
        {
            this.AddInfoLog("Стратегия останавливается.");
            base.OnStopping();
        }

    }

Лог прикреплен.

@Sergey-Dvortsov
Copy link
Contributor Author

log.txt

risty added a commit to risty/StockSharp that referenced this issue Oct 15, 2016
This was referenced Oct 15, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants