Click or drag to resize

Rules suspension

Sometimes you want to set multiple rules in suspension mode (prevent to trigger any of them until code initialization will be finished). To do this, the MarketRuleHelperSuspendRules(Action) method is used.

Rules suspension using
  • Out of the strategy:

    C#
    MarketRuleHelper.SuspendRules(() =>    
    {
        order
            .WhenRegistered()
            .Do(() => trader.AddInfoLog("The order was successfully registered."))
            .Once()
            .Apply(this);
    
        order
            .WhenCancelled()
            .Do(() => trader.AddInfoLog("The order was successfully cancelled."))
            .Once()
            .Apply(this);
    });
    
    // регистрация заявки
    trader.RegisterOrder(order);
  • Inside the strategy:

    C#
    class FirstStrategy : Strategy
    {
        ...
    
        protected override void OnStarting()
        {
            this.SuspendRules(() =>
            {
                _series
                    .WhenCandlesFinished()
                    .Do(FinishCandle)
                    .Apply(this);
    
                Security
                    .WhenNewTrades()
                    .Do(NewTrade)
                    .Apply(this);
            });
    
            base.OnStarting();
        }
    
        ...
    }