示例#1
0
        //Execute rule logic
        //Place Sell Limit orders when notified by OnOpenForTrading rule
        override protected bool ExcuteRuleLogic(Niffle message)
        {
            if (IsTickMessageEmpty(message))
            {
                return(false);
            }
            if (EntryPipsFromTradeOpenPrice == 0.0)
            {
                return(false);                                     //trigger points should be set when initialised
            }
            if (OpenPrice == 0.0)
            {
                return(false);                  //Open price should be set once activated
            }
            double EntryPrice = TradeUtils.AddPipsToPrice(OpenPrice, EntryPipsFromTradeOpenPrice);

            for (int orderNumber = 1; orderNumber <= NumberOfOrders; orderNumber++)
            {
                TradePublisher.PlaceSellLimit(SymbolCode,
                                              StrategyId + "-" + orderNumber,
                                              TradeUtils.CalculateNextOrderVolume(orderNumber),
                                              TradeUtils.AddPipsToPrice(EntryPrice, TradeUtils.CalculateNextEntryPips(orderNumber)));
            }

            //Set inactive if only executing once
            SetActiveState(false);

            //return true to publish a success Service Notify message
            return(true);
        }
示例#2
0
文件: IRule.cs 项目: bildukas86/bots
        private bool IsActive = true; //Default state is active

        public IRule(StrategyConfiguration strategyConfig, RuleConfiguration ruleConfig)
        {
            this.StrategyConfig = strategyConfig;
            this.RuleConfig     = ruleConfig;

            StrategyId = StrategyConfig.StrategyId;
            if (String.IsNullOrEmpty(StrategyId))
            {
                IsInitialised = false;
            }

            ExchangeName = StrategyConfig.Exchange;
            if (String.IsNullOrEmpty(ExchangeName))
            {
                IsInitialised = false;
            }

            BrokerId = StrategyConfig.BrokerId;
            if (String.IsNullOrEmpty(BrokerId))
            {
                IsInitialised = false;
            }

            //Initialise TradeUtils for broker specific config
            TradeUtils = new TradeUtils(new BrokerConfiguration(BrokerId), ruleConfig);

            //Initialise a TradesPublisher
            TradePublisher = new TradePublisher(Publisher, TradeUtils, GetServiceName());

            //Add Rule configuration to Firebase
            StateManager = new StateManager(StrategyId);
            if (StateManager == null)
            {
                IsInitialised = false;
            }
            StateManager.SetInitialStateAsync(RuleConfig.Params);

            //Manage State updates if subscribed to by the derived rule
            StateManager.StateUpdateReceived += OnStateEventUpdate;

            StateManager.SetActivationRulesAsync(GetServiceName(), RuleConfig.ActivateRules);
            StateManager.SetDeactivationRulesAsync(GetServiceName(), RuleConfig.DeactivateRules);

            //If this rule has activation rules default state IsActive = false
            if (RuleConfig.ActivateRules != null)
            {
                IsActive = false;
            }
            StateManager.UpdateRuleStatusAsync(GetServiceName(), RuleConfiguration.ISACTIVE, IsActive);
        }