Ejemplo n.º 1
0
        public BotViewModel GetLatestArranged()
        {
            try
            {
                var viewModel = new BotViewModel();

                var lastFolder = _directoryManager.GetLastFolder(DirSwitcher.BotForecast);
                var results    = _directoryManager.GetListByBotArrange(lastFolder);
                viewModel.Buy      = results.BuyAssets;
                viewModel.Consider = results.ConsiderAssets;
                viewModel.DontBuy  = results.DontBuyAssets;
                viewModel.Report   = _directoryManager.GetArrangeBotReport(lastFolder);
                return(viewModel);
            }
            catch (Exception e)
            {
                throw new Exception(e.Message);
            }
        }
Ejemplo n.º 2
0
        public async Task <BotViewModel> MakeBotForecast(int rsi, List <int> trend, List <int> border)
        {
            var viewModel = new BotViewModel();

            if (trend.Count <= 0)
            {
                throw new Exception("Select at least one trend option!");
            }

            if (border.Count <= 0)
            {
                throw new Exception("Select at least one border option!");
            }

            const int periods   = 24;
            const int dataHours = 230;

            IEnumerable <string> assets;
            string lastFolder;

            try
            {
                //assets = _fileManager.ReadAssetsFromExcel(_directoryManager.AsstesLocation);
                assets = _fileManager.ReadAssetsFromExcel(_directoryManager.ObservablesLocation);
                var currentTime = DateTime.Now;
                Parallel.ForEach(assets, asset =>
                {
                    var pathToFolder =
                        _directoryManager.GenerateForecastFolder(asset, periods, DirSwitcher.BotForecast,
                                                                 currentTime);

                    var normalized = _processModel.GetDataAuto(asset, dataHours);
                    if (normalized == null || !normalized.Any())
                    {
                        _directoryManager.RemoveFolder(pathToFolder);
                        var zeroResults = new ExcelBotArrangeLog()
                        {
                            AssetName  = asset,
                            Log        = Indicator.ZeroRezults.ToString(),
                            Rate       = "1",
                            Width      = "0",
                            Volume     = "0",
                            Change     = "0",
                            Rsi        = "0",
                            BotArrange = BotArrange.DontBuy.ToString()
                        };
                        Shared.ArrangeBotLog(zeroResults);
                        return;
                    }

                    var csv = _fileManager.CreateDataCsv(normalized, pathToFolder);
                    if (string.IsNullOrEmpty(csv))
                    {
                        var zeroResults = new ExcelBotArrangeLog()
                        {
                            AssetName  = asset,
                            Log        = Indicator.ZeroRezults.ToString(),
                            Rate       = "1",
                            Width      = "0",
                            Volume     = "0",
                            Change     = "0",
                            Rsi        = "0",
                            BotArrange = BotArrange.DontBuy.ToString()
                        };
                        Shared.ArrangeBotLog(zeroResults);
                        return;
                    }

                    _directoryManager.SaveDataFile(csv, pathToFolder);

                    _pythonExec.RunPython(pathToFolder, periods, false, false);

                    var pathToOut        = _directoryManager.FilePathOut(pathToFolder);
                    var pathToComponents = _directoryManager.FileComponentsOut(pathToFolder);
                    var pathToForecast   = _directoryManager.FileForecastOut(pathToFolder);

                    var outCreated        = _directoryManager.WaitForFile(pathToOut, 60);
                    var componentsCreated = _directoryManager.WaitForFile(pathToComponents, 10);
                    var forecastCreated   = _directoryManager.WaitForFile(pathToForecast, 10);

                    if (!outCreated.Result || !forecastCreated.Result || !componentsCreated.Result)
                    {
                        return;
                    }

                    var stats          = _fileManager.BuildOutTableRows(pathToOut, periods);
                    var performance    = _utility.DefinePerformance(stats);
                    var marketFeatures = _utility.GetFeatures(normalized, asset);
                    var rsiCalculated  = _utility.Rsi(normalized);

                    var botArrange = _directoryManager.SpecifyDirByIndicators(pathToFolder, rsi, trend, border,
                                                                              performance, rsiCalculated);
                    var log = new ExcelBotArrangeLog()
                    {
                        AssetName  = asset,
                        Log        = performance.Indicator.ToString(),
                        Rate       = performance.Rate.ToString(),
                        Width      = performance.Width.ToString(),
                        Volume     = marketFeatures.Volume.ToString() + "BTC",
                        Change     = marketFeatures.Change.ToString("N2"),
                        Rsi        = rsiCalculated.ToString("N2") + "%",
                        BotArrange = botArrange.ToString()
                    };
                    Shared.ArrangeBotLog(log);
                }
                                 );

                lastFolder = _directoryManager.GetLastFolder(DirSwitcher.BotForecast);
                var results = _directoryManager.GetListByBotArrange(lastFolder);
                viewModel.Buy      = results.BuyAssets;
                viewModel.Consider = results.ConsiderAssets;
                viewModel.DontBuy  = results.DontBuyAssets;

                var res = _fileManager.WriteArrangeBotLogExcel(lastFolder, Shared.GetArrangedBotLog);
                _directoryManager.WriteArrangeBotLogToExcel(lastFolder, res);
                Shared.ClearArrangeBotLog();
                viewModel.Report = _directoryManager.GetArrangeBotReport(lastFolder);

                var requests = _requestHelper.GetStats();
                viewModel.CallsMadeHisto = requests.CallsMade.Histo;
                viewModel.CallsLeftHisto = requests.CallsLeft.Histo;
                return(viewModel);
            }
            catch (Exception e)
            {
                lastFolder = _directoryManager.GetLastFolder(DirSwitcher.BotForecast);
                if (Shared.GetArrangedBotLog.Any())
                {
                    var res = _fileManager.WriteLogExcel(lastFolder, Shared.GetArrangedBotLog);
                    _directoryManager.WriteLogToExcel(lastFolder, res);
                    Shared.ClearArrangeBotLog();
                }

                throw new Exception(e.Message);
            }
        }