public void My_CexIOTest_Init()
 {
     Console.WriteLine("------ My_CexIO Unit Test N° " + numTest + "------");
     this.cexio = new My_CexIO();
     numTest++;
 }
        /// <summary>
        ///     Function that check arbitrage, one the same <paramref name="ccy1"/>
        ///     , between all handled exchanges.
        ///     It checks if there's a free opportunity to make profit, by simply sending
        ///     the crypto currency to an exchange (paying some fees), and selling it on the
        ///     other exchange.
        ///     Thus, it checks if the price + the fees are inferior to the price on the other exchange
        /// </summary>
        public bool CheckPlatformArbitrage(string ccy1)
        {
            My_Bittrex  bittrex  = new My_Bittrex();
            My_Bitfinex bitfinex = new My_Bitfinex();
            My_Binance  binance  = new My_Binance();
            My_CexIO    cexio    = new My_CexIO();
            My_Coinbase coinbase = new My_Coinbase();
            Dictionary <Exchanges, Price>  handledExchanges    = new Dictionary <Exchanges, Price>();
            Dictionary <Exchanges, double> handledExchangesUSD = new Dictionary <Exchanges, double>();
            Dictionary <Exchanges, Price>  unhandledExchanges  = new Dictionary <Exchanges, Price>();
            Dictionary <Exchanges, Price>  allPrices           = new Dictionary <Exchanges, Price>();
            Dictionary <string, double>    allUSDPrices        = new Dictionary <string, double>();
            Dictionary <string, Task>      allTasks            = new Dictionary <string, Task>();
            double fees    = 0.01;
            double bpToAct = 0.02;
            Dictionary <Exchanges, Func <string, Price> > function2invoke = new Dictionary <Exchanges, Func <string, Price> >();

            foreach (var exchange in Enum.GetNames(typeof(Exchanges)))
            {
                Exchanges goodExchange = (Exchanges)Enum.Parse(typeof(Exchanges), exchange);
                if (this.Exchange2GetPrice.ContainsKey(goodExchange))
                {
                    function2invoke.Add(goodExchange, this.Exchange2GetPrice[goodExchange]);
                    allTasks.Add(exchange, new Task(() => allPrices.Add(goodExchange, (Price)function2invoke[goodExchange].DynamicInvoke(ccy1))));
                }
            }

            foreach (Task task in allTasks.Values)
            {
                task.Start();
                System.Threading.Thread.Sleep(400);
            }

            foreach (Task task in allTasks.Values)
            {
                task.Wait();
                System.Threading.Thread.Sleep(400);
            }

            System.Threading.Thread.Sleep(500);

            foreach (Price price in allPrices.Values)
            {
                if (price.ccyPair != MainCurrency.USD.ToString() && price.ccyPair != MainCryptos.USDT.ToString())
                {
                    if (price.ccyPair == MainCryptos.BTC.ToString())
                    {
                        Exchanges goodExchange    = (Exchanges)Enum.Parse(typeof(Exchanges), price.exchange);
                        var       getprice2invoke = this.Exchange2GetPrice[goodExchange];
                        Price     BTCprice        = (Price)getprice2invoke.DynamicInvoke("BTC");
                        allUSDPrices.Add(price.exchange, price.price * BTCprice.price);
                    }
                    if (price.ccyPair == "ERROR")
                    {
                        allUSDPrices.Add(price.exchange, price.price);
                    }
                }
                else
                {
                    allUSDPrices.Add(price.exchange, price.price);
                }
            }

            foreach (var price in allPrices.Values)
            {
                if (price.error != true)
                {
                    handledExchanges.Add((Exchanges)Enum.Parse(typeof(Exchanges), price.exchange), price);
                    handledExchangesUSD.Add((Exchanges)Enum.Parse(typeof(Exchanges), price.exchange), allUSDPrices[price.exchange]);
                }
                else
                {
                    unhandledExchanges.Add((Exchanges)Enum.Parse(typeof(Exchanges), price.exchange), price);
                }
            }

            double minPrice = 10000000.00;
            double maxPrice = 0.00;

            foreach (var price in handledExchanges.Values)
            {
                minPrice = Math.Min(minPrice, price.price);
                maxPrice = Math.Max(maxPrice, price.price);
            }

            minPrice = 10000000.00;
            maxPrice = 0.00;
            foreach (var price in handledExchangesUSD.Values)
            {
                minPrice = Math.Min(minPrice, price);
                maxPrice = Math.Max(maxPrice, price);
            }

            if (maxPrice >= (1 + fees + bpToAct) * minPrice || minPrice <= (1 - fees - bpToAct) * maxPrice)
            {
                return(true);
            }
            else if (maxPrice == minPrice)
            {
                return(false);
            }
            else
            {
                return(false);
            }
        }