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"); } }