public BuySellStockOnSignal(BuySellOnSignalSymbolConfig config, KiteConnect.Kite kite, SignalSettingInfo signalSettingInfo)
 {
     _config            = config;
     _kite              = kite;
     _signalSettingInfo = signalSettingInfo;
     if (config.ReversalInfoes != null && config.ReversalInfoes.Any())
     {
         _reversalMultiplier = config.ReversalInfoes.GroupBy(s => s.ReversalNumber).ToDictionary(key => key.Key, value => value.FirstOrDefault().Multiplier);
     }
 }
 internal void SquareOffAllPositions(BuySellOnSignalSymbolConfig buySellOnSignalSymbolConfig, int count)
 {
     if (_configuresStocks != null && _configuresStocks.Any())
     {
         var stock = _configuresStocks.FirstOrDefault(s => s.IsMatchSymbol(buySellOnSignalSymbolConfig.Exchange, buySellOnSignalSymbolConfig.Symbol));
         if (stock != null)
         {
             stock.SquareOffAllPositions(count);
         }
     }
 }
 public void UpdateMaxLoss(BuySellOnSignalSymbolConfig buySellOnSignalSymbolConfig)
 {
     if (_configuresStocks != null && _configuresStocks.Any())
     {
         var stock = _configuresStocks.FirstOrDefault(s => s.IsMatchSymbol(buySellOnSignalSymbolConfig.Exchange, buySellOnSignalSymbolConfig.Symbol));
         if (stock != null)
         {
             stock.UpdateMaxLoss(buySellOnSignalSymbolConfig.MaxLoss);
         }
     }
 }
 internal void Stop(BuySellOnSignalSymbolConfig buySellOnSignalSymbolConfig)
 {
     if (_configuresStocks != null && _configuresStocks.Any())
     {
         var stock = _configuresStocks.FirstOrDefault(s => s.IsMatchSymbol(buySellOnSignalSymbolConfig.Exchange, buySellOnSignalSymbolConfig.Symbol));
         if (stock != null)
         {
             stock.CloseAllPosition(StrategyStockStatus.Stopped);
             //_configuresStocks.Remove(stock);
         }
     }
 }
        public async void UpdateCurrentProfitLoss(BuySellOnSignalSymbolConfig stock)
        {
            await Task.Factory.StartNew(() =>
            {
                int quantity = stock.NetQuantity.HasValue ?  stock.NetQuantity.Value:0;
                var pnl      = stock.CurrentProfitLoss;

                if (_configuresStocks != null && _configuresStocks.Any())
                {
                    var configuredstock = _configuresStocks.FirstOrDefault(s => s.IsMatchSymbol(stock.Exchange, stock.Symbol));
                    if (configuredstock != null)
                    {
                        if (configuredstock.CheckMaxProfitLossAndClosePosition(quantity, pnl))
                        {
                            _configuresStocks.Remove(configuredstock);
                        }
                    }
                }
            });
        }
        public void Start(BuySellOnSignalSymbolConfig stock, KiteConnect.Kite kite, SignalSettingInfo settingInfo)
        {
            var clonnedStock = stock.DeepCopy <BuySellOnSignalSymbolConfig>();

            clonnedStock.StartTime = stock.StartTime;
            var clonnedSetting = settingInfo != null?settingInfo.DeepCopy <SignalSettingInfo>() : new SignalSettingInfo();

            BuySellStockOnSignal signal = new BuySellStockOnSignal(clonnedStock, kite, clonnedSetting);

            var addedstock = _configuresStocks.FirstOrDefault(s => s.IsMatchSymbol(clonnedStock.Exchange, clonnedStock.Symbol));

            if (addedstock != null)
            {
                addedstock.Reset();
                _configuresStocks.Remove(addedstock);
            }
            _kite = kite;
            signal.Start();

            _configuresStocks.Add(signal);
        }