private async void CheckGlobalProfitLoss()
        {
            await Task.Factory.StartNew(() =>
            {
                if (DayMaxLoss != 0 && DayMaxProfit != 0)
                {
                    var shouldClosePosition    = false;
                    StrategyStockStatus status = StrategyStockStatus.Added;
                    if (CurrentProfitLoss > 0 && CurrentProfitLoss >= DayMaxProfit)
                    {
                        shouldClosePosition = true;
                        status = StrategyStockStatus.DayProfitReached;
                    }
                    else if (CurrentProfitLoss < 0 && Math.Abs(CurrentProfitLoss) >= DayMaxLoss)
                    {
                        shouldClosePosition = true;
                        status = StrategyStockStatus.DayLossReached;
                    }

                    if (shouldClosePosition)
                    {
                        _configuresStocks.ForEach(s => s.CloseAllPosition(status));
                    }
                }
            });
        }
        public void CloseAllPosition(StrategyStockStatus status)
        {
            try
            {
                if (_oldOrderMode.HasValue && _currentOpenPosition != 0)
                {
                    _kite.PlaceOrder(_config.Exchange, _config.Symbol, _oldOrderMode.Value == OrderMode.BUY ? OrderMode.SELL.ToString() : OrderMode.BUY.ToString(), Convert.ToInt32(Math.Abs(_currentOpenPosition)), Product: "MIS", OrderType: "MARKET");
                }
            }
            catch (Exception)
            {
            }

            fileWather.EnableRaisingEvents            = false;
            fileWather.Changed                       -= FileWather_Changed;
            _currentOpenPosition                      = 0;
            _countOfContiniousExecutionInOneDirection = 0;
            _oldOrderMode = null;
            Events.RaiseStatusChangedEvent(_config.Exchange, _config.Symbol, status.ToString());
        }
Esempio n. 3
0
        private void Events_StatusChangedEvent(string exchange, string symbol, string status)
        {
            StrategyStockStatus strategyStatus = StrategyStockStatus.Added;

            if (BuySellOnSignalSymbolConfigs == null)
            {
                return;
            }
            var stock = BuySellOnSignalSymbolConfigs.FirstOrDefault(s => s.Exchange == exchange && symbol == s.Symbol);

            if (BuySellOnSignalSymbolConfigs != null && Enum.TryParse(status, out strategyStatus))
            {
                if (stock != null)
                {
                    stock.Status = strategyStatus;
                }
            }
            else if (stock != null)
            {
                stock.DebugStatus = status;
            }
        }