public List <TradeInfo> GetTradesList(string symbol, string exchange)
        {
            ConcurrentDictionary <string, List <TradeInfo> > symbolTrades;

            if (!Trades.TryGetValue(symbol, out symbolTrades))
            {
                symbolTrades   = new ConcurrentDictionary <string, List <TradeInfo> >();
                Trades[symbol] = symbolTrades;
            }

            List <TradeInfo> agrTrades;

            if (!symbolTrades.TryGetValue(exchange, out agrTrades))
            {
                agrTrades = new List <TradeInfo>();
                symbolTrades[exchange] = agrTrades;
            }
            return(agrTrades);
        }
        public void GetTradesListFiltered(string symbol, string exchange, out List <TradeInfo> agrTradesCut, out List <TradeInfo> TradesCutCheck, out List <TradeInfo> TradesCutPrediction)
        {
            float advanceMargin = Parameters.ArbPercentForAdvancePreopting;

            agrTradesCut        = new List <TradeInfo>();
            TradesCutCheck      = new List <TradeInfo>();
            TradesCutPrediction = new List <TradeInfo>();

            ConcurrentDictionary <string, List <TradeInfo> > symbolTrades;

            if (!Trades.TryGetValue(symbol, out symbolTrades))
            {
                return;
            }

            List <TradeInfo> agrTrades;

            if (!symbolTrades.TryGetValue(exchange, out agrTrades))
            {
                return;
            }

            var   agrValue        = agrTrades.Select(trade => trade.OpenSlip).Distinct().OrderBy(v => v).ToArray();
            var   maxLength       = agrValue.Length;
            float arbCount        = agrTrades.Sum(trade => trade.isArbitrage ? 1 : 0);
            var   openSlipMargins = new List <string>();
            var   corFil          = new float[maxLength, 6];

            for (int i = 0; i < maxLength; i++)
            {
                corFil[i, 0] = agrValue[i];
                for (int tradeIndex = 0; tradeIndex < agrTrades.Count; tradeIndex++)
                {
                    if (agrTrades[tradeIndex].OpenSlip == corFil[i, 0])
                    {
                        if (agrTrades[tradeIndex].isArbitrage)
                        {
                            corFil[i, 1]++;
                        }

                        corFil[i, 3]++;
                    }
                }

                if (i > 0)
                {
                    corFil[i, 2] = corFil[i - 1, 2] + corFil[i, 1];
                    corFil[i, 4] = corFil[i - 1, 4] + corFil[i, 3];
                }
                else
                {
                    corFil[i, 2] = corFil[i, 1];
                    corFil[i, 4] = corFil[i, 3];
                }

                if (i == maxLength - 1)
                {
                    corFil[i, 5] = 0;
                    openSlipMargins.Add(symbol + "\t" + exchange + "\t" + Convert.ToString(corFil[i, 0]) + "\t" + Convert.ToString(corFil[i, 5]));
                }
                else
                {
                    corFil[i, 5] = 1 - corFil[i, 2] / corFil[i, 4];
                    openSlipMargins.Add(symbol + "\t" + exchange + "\t" + Convert.ToString(corFil[i, 0]) + "\t" + Convert.ToString(corFil[i, 5]));
                }
            }

            Parameters.MinAdvance       = corFil[0, 0] - 1;
            Parameters.MinAdvanceGlobal = corFil[0, 0] - 1;

            for (int i = maxLength - 1; i >= 0; i--)
            {
                if (corFil[i, 5] >= advanceMargin)
                {
                    Parameters.MinAdvance = corFil[i, 0];
                    break;
                }
            }

            if (Parameters.MinAdvance > -1)
            {
                Parameters.MinAdvance = -1;                            //openSlipetch protect
            }
            var tempIndexes = new int[agrTrades.Count];
            int counter     = -1;

            for (int i = 0; i < agrTrades.Count; i++)
            {
                if (agrTrades[i].OpenSlip > Parameters.MinAdvance)
                {
                    counter++;
                    tempIndexes[counter] = i;
                }
            }

            var indexes = new int[counter + 1];

            for (int i = 0; i < indexes.Length; i++)
            {
                indexes[i] = tempIndexes[i];
            }


            Parameters.CountOfVariable = steps.Length - 1;
            Dictionary <DateTime, List <int> > StDev = new Dictionary <DateTime, List <int> >();

            for (int i = 0; i < (int)Math.Round(Parameters.PercentOfOptLog * indexes.Length); i++)
            {
                agrTradesCut.Add(agrTrades[indexes[i]]);
                DateTime currentLogDay = new DateTime();
                currentLogDay = agrTrades[indexes[i]].openDate.Date;
                if (!StDev.ContainsKey(currentLogDay))
                {
                    StDev.Add(currentLogDay, new List <int>());
                }
            }

            for (int i = (int)Math.Round(Parameters.PercentOfOptLog * indexes.Length); i < (int)Math.Round((Parameters.PercentOfOptLog + Parameters.PercentOfCheckLog) * indexes.Length); i++)
            {
                TradesCutCheck.Add(agrTrades[indexes[i]]);
                DateTime currentLogDay = new DateTime();
                currentLogDay = agrTrades[indexes[i]].openDate.Date;
                if (!StDev.ContainsKey(currentLogDay))
                {
                    StDev.Add(currentLogDay, new List <int>());
                }
            }
            Parameters.daysCount = StDev.Count;
            for (int i = (int)Math.Round((Parameters.PercentOfOptLog + Parameters.PercentOfCheckLog) * indexes.Length); i < indexes.Length; i++)
            {
                TradesCutPrediction.Add(agrTrades[indexes[i]]);
                DateTime currentLogDay = new DateTime();
                currentLogDay = agrTrades[indexes[i]].openDate.Date;
                if (!StDev.ContainsKey(currentLogDay))
                {
                    StDev.Add(currentLogDay, new List <int>());
                }
            }
            openSlipMargins.Add(Convert.ToString(Parameters.MinAdvance));
            string path = Directory.GetCurrentDirectory();

            System.IO.File.AppendAllLines(path + "/Recomends/Preopting.txt", openSlipMargins);
        }