Example #1
0
        public Statistics StartBackTest(DateTime startTime, DateTime stopTime, double depositAsset, double depositQuote)
        {
            logService.CreateLogFile("backtest");
            logService.Write("***********Нажата кнопка старт***********", true);

            SetConfifuration();
            tradeConfiguration.GeneralSetting.StartTime    = TimeZoneInfo.ConvertTimeToUtc(startTime).ToUnixTime();
            tradeConfiguration.GeneralSetting.StopTime     = TimeZoneInfo.ConvertTimeToUtc(stopTime).ToUnixTime();
            tradeConfiguration.GeneralSetting.DepositAsset = depositAsset;
            tradeConfiguration.GeneralSetting.DepositQuote = depositQuote;

            var startTradeId = tradeHistoryRepository.MinId(tradeConfiguration.GeneralSetting.StartTime);
            var stopTradeId  = tradeHistoryRepository.MaxId(tradeConfiguration.GeneralSetting.StopTime);

            logService.Write($"startTradeId: {startTradeId} stopTradeId: {stopTradeId}");

            isReload            = false;
            IsActiveAlgoritm    = false;
            IsActiveCalculating = true;
            if (startTradeId > 0 && stopTradeId > 0)
            {
                var firstPrice = GetTades(simbol, startTradeId, startTradeId).FirstOrDefault()?.Price ?? 0;
                tradeConfiguration.GeneralSetting.SetDeposit(firstPrice);

                var amountElementsGet = 100000L;
                for (long i = startTradeId; i < stopTradeId; i += amountElementsGet)
                {
                    var stopI  = i + amountElementsGet;
                    var trades = GetTades(simbol, i, stopI <= stopTradeId ? stopI : stopTradeId);

                    foreach (var trade in trades) // запуск теста. проходим по сделкам
                    {
                        if (!IsActiveAlgoritm)
                        {
                            StartAlgoritm(trade.Price);
                        }
                        else
                        {
                            CurrentTrades_LastPriceEvent(trade.Price);
                        }

                        long x = 10000;
                        if (trade.TradeId % x == 0)
                        {
                            logService.Write($"***********************************\n************************* {trade.TradeId} ************************\n*******************************************************", true);
                        }

                        if (!IsActiveAlgoritm)
                        {
                            logService.Write("***********TEST END** ERROR *********", true);
                            return(null);
                        }
                        if (!IsActiveCalculating)
                        {
                            logService.Write("***********TEST END** Остановлено пользователем *********", true);
                            return(null);
                        }
                    }
                }
            }

            var statistics = new Statistics(positionRepository.Get().ToList(), tradeConfiguration.GeneralSetting.Deposit);

            statistics.CalcStatistics();

            logService.Write("***********TEST END***********", true);
            return(statistics);
        }
Example #2
0
 public void RequestedBalances()
 {
     logService.Write("***********RequestedBalances START***********", true);
     try
     {
         keys = keyRepo.Get()?.ToList();
         if (keys != null)
         {
             logService.Write("\tRequestedBalances get keys successful.");
             foreach (var key in keys)
             {
                 logService.Write($"\tPublic key: {key.PublicKey}");
                 var account = Account(key.PublicKey, key.SecretKey);
                 if (account != null)
                 {
                     logService.Write("\tRequestedBalances get account successful.");
                     if (account.Balances != null)
                     {
                         logService.Write("\tRequestedBalances get Balances successful.");
                         foreach (var balance in account.Balances)
                         {
                             SaveBalance(balance, key.PublicKey);
                         }
                     }
                 }
             }
         }
     }
     catch (Exception ex)
     {
         logService.Write($"RequestedBalances error: Exception: {ex.Message} Innerexception: {ex.InnerException?.Message}", true);
     }
     logService.Write("***********RequestedBalances END***********", true);
 }
Example #3
0
 public void RequestedTrades()
 {
     logService.Write("***********RequestedTrades START***********", true);
     try
     {
         keys           = keyRepo.Get()?.ToList();
         configurations = configRepository.GetActive()?.ToList();
         if (keys != null)
         {
             logService.Write("\tRequestedTrades get keys successful.");
             foreach (var key in keys)
             {
                 logService.Write($"\tPublic key: {key.PublicKey}");
                 if (configurations != null)
                 {
                     foreach (var configuration in configurations)
                     {
                         RequestedTrades(key.PublicKey, key.SecretKey, $"{configuration.MainCoin}{configuration.AltCoin}");
                     }
                 }
             }
         }
     }
     catch (Exception ex)
     {
         logService.Write($"RequestedTrades error: Exception: {ex.Message} Innerexception: {ex.InnerException?.Message}", true);
     }
     logService.Write("***********RequestedTrades END***********", true);
 }