예제 #1
0
        public async Task <List <TradingConditionContract> > List([FromQuery] bool?isDefault = null)
        {
            var data = await _tradingConditionsRepository.GetAsync();

            return(data
                   .Where(x => isDefault == null || x.IsDefault == isDefault)
                   .Select(x => _convertService.Convert <ITradingCondition, TradingConditionContract>(x)).ToList());
        }
        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");
            }
        }
예제 #3
0
        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");
            }
        }