예제 #1
0
        // call by StartTradePackage()
        public void SetArbitrageSymbolsDate()
        {
            ExchangeOrderBook book = api.GetOrderBook(arbitrageSymbol, StaticVariables.maxCount);

            FindingSymbolsTrading.GetPrice(book, arbitrageSymbolsDate, true);
            FindingSymbolsTrading.GetPrice(book, arbitrageSymbolsDate, false);
            arbitrageSymbolsDate.ItsBuy = itsBuyArbitrage;
            arbitrageSymbolsDate.orderTrade.request.api = StaticVariables.api;
            arbitrageSymbolsDate.orderTrade.request.ShouldRoundAmount = true;

            if (itsBuyArbitrage)
            {
                arbitrageSymbolsDate.orderTrade.request.Amount = AmountTrade * buySymbolsDate.orderTrade.request.Price;
            }
            else
            {
                arbitrageSymbolsDate.orderTrade.request.Amount = AmountTrade * sellSymbolsDate.orderTrade.request.Price;
            }

            if (arbitrageSymbolsDate.orderTrade.request.Amount < arbitrageSymbolsDate.MinAmount)
            {
                arbitrageSymbolsDate.orderTrade.request.Amount = arbitrageSymbolsDate.MinAmount;
            }
        }
예제 #2
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
            }
        }