public IActionResult GetCondition(string condition, string password) { var conditions = Registry.GetConditions().ToList(); var conditionEntry = conditions.FirstOrDefault(c => c.Name.ToLower() == condition.ToLower()); if (conditionEntry == null) { return(NotFound()); } var data = new List <AlertDTO>(); var syncService = this.ServiceProvider.GetService <ISyncService>(); var orders = syncService.GetTotalOrders(enableAudit: false); var config = this.Context.ConfigurationReadOnly; var poolData = this.Context.PoolHashratesReadOnly.ToList(); ICondition conditionInstance = (ICondition)Activator.CreateInstance(conditionEntry, args: this.ServiceProvider); if (conditionEntry.IsDefined(typeof(GlobalConditionAttribute), false)) { data = conditionInstance.Compute(orders.SelectMany(o => o), config, poolData).ToList(); } else { foreach (var order in orders) { data.AddRange(conditionInstance.Compute(order, config, poolData)); } } var cache = ServiceProvider.GetService <IMemoryCache>(); cache.TryGetValue <double>(Constants.HashRateKey, out var networkRate); cache.TryGetValue <double>(Constants.DifficultyKey, out var networkDifficulty); cache.TryGetValue <double>(Constants.BtcBtgPriceKey, out var price); return(Ok(new { Condition = conditionEntry.FullName, Data = data, Variables = new { StoredNetworkRate = networkRate, StoredNetworkDifficulty = networkDifficulty, StoredBtcBtgPrice = price }, Input = new { Config = config, Orders = orders, PoolData = poolData, } })); }
public IEnumerable <AlertDTO> Check(IEnumerable <IEnumerable <BidEntry> > orders, ApiConfiguration config, IEnumerable <ConditionSetting> settings, IEnumerable <PoolHashrate> poolData) { var foundOrders = new List <AlertDTO>(); var foundOrdersIDs = new HashSet <string>(); // Conditions are in order of priority var conditions = Registry.GetConditions().OrderBy(Registry.GetPriority).ToList(); foreach (var conditionEntry in conditions) { if (this.IsEnabled(settings, conditionEntry.Name)) { var data = new List <AlertDTO>(); ICondition condition = (ICondition)Activator.CreateInstance(conditionEntry, args: _serviceProvider); if (conditionEntry.IsDefined(typeof(GlobalConditionAttribute), false)) { data = condition.Compute(orders.SelectMany(o => o), config, poolData).ToList(); } else { foreach (var order in orders) { data.AddRange(condition.Compute(order, config, poolData)); } } foreach (var alert in data) { // Avoid duplicate alerts var sig = $"{alert.BidEntry.NiceHashId}{alert.BidEntry.NiceHashDataCenter}"; if (!foundOrdersIDs.Contains(sig)) { foundOrdersIDs.Add(sig); foundOrders.Add(alert); } } } } return(foundOrders); }