private bool Tradable(SnapshotPath path)
        {
            string  baseCoin;
            string  marketCoin;
            decimal minTradableVolume;
            decimal amount;

            for (int i = 0; i < path.LstStep.Count - 1; i++)
            {
                if (path.LstStep[i + 1].Action == "BUY")
                {
                    amount     = path.LstStep[i + 1].Amount;
                    baseCoin   = path.LstStep[i].Coin;
                    marketCoin = path.LstStep[i + 1].Coin;
                }
                else
                {
                    amount     = path.LstStep[i].Amount;
                    baseCoin   = path.LstStep[i + 1].Coin;
                    marketCoin = path.LstStep[i].Coin;
                }

                minTradableVolume = _lstMarket.First(x => x.QuoteCurrency.Equals(baseCoin) && x.BaseCurrency.Equals(marketCoin)).QuantityIncrement;
                if (amount < minTradableVolume)
                {
                    return(false);
                }
            }

            return(true);
        }
        private SnapshotPath GetSnapshotPath(Path path)
        {
            path.TotalVolume(path.MaxStartVolume < CurrentAmount ? path.MaxStartVolume : CurrentAmount);
            SnapshotPath snapshot = new SnapshotPath();

            foreach (Model.Step step in path.LstStep)
            {
                snapshot.LstStep.Add(new SnapshotStep()
                {
                    Action            = step.Action,
                    Amount            = step.Amount,
                    AmountWithOutFee  = step.AmountWithOutFee,
                    Coin              = step.Coin,
                    Price             = step.Price,
                    QuantityIncrement = step.QuantityIncrement
                });
            }
            return(snapshot);
        }
        public void WalkPath(Path path)
        {
            SnapshotPath snapshot = GetSnapshotPath(path);

            if (!(snapshot.Percentage > 100))
            {
                return;
            }
            if (!Tradable(snapshot))
            {
                return;
            }
            if (!snapshot.Tradable(MinTotalTrade))
            {
                return;
            }

            string      tradeHistory   = DateTime.Now.ToString("dd/MM/yyyy HH:mm:ss") + "\t";
            List <long> lstTimeElapsed = new List <long>();

            for (int i = 0; i < 5; i++)
            {
                if (snapshot.LstStep.Count > i)
                {
                    tradeHistory += snapshot.LstStep[i].Coin + "\t";
                }
                else
                {
                    tradeHistory += "\t";
                }
            }

            tradeHistory += snapshot.Percentage.ToString("0.#####") + "\t" + snapshot.StartVolume.ToString("0.########") + "\t" + snapshot.FinalVolume.ToString("0.########") + "\t";

            Stopwatch watch      = new Stopwatch();
            Stopwatch watchTrade = new Stopwatch();

            Console.WriteLine();
            Console.BackgroundColor = ConsoleColor.DarkCyan;
            Console.WriteLine("Path Selected: " + snapshot.ToString());
            Console.ResetColor();
            Console.WriteLine("Starting PATH...");
            for (int i = 0; i < snapshot.LstStep.Count - 1; i++)
            {
                watch.Restart();
                string output = (i + 1) + ")  ";
                output += (snapshot.LstStep[i].Coin + (snapshot.LstStep[i + 1].Action == "BUY" ? "-->" : "<--") + snapshot.LstStep[i + 1].Coin).PadRight(20);
                output += ("Amount: " + (snapshot.LstStep[i + 1].Action == "BUY" ? (snapshot.LstStep[i + 1].AmountWithOutFee.ToString("0.######") + snapshot.LstStep[i + 1].Coin) : (snapshot.LstStep[i].Amount.ToString("0.######")) + snapshot.LstStep[i].Coin)).PadRight(25);
                output += ("Price: " + snapshot.LstStep[i + 1].Price.ToString("0.######") + (snapshot.LstStep[i + 1].Action == "BUY" ? snapshot.LstStep[i].Coin : snapshot.LstStep[i + 1].Coin)).PadRight(25);
                output += "Total: " + (snapshot.LstStep[i + 1].Action == "BUY" ? (snapshot.LstStep[i].Amount.ToString("0.######") + snapshot.LstStep[i].Coin) : (snapshot.LstStep[i + 1].Amount.ToString("0.######") + snapshot.LstStep[i + 1].Coin));

                Console.WriteLine(output);
                HitOrder trade = null;
                watchTrade.Restart();
                trade = DoTrade(snapshot.LstStep[i], snapshot.LstStep[i + 1]);
                watchTrade.Stop();
                lstTimeElapsed.Add(watchTrade.ElapsedMilliseconds);

                HitOrder openOrder = null;
                bool     isFilled  = false;
                try
                {
                    do
                    {
                        HitResponse <HitOrder> resultOpenOrder;

                        if (trade.Status == HitOrderStatus.Filled)
                        {
                            isFilled = true;
                            Console.WriteLine("ALL bought/selled");
                            continue;
                        }

                        else
                        {
                            resultOpenOrder = _hitbtcRestClient.GetActiveOrderByClientIdAsync(trade.ClientOrderId).Result;
                            openOrder       = resultOpenOrder.Result;

                            if (resultOpenOrder.Result == null || openOrder.Status == HitOrderStatus.Filled)
                            {
                                isFilled = true;
                                Console.WriteLine("ALL bought/selled");
                                continue;
                            }

                            Console.WriteLine(" Exchange: " + openOrder.Symbol + " OrderType: " + openOrder.OrderType + " isOpen: " + openOrder.Status);

                            System.Threading.Thread.Sleep(200);
                        }

                        if (watch.ElapsedMilliseconds > _waitingTime)
                        {
                            //  Reset();
                            tradeHistory += "NO" + "\t";
                            tradeHistory += UpdatedAmount + "\t";

                            foreach (var time in lstTimeElapsed)
                            {
                                tradeHistory += time + "\t";
                            }
                            tradeHistory += "\r\n";

                            using (StreamWriter writetext = File.AppendText("C:\\log\\tradehistory.txt"))
                            {
                                writetext.Write(tradeHistory);
                                writetext.Close();
                            }
                            return;
                        }
                    } while (!isFilled);
                }
                catch (Exception e)
                {
                    Console.WriteLine("Eccezione while: " + e.ToString());

                    // Reset();
                    tradeHistory += "NO" + "\t";
                    tradeHistory += UpdatedAmount + "\t";

                    foreach (var time in lstTimeElapsed)
                    {
                        tradeHistory += time + "\t";
                    }
                    tradeHistory += "\r\n";

                    using (StreamWriter writetext = File.AppendText("C:\\log\\tradehistory.txt"))
                    {
                        writetext.Write(tradeHistory);
                        writetext.Close();
                    }
                    return;
                }
            }
            //  Reset();
            tradeHistory += "SI" + "\t";
            tradeHistory += UpdatedAmount + "\t";

            foreach (var time in lstTimeElapsed)
            {
                tradeHistory += time + "\t";
            }
            tradeHistory += "\r\n";

            using (StreamWriter writetext = File.AppendText("C:\\log\\tradehistory.txt"))
            {
                writetext.Write(tradeHistory);
                writetext.Close();
            }
        }