Пример #1
0
        public static void AddMagicNumberTable(Dictionary <string, MagicNumber> magicNumberList)
        {
            List <MagicNumber> magicNumbers = new List <MagicNumber>();

            foreach (var item in magicNumberList)
            {
                magicNumbers.Add(item.Value);
            }
            SqlMagicNumber.AddAllInstance(magicNumbers);
        }
Пример #2
0
        public static void Start()
        {
            List <MagicNumber> buyWaitingTime  = GetBuyWaitingTimeList();
            List <MagicNumber> sellWaitingTime = GetSellWaitingTimeList();

            int buyNewMagicWaiting  = SetBuyWaitingTime(buyWaitingTime);
            int sellNewMagicWaiting = SetSellWaitingTime(sellWaitingTime);

            bool buyResult  = (buyNewMagicWaiting == StaticVariables.startBuyMagicWaiting);
            bool sellResult = (sellNewMagicWaiting == StaticVariables.startSellMagicWaiting);

            if (buyResult & sellResult)
            {
                return;
            }

            List <MagicNumber> magicNumbersToUpdate = new List <MagicNumber>();

            foreach (var item in StaticVariables.magicNumberList)
            {
                if (item.Value.Buy.IsArbitrageSymbol == false) // We will only update symbols that are not used for arbitrage
                {
                    if (item.Value.Buy.NumSuccess == 0)        // We will only update symbols that have not been valued by trading in the past
                    {
                        item.Value.Buy.WaitingTimeForNextPriceUpdate = buyNewMagicWaiting;
                        magicNumbersToUpdate.Add(item.Value);
                    }

                    if (item.Value.Sell.NumSuccess == 0 & item.Value.Sell.NumUnSuccess == 0)    // We will only update symbols that have not been valued by trading in the past
                    {
                        item.Value.Sell.WaitingTimeForNextPriceUpdate = sellNewMagicWaiting;
                        magicNumbersToUpdate.Add(item.Value);
                    }
                }
            }

            if (magicNumbersToUpdate.Count > 0)
            {
                magicNumbersToUpdate = magicNumbersToUpdate.Distinct().ToList();
                SqlMagicNumber.UpdateAll(magicNumbersToUpdate);
            }

            StaticVariables.startBuyMagicWaiting  = buyNewMagicWaiting;
            StaticVariables.startSellMagicWaiting = sellNewMagicWaiting;
        }
Пример #3
0
        public static Dictionary <string, MagicNumber> GetMagicNumberTable()
        {
            Dictionary <string, MagicNumber> magicNumberList = new Dictionary <string, MagicNumber>();
            List <MagicNumber> magicNumbers = new List <MagicNumber>();

            magicNumbers = SqlMagicNumber.GetAll();
            foreach (var item in magicNumbers)
            {
                magicNumberList.Add(item.Symbol, item);
            }

            if (magicNumberList.Count > 0)
            {
                WaitingTimeML.Start();      // USE to ML_4
            }

            return(magicNumberList);
        }
Пример #4
0
        public static void FindAndTrade(bool trade)
        {
            StaticVariables.Wallet = WalletFunc.GetWallet();
#if DEBUG
            PrintDataDebug();
#endif

            DateTime currentTime;
            string   timeHouer;
            string   pathSummaryFind;
            int      numFind = 0;

            while (true)
            {
                numFind++;
                currentTime = DateTime.Now;
                List <OrderHandling> packageList = new List <OrderHandling>();

                int  i = 0;
                bool tradeSuccses;
                List <MagicNumber> magicNumbersToUpdate = new List <MagicNumber>();
                foreach (var item in StaticVariables.symbolsDateList)
                {
                    if (i % 5 == 0)
                    {
                        WalletFunc.ConversionPayment();
                    }
                    i++;

                    tradeSuccses = false;
                    do
                    {
                        OrderHandling package;
                        try
                        {
                            package = FindingSymbolsTrading.ArbitragePercent(item.Key, item.Value);
                        }
                        catch (Exception ex)
                        {
                            package = null;
                            DateTime localDate   = DateTime.Now;
                            string   printResult = String.Format("{0}\n{1}", localDate.ToString(), ex.ToString());
                            printResult += String.Format("\ncurrency - {0}", item.Key);
                            PrintException.Start(MethodBase.GetCurrentMethod().Name, printResult);
                        }

                        if (package != null)
                        {
                            packageList.Add(package);
                            PrintTable.Start(StaticVariables.pathFindFile + item.Key + ".csv", package.ToString(), "Trade_package");

                            // TODO Add Func TradeFast

                            List <MagicNumber> magicNumbersTradeMagicToUpdate = new List <MagicNumber>();
                            if (package.percentPotential > StaticVariables.revnuTrade)
                            {
                                if (StaticVariables.rateGateLimit)
                                {
                                    StaticVariables.api.RateLimit.OneOpportunity = true;
                                }

                                try
                                {
                                    if (package.StartTradePackageMagic())
                                    {
                                        tradeSuccses = TradeMagic.Start(package);
                                    }
                                }
                                catch (Exception ex)
                                {
                                    StaticVariables.Wallet = WalletFunc.GetWallet();  // Wallet update. Because part of the trade was carried out. Apparently the amounts of coins have changed

                                    DateTime localDate   = DateTime.Now;
                                    string   printResult = String.Format("{0}\n{1}", localDate.ToString(), ex.ToString());
                                    PrintException.Start(MethodBase.GetCurrentMethod().Name, printResult);
                                    try
                                    {
                                        PrintTable.Start(StaticVariables.pathWithDate + "Exception_TradeMagic_" + item.Key + ".csv", package.Buy.ToString(), "OrderTrade");
                                        PrintTable.Start(StaticVariables.pathWithDate + "Exception_TradeMagic_" + item.Key + ".csv", package.Sell.ToString(), "OrderTrade");
                                        PrintTable.Start(StaticVariables.pathWithDate + "Exception_TradeMagic_" + item.Key + ".csv", package.Arbitrage.ToString(), "OrderTrade");
                                    }
                                    catch (Exception)
                                    {
                                        PrintTable.Start(StaticVariables.pathWithDate + "Exception_TradeMagic_Exception_" + item.Key + ".csv", package.ToString(), "Trade_package");
                                    }
                                }

                                if (StaticVariables.rateGateLimit)
                                {
                                    StaticVariables.api.RateLimit.OneOpportunity = false;
                                }

                                magicNumbersTradeMagicToUpdate.Add(package.buySymbolsDate.magicNumber);
                                magicNumbersTradeMagicToUpdate.Add(package.sellSymbolsDate.magicNumber);
                                magicNumbersTradeMagicToUpdate.Add(package.arbitrageSymbolsDate.magicNumber);
                                SqlMagicNumber.UpdateAll(magicNumbersTradeMagicToUpdate);
                            }
                            else
                            {
                                magicNumbersToUpdate.Add(package.buySymbolsDate.magicNumber);
                            }
                        }
                    } while (tradeSuccses);
                }

                SqlMagicNumber.UpdateAll(magicNumbersToUpdate);
                WaitingTimeML.Start();      // USE to ML_4
                timeHouer = String.Format("{0}-{1}-{2}", currentTime.Hour, currentTime.Minute, currentTime.Second);
                PrintTable.PrintConsole(timeHouer + "\t" + numFind);
                pathSummaryFind = StaticVariables.pathSummaryFind + "SummaryFind_" + timeHouer + ".csv";
                foreach (var item in packageList)
                {
                    PrintTable.Start(pathSummaryFind, item.ToString(), "Trade_package");
                    if (item.percent > StaticVariables.revnuTrade || item.percentPotential > StaticVariables.revnuTrade)
                    {
                        PrintTable.PrintConsole(item.ToConsole());
                        PrintTable.Start(StaticVariables.pathWithDate + "SummaryFind" + ".csv", item.ToString(), "Trade_package");
                    }
                }

#if DEBUG
                PrintFunc.PrintDictionary(StaticVariables.magicNumberList, nameof(StaticVariables.magicNumberList), StaticVariables.pathDataDebug);
#endif
            }
        }