private void Validate(AssetPairExtPriceSettings extPriceSettings) { extPriceSettings.RequiredNotNull("extPriceSettings for pair " + _assetPairId); extPriceSettings.Exchanges.RequiredNotNullOrEmpty( "extPriceSettings.Exchanges for pair " + _assetPairId); extPriceSettings.PresetDefaultExchange.RequiredInSet(extPriceSettings.Exchanges.Keys, "extPriceSettings.PresetDefaultExchange for pair " + _assetPairId); extPriceSettings.OutlierThreshold.RequiredBetween(0.00001m, 0.5m, "extPriceSettings.OutlierThreshold for " + _assetPairId); extPriceSettings.MinOrderbooksSendingPeriod.RequiredBetween(TimeSpan.Zero, TimeSpan.FromHours(1), "extPriceSettings.MinOrderbooksSendingPeriod for " + _assetPairId); extPriceSettings.Markups.RequiredNotNull("extPriceSettings.Markups for " + _assetPairId); extPriceSettings.RepeatedOutliers.RequiredNotNull( "extPriceSettings.RepeatedOutliers for " + _assetPairId); extPriceSettings.RepeatedOutliers.MaxSequenceLength.RequiredBetween(2, 100000, "extPriceSettings.RepeatedOutliers.MaxSequenceLength for " + _assetPairId); extPriceSettings.RepeatedOutliers.MaxSequenceAge.RequiredBetween(TimeSpan.FromMilliseconds(1), TimeSpan.FromHours(1), "extPriceSettings.RepeatedOutliers.MaxSequenceAge for " + _assetPairId); extPriceSettings.RepeatedOutliers.MaxAvg.RequiredBetween(0.0001m, 1, "extPriceSettings.RepeatedOutliers.MaxAvg for " + _assetPairId); extPriceSettings.RepeatedOutliers.MaxAvgAge.RequiredBetween(TimeSpan.FromMilliseconds(1), TimeSpan.FromHours(1), "extPriceSettings.RepeatedOutliers.MaxAvgAge for " + _assetPairId); extPriceSettings.Steps.RequiredNotNull("extPriceSettings.Steps for " + _assetPairId); foreach (var(exchangeName, exchangeSettings) in extPriceSettings.Exchanges) { new ExchangeValidator(_assetPairId, exchangeName, exchangeSettings).Validate(); } }
public ExchangeExtPriceSettings Add(string assetPairId, string exchangeName, string reason) { var newExchange = GetDefaultExchange(); Update(assetPairId, old => AssetPairExtPriceSettings.Change(old, old.Exchanges.Add(exchangeName, newExchange)), reason); return(newExchange); }
public void Delete(string assetPairId, string exchangeName, string reason) { if (TryGetExchange(assetPairId, exchangeName) == null) { throw new Exception($"Exchange {exchangeName} not exist for asset pair {assetPairId}"); } Update(assetPairId, old => AssetPairExtPriceSettings.Change(old, old.Exchanges.Remove(exchangeName)), reason); }
private void UpdateExchanges(string assetPairId, IEnumerable <string> exchangeNames, Func <ExchangeExtPriceSettings, ExchangeExtPriceSettings> changeFunc, string reason) { var exchangesHashSet = exchangeNames.ToImmutableHashSet(); Update(assetPairId, old => { var newExchanges = old.Exchanges .SetItems(old.Exchanges.Where(o => exchangesHashSet.Contains(o.Key)) .Select(s => KeyValuePair.Create(s.Key, changeFunc(s.Value)))); return(AssetPairExtPriceSettings.Change(old, newExchanges)); }, reason); }
private AssetPairExtPriceSettingsModel Convert(string assetPairId, [CanBeNull] AssetPairExtPriceSettings setting) { if (setting == null) { return(null); } var model = _convertService.Convert <AssetPairExtPriceSettings, AssetPairExtPriceSettingsModel>(setting, o => o.ConfigureMap(MemberList.Source).ForSourceMember(s => s.Exchanges, e => e.Ignore())); model.AssetPairId = assetPairId; model.Steps = Convert(_extPricesSettingsService.GetDefaultSteps().SetItems(setting.Steps)); return(model); }
public void UpdateWithoutExchanges(string assetPairId, AssetPairExtPriceSettings setting, string reason) { Update(assetPairId, old => AssetPairExtPriceSettings.Change(setting, old.Exchanges), reason); }