private async Task ValidateTradingCondition(TradingConditionContract tradingCondition) { if (tradingCondition == null) { throw new ArgumentNullException("tradingCondition", "Model is incorrect"); } if (string.IsNullOrWhiteSpace(tradingCondition?.Id)) { throw new ArgumentNullException(nameof(tradingCondition.Id), "TradingCondition Id must be set"); } if (!string.IsNullOrEmpty(tradingCondition.LimitCurrency) && await _assetsRepository.GetAsync(tradingCondition.LimitCurrency) == null) { throw new InvalidOperationException($"LimitCurrency asset {tradingCondition.LimitCurrency} does not exist"); } foreach (var baseAsset in tradingCondition.BaseAssets) {//TODO optimization may be applied here if (await _assetsRepository.GetAsync(baseAsset) == null) { throw new InvalidOperationException($"Base asset {baseAsset} does not exist"); } } }
private async Task ValidateTradingInstrument(TradingInstrumentContract instrument) { if (instrument == null) { throw new ArgumentNullException("instrument", "Model is incorrect"); } if (string.IsNullOrWhiteSpace(instrument?.TradingConditionId)) { throw new ArgumentNullException(nameof(instrument.TradingConditionId), "TradingConditionId must be set"); } if (string.IsNullOrWhiteSpace(instrument.Instrument)) { throw new ArgumentNullException(nameof(instrument.Instrument), "Instrument must be set"); } if (await _tradingConditionsRepository.GetAsync(instrument.TradingConditionId) == null) { throw new InvalidOperationException($"Trading condition {instrument.TradingConditionId} does not exist"); } if (await _assetPairsRepository.GetAsync(instrument.Instrument) == null) { throw new InvalidOperationException($"Asset pair {instrument.Instrument} does not exist"); } if (instrument.LeverageInit <= 0) { throw new InvalidOperationException($"LeverageInit must be greather then zero"); } if (instrument.LeverageMaintenance <= 0) { throw new InvalidOperationException($"LeverageMaintenance must be greather then zero"); } if (await _assetsRepository.GetAsync(instrument.CommissionCurrency) == null) { throw new InvalidOperationException($"Commission currency {instrument.CommissionCurrency} does not exist"); } }
private async Task ValidateRoute(MatchingEngineRouteContract route) { if (route == null) { throw new ArgumentNullException(nameof(route), "Model is incorrect"); } if (string.IsNullOrWhiteSpace(route?.Id)) { throw new ArgumentNullException(nameof(route.Id), "Route Id must be set"); } if (route.Type != null && !Enum.IsDefined(typeof(OrderDirectionContract), route.Type)) { throw new ArgumentNullException(nameof(route.Type), "Route Type is set to an incorrect value"); } if (!string.IsNullOrEmpty(route.TradingConditionId) && await _tradingConditionsRepository.GetAsync(route.TradingConditionId) == null) { throw new InvalidOperationException($"Trading condition {route.TradingConditionId} does not exist"); } if (!string.IsNullOrEmpty(route.Instrument) && await _assetPairsRepository.GetAsync(route.Instrument) == null) { throw new InvalidOperationException($"Asset pair {route.Instrument} does not exist"); } if (string.IsNullOrEmpty(route.Asset) || route.Asset == AnyValue) { route.Asset = AnyValue; } else if (await _assetsRepository.GetAsync(route.Asset) == null) { throw new InvalidOperationException($"Asset {route.Asset} does not exist"); } }
public async Task <List <AssetContract> > List() { var data = await _assetsRepository.GetAsync(); return(data.Select(x => _convertService.Convert <IAsset, AssetContract>(x)).ToList()); }
private async Task ValidatePairInsert(AssetPairContract assetPair) { if (assetPair == null) { throw new ArgumentNullException(nameof(assetPair), "Model is incorrect"); } if (string.IsNullOrWhiteSpace(assetPair.Id)) { throw new ArgumentNullException(nameof(assetPair.Id), "AssetPair Id must be set"); } if (!Enum.IsDefined(typeof(MatchingEngineModeContract), assetPair.MatchingEngineMode)) { throw new ArgumentNullException(nameof(assetPair.MatchingEngineMode), "AssetPair MatchingEngineMode must be set"); } if (await _assetsRepository.GetAsync(assetPair.BaseAssetId) == null) { throw new InvalidOperationException($"Base Asset {assetPair.BaseAssetId} does not exist"); } if (await _assetsRepository.GetAsync(assetPair.QuoteAssetId) == null) { throw new InvalidOperationException($"Quote Asset {assetPair.QuoteAssetId} does not exist"); } if (!string.IsNullOrEmpty(assetPair.MarketId) && await _marketRepository.GetAsync(assetPair.MarketId) == null) { throw new InvalidOperationException($"Market {assetPair.MarketId} does not exist"); } if (assetPair.StpMultiplierMarkupAsk <= 0) { throw new InvalidOperationException($"StpMultiplierMarkupAsk must be greater then zero"); } if (assetPair.StpMultiplierMarkupBid <= 0) { throw new InvalidOperationException($"StpMultiplierMarkupBid must be greater then zero"); } if (await _assetPairsRepository.GetByBaseQuoteAndLegalEntityAsync(assetPair.BaseAssetId, assetPair.QuoteAssetId, assetPair.LegalEntity) != null) { throw new InvalidOperationException($"Asset pair with base asset [{assetPair.BaseAssetId}], quote asset [{assetPair.QuoteAssetId}] and legal entity [{assetPair.LegalEntity}] already exists"); } //base pair check <-- the last one if (assetPair.BasePairId == null) { return; } if (await _assetPairsRepository.GetAsync(assetPair.BasePairId) == null) { throw new InvalidOperationException($"BasePair with Id {assetPair.BasePairId} does not exist"); } if (await _assetPairsRepository.GetByBaseAssetPairAsync(assetPair.BasePairId) != null) { throw new InvalidOperationException($"BasePairId {assetPair.BasePairId} does not exist"); } if (await _assetPairsRepository.GetByBaseAssetPairAndNotByIdAsync(assetPair.Id, assetPair.BasePairId) != null) { throw new InvalidOperationException($"BasePairId {assetPair.BasePairId} cannot be added twice"); } }