コード例 #1
0
ファイル: WhenAnalysingIndeces.cs プロジェクト: nelly2k/bot
        public void Long_Macd_FFalls_SDontCare_RSI_High_Price_Falling_Sell()
        {
            var dt    = new DateTime(2017, 10, 10);
            var trade = new BaseTrade()
            {
                DateTime = dt.AddMinutes(1)
            };
            var macd_fast = new MacdAnalysisResult()
            {
                CrossType = CrossType.MacdFalls,
                Trade     = trade
            };

            var rsi = new PeakAnalysisResult()
            {
                ExitTrade = trade,
                PeakType  = PeakType.High
            };


            var macdSlowStatus = TradeStatus.Buy;

            var result = AnalysisExtensions.AnalyseIndeces(30, dt, macd_fast, rsi, macdSlowStatus);

            Assert.That(result, Is.EqualTo(PriceStatus.GoingFall));
        }
コード例 #2
0
ファイル: WhenAnalysingIndeces.cs プロジェクト: nelly2k/bot
        public void Long_Macd_FRises_SBuy_RSI_Low_Price_Rises_Buy()
        {
            var dt    = new DateTime(2017, 10, 10);
            var trade = new BaseTrade()
            {
                DateTime = dt.AddMinutes(1)
            };
            var macd_fast = new MacdAnalysisResult()
            {
                CrossType = CrossType.MacdRises,
                Trade     = trade
            };

            var rsi = new PeakAnalysisResult()
            {
                ExitTrade = trade,
                PeakType  = PeakType.Low
            };


            var macdSlowStatus = TradeStatus.Buy;

            var result = AnalysisExtensions.AnalyseIndeces(30, dt, macd_fast, rsi, macdSlowStatus);

            Assert.That(result, Is.EqualTo(PriceStatus.GoinRaise));
        }
コード例 #3
0
        //TODO: allow generics
        void CreateFunc()
        {
            Func <object, CancellationToken, object> rule = null;

            try
            {
                if (string.IsNullOrEmpty(funcName))
                {
                    throw new InvalidOperationException("Rule extension does not specify a func " + GetErrSource());
                }

                int dotIdx = funcName.LastIndexOf('.');
                if (dotIdx <= 0)
                {
                    throw new InvalidOperationException("Rule func name ' " + funcName + " 'is invalid " + GetErrSource());
                }

                string typeName = funcName.Substring(0, dotIdx);
                var    type     = this.Addin.GetType(typeName, true);

                var inputType  = AnalysisExtensions.GetType(Input);
                var outputType = AnalysisExtensions.GetType(Output);

                string methodName = funcName.Substring(dotIdx + 1);
                var    methodInfo = type.GetMethod(methodName,
                                                   BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic,
                                                   Type.DefaultBinder, new Type[] { inputType, typeof(CancellationToken) },
                                                   new ParameterModifier [] { new ParameterModifier() });

                if (methodInfo == null)
                {
                    throw new InvalidOperationException("Rule func ' " + funcName + "' could not be resolved " + GetErrSource());
                }

                if (methodInfo.ReturnType != outputType)
                {
                    throw new InvalidOperationException("Rule func ' " + funcName + "' has wrong output type " + GetErrSource());
                }

                var wrapper = new DynamicMethod(methodName + "_obj" + (dynamicMethodKey++),
                                                typeof(object), new Type[] { typeof(object), typeof(CancellationToken) }, true);

                var il = wrapper.GetILGenerator();
                il.Emit(OpCodes.Ldarg_0);
                il.Emit(OpCodes.Castclass, inputType);
                il.Emit(OpCodes.Ldarg_1);
                il.Emit((methodInfo.IsFinal || !methodInfo.IsVirtual) ? OpCodes.Call : OpCodes.Callvirt, methodInfo);
                il.Emit(OpCodes.Ret);

                rule = (Func <object, CancellationToken, object>)wrapper.CreateDelegate(typeof(Func <object, CancellationToken, object>));
            }
            finally
            {
                cachedInstance = rule ?? NullRule;
            }
        }
コード例 #4
0
ファイル: SurfaceDataTests.cs プロジェクト: zeusongit/Dynamo
        public void AnalysisExtensionsIsAlmostEqualToTest()
        {
            //Arrange
            //Define two UV coordinates that are extremely close
            var UVCoord1 = UV.ByCoordinates(0.0000005, 0.0000005);
            var UVCoord2 = UV.ByCoordinates(0.0000004, 0.0000004);

            //Act
            var boolResult = AnalysisExtensions.IsAlmostEqualTo(UVCoord1, UVCoord2);

            //Assert
            //If is true means that the coordinates are almost equal
            Assert.IsTrue(boolResult);
        }
コード例 #5
0
        public TradeStatus FindStatusFromTrades(List <IDateCost> groupedTrades, List <IDateCost> groupedTradesSlow, string pair)
        {
            var macd         = groupedTrades.Macd(_config[pair].MacdSlow, _config[pair].MacdFast, _config[pair].MacdSignal);
            var macdAnalysis = macd.MacdAnalysis();

            _fileService.GatherDetails(pair, FileSessionNames.MACD_Fast_Value, macdAnalysis.Trade.Price);

            if (macdAnalysis.Trade is BaseTrade macdTrade)
            {
                _fileService.GatherDetails(pair, FileSessionNames.MACD_Fast_Signal, macdTrade.Volume);
            }

            _fileService.GatherDetails(pair, FileSessionNames.MACD_Fast_Minutes, (_dateTime.Now - macdAnalysis.Trade.DateTime).TotalMinutes);
            _fileService.GatherDetails(pair, FileSessionNames.MACD_Fast_Decision, macdAnalysis.CrossType == CrossType.MacdFalls ? "sell" : "buy");


            var rsiLastPeak = groupedTrades.RelativeStrengthIndex(_config[pair].RsiEmaPeriods)
                              .GetPeaks(_config[pair].RsiLow, _config[pair].RsiHigh).OrderByDescending(x => x.PeakTrade.DateTime)
                              .FirstOrDefault();

            if (rsiLastPeak != null)
            {
                _fileService.GatherDetails(pair, FileSessionNames.RSI_Peak, rsiLastPeak.PeakTrade.Price);
                _fileService.GatherDetails(pair, FileSessionNames.RSI_Analysis_Minutes, (_dateTime.Now - rsiLastPeak.ExitTrade.DateTime).TotalMinutes);
                _fileService.GatherDetails(pair, FileSessionNames.RSI_Decision, rsiLastPeak.PeakType == PeakType.High ? "sell" : "buy");
            }

            var macdSlow = groupedTradesSlow.Macd(_config[pair].MacdSlow, _config[pair].MacdFast, _config[pair].MacdSignal).ToList();

            var macdSlowAnalysis = macdSlow.MacdSlowAnalysis();

            _fileService.GatherDetails(pair, FileSessionNames.MACD_Slow_Analysis, macdSlowAnalysis.ToString());
            _fileService.GatherDetails(pair, FileSessionNames.MACD_Slow_Analysis_Value, macdSlow.Last().Macd);
            _fileService.GatherDetails(pair, FileSessionNames.MACD_Slow_Analysis_Signal, macdSlow.Last().Signal);


            var status = AnalysisExtensions.AnalyseIndeces(_config[pair].ThresholdMinutes, _dateTime.Now, macdAnalysis, rsiLastPeak, macdSlowAnalysis);

            _fileService.GatherDetails(pair, FileSessionNames.Analysis, status.ToString());
            return(status);
        }
コード例 #6
0
        public async Task <IActionResult> OnPostAsync()
        {
            // Get the current user.
            var user = await _userManager.GetUserAsync(User);

            // Check if there aren't any IDs provided.
            if (Input.Ids == null || !Input.Ids.Any())
            {
                // Display a message.
                TempData["StatusMessage"] = "Error: No or invalid IDs have been provided.";
                // Redirect to the index page.
                return(RedirectToPage("/Content/DatabaseTypes/PPI/Created/Analyses/Index"));
            }
            // Define the view.
            View = new ViewModel
            {
                Items = _context.Analyses
                        .Where(item => item.AnalysisDatabases.Any(item1 => item1.Database.DatabaseType.Name == "PPI"))
                        .Where(item => item.IsPublic || item.AnalysisUsers.Any(item1 => item1.User == user))
                        .Where(item => Input.Ids.Contains(item.Id))
            };
            // Check if there weren't any items found.
            if (View.Items == null || !View.Items.Any())
            {
                // Display a message.
                TempData["StatusMessage"] = "Error: No analyses have been found with the provided IDs, or you don't have access to them.";
                // Redirect to the index page.
                return(RedirectToPage("/Content/DatabaseTypes/PPI/Created/Analyses/Index"));
            }
            // Check if the reCaptcha is valid.
            if (!await _reCaptchaChecker.IsValid(Input.ReCaptchaToken))
            {
                // Add an error to the model.
                ModelState.AddModelError(string.Empty, "The reCaptcha verification failed.");
                // Return the page.
                return(Page());
            }
            // Check if the provided model isn't valid.
            if (!ModelState.IsValid)
            {
                // Add an error to the model.
                ModelState.AddModelError(string.Empty, "An error has been encountered. Please check again the input fields.");
                // Redisplay the page.
                return(Page());
            }
            // Return the streamed file.
            return(new FileCallbackResult(MediaTypeNames.Application.Zip, async(zipStream, _) =>
            {
                // Define a new ZIP archive.
                using var archive = new ZipArchive(zipStream, ZipArchiveMode.Create);
                // Check if the overview file should be added.
                if (true)
                {
                    // Create a new entry in the archive and open it.
                    using var stream = archive.CreateEntry($"Analyses-List.txt", CompressionLevel.Fastest).Open();
                    // Write to the entry the corresponding file content.
                    await AnalysisExtensions.WriteToStreamOverviewTextFileContent(View.Items.Select(item => item.Id), stream, _serviceProvider, HttpContext.Request.Scheme, HttpContext.Request.Host);
                }
                // Check which should be the format of the files within the archive.
                if (Input.FileFormat == "txt")
                {
                    // Go over each of the analyses to download.
                    foreach (var analysis in View.Items)
                    {
                        // Create a new entry in the archive and open it.
                        using var stream = archive.CreateEntry($"Analysis-{analysis.Name.Replace(" ", "-")}-{analysis.Id}.txt", CompressionLevel.Fastest).Open();
                        // Write to the entry the corresponding file content.
                        await analysis.WriteToStreamTxtFileContent(stream, _serviceProvider);
                    }
                }
                if (Input.FileFormat == "sif")
                {
                    // Go over each of the analyses to download.
                    foreach (var analysis in View.Items)
                    {
                        // Create a new entry in the archive and open it.
                        using var stream = archive.CreateEntry($"Analysis-{analysis.Name.Replace(" ", "-")}-{analysis.Id}.sif", CompressionLevel.Fastest).Open();
                        // Write to the entry the corresponding file content.
                        await analysis.WriteToStreamSifFileContent(stream, _serviceProvider);
                    }
                }
                else if (Input.FileFormat == "json")
                {
                    // Go over each of the analyses to download.
                    foreach (var analysis in View.Items)
                    {
                        // Create a new entry in the archive and open it.
                        using var stream = archive.CreateEntry($"Analysis-{analysis.Name.Replace(" ", "-")}-{analysis.Id}.json", CompressionLevel.Fastest).Open();
                        // Write to the entry the corresponding file content.
                        await analysis.WriteToStreamJsonFileContent(stream, _serviceProvider);
                    }
                }
                else if (Input.FileFormat == "cyjs")
                {
                    // Go over each of the analyses to download.
                    foreach (var analysis in View.Items)
                    {
                        // Create a new entry in the archive and open it.
                        using var stream = archive.CreateEntry($"Analysis-{analysis.Name.Replace(" ", "-")}-{analysis.Id}.cyjs", CompressionLevel.Fastest).Open();
                        // Write to the entry the corresponding file content.
                        await analysis.WriteToStreamCyjsFileContent(stream, _serviceProvider);
                    }
                }
                else if (Input.FileFormat == "xlsx")
                {
                    // Go over each of the analyses to download.
                    foreach (var analysis in View.Items)
                    {
                        // Create a new entry in the archive and open it.
                        using var stream = archive.CreateEntry($"Analysis-{analysis.Name.Replace(" ", "-")}-{analysis.Id}.xlsx", CompressionLevel.Fastest).Open();
                        // Write to the entry the corresponding file content.
                        await analysis.WriteToStreamXlsxFileContent(stream, _serviceProvider);
                    }
                }
            })
            {
                FileDownloadName = $"NetControl4BioMed-Analyses-{DateTime.UtcNow:yyyyMMdd}.zip"
            });