Exemplo n.º 1
0
            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();
                }
            }
Exemplo n.º 2
0
        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);
        }
Exemplo n.º 3
0
        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);
        }
Exemplo n.º 4
0
        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);
        }
Exemplo n.º 5
0
        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);
        }
Exemplo n.º 6
0
 public void UpdateWithoutExchanges(string assetPairId, AssetPairExtPriceSettings setting, string reason)
 {
     Update(assetPairId, old => AssetPairExtPriceSettings.Change(setting, old.Exchanges), reason);
 }