예제 #1
0
 public async Task <List <AssetPairContract> > List([FromQuery] string legalEntity,
                                                    [FromQuery] MatchingEngineModeContract?matchingEngineMode)
 {
     return((await _assetPairsRepository.GetAsync()).Select(Convert)
            .Where(s => (matchingEngineMode == null || s.MatchingEngineMode == matchingEngineMode) &&
                   (legalEntity == null || s.LegalEntity == legalEntity)).ToList());
 }
예제 #2
0
 private void InitAssetPairs()
 {
     lock (InitAssetPairsLock)
     {
         var pairs = _assetPairsRepository.GetAsync().GetAwaiter().GetResult()
             .ToDictionary(a => a.Id, s => s);
         _assetPairsCache.InitPairsCache(pairs);
     }
 }
예제 #3
0
        public async Task <ActionResult> EditDialog(string id)
        {
            var viewModel = new AssetPairsEditViewModel
            {
                Caption   = Phrases.EditAssetPair,
                Assets    = (await _assetsRepository.GetAssetsAsync()).ToDictionary(itm => itm.Id),
                AssetPair = string.IsNullOrEmpty(id) ? AssetPair.CreateDefault() : await _assetPairsRepository.GetAsync(id)
            };

            return(View(viewModel));
        }
예제 #4
0
        public async Task <List <CompiledScheduleContract> > StateList([FromBody] string[] assetPairIds)
        {
            var allSettingsTask = _scheduleSettingsRepository.GetFilteredAsync();
            var assetPairsTask  = _assetPairsRepository.GetAsync(assetPairIds);
            var allSettings     = await allSettingsTask;
            var assetPairs      = await assetPairsTask;

            //extract the list of assetPairs with same settings based on regex, market or list
            var result = assetPairs.Select(assetPair => new CompiledScheduleContract
            {
                AssetPairId      = assetPair.Id,
                ScheduleSettings = allSettings
                                   .Where(setting => setting.AssetPairs.Contains(assetPair.Id) ||
                                          (!string.IsNullOrWhiteSpace(setting.AssetPairRegex) &&
                                           Regex.IsMatch(assetPair.Id,
                                                         setting.AssetPairRegex,
                                                         RegexOptions.IgnoreCase)) ||
                                          setting.MarketId == assetPair.MarketId)
                                   .Select(x =>
                                           _convertService.Convert <IScheduleSettings, CompiledScheduleSettingsContract>(x)).ToList()
            }).ToList();

            return(result);
        }
        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");
            }
        }
예제 #6
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");
            }
        }
예제 #7
0
 public async Task <List <AssetPairContract> > AssetPairs()
 {
     return((await _assetPairsRepository.GetAsync()).Select(Convert).ToList());
 }
        public async Task <AssetPairContract> Get(string assetPairId)
        {
            var obj = await _assetPairsRepository.GetAsync(assetPairId);

            return(_convertService.Convert <IAssetPair, AssetPairContract>(obj));
        }