Ejemplo n.º 1
0
        public async Task <MtBackendResponse <TradingConditionModel> > AddOrReplaceTradingCondition(
            [FromBody] TradingConditionModel model)
        {
            if (string.IsNullOrWhiteSpace(model.Id))
            {
                return(MtBackendResponse <TradingConditionModel> .Error("Id cannot be empty"));
            }

            if (string.IsNullOrWhiteSpace(model.Name))
            {
                return(MtBackendResponse <TradingConditionModel> .Error("Name cannot be empty"));
            }

            if (string.IsNullOrWhiteSpace(model.LegalEntity))
            {
                return(MtBackendResponse <TradingConditionModel> .Error("LegalEntity cannot be empty"));
            }

            if (_tradingConditionsCacheService.IsTradingConditionExists(model.Id))
            {
                var existingCondition = _tradingConditionsCacheService.GetTradingCondition(model.Id);

                if (existingCondition.LegalEntity != model.LegalEntity)
                {
                    return(MtBackendResponse <TradingConditionModel> .Error("LegalEntity cannot be changed"));
                }
            }

            var tradingCondition = model.ToDomainContract();

            tradingCondition = await _tradingConditionsManager.AddOrReplaceTradingConditionAsync(tradingCondition);

            return(MtBackendResponse <TradingConditionModel> .Ok(tradingCondition?.ToBackendContract()));
        }
Ejemplo n.º 2
0
        public async Task <MtBackendResponse <MarginTradingAccountModel> > SetTradingCondition(
            [FromBody] SetTradingConditionModel model)
        {
            if (!_tradingConditionsCacheService.IsTradingConditionExists(model.TradingConditionId))
            {
                return(MtBackendResponse <MarginTradingAccountModel> .Error(
                           $"No trading condition {model.TradingConditionId} found in cache"));
            }

            var tradingCondition = _tradingConditionsCacheService.GetTradingCondition(model.TradingConditionId);

            var account =
                await _accountManager.SetTradingCondition(model.ClientId, model.AccountId, model.TradingConditionId);

            if (account == null)
            {
                return(MtBackendResponse <MarginTradingAccountModel> .Error(
                           $"Account for client [{model.ClientId}] with id [{model.AccountId}] was not found"));
            }

            if (tradingCondition.LegalEntity != account.LegalEntity)
            {
                return(MtBackendResponse <MarginTradingAccountModel> .Error(
                           $"Account for client [{model.ClientId}] with id [{model.AccountId}] has LegalEntity " +
                           $"[{account.LegalEntity}], but trading condition wit id [{tradingCondition.Id}] has " +
                           $"LegalEntity [{tradingCondition.LegalEntity}]"));
            }

            return(MtBackendResponse <MarginTradingAccountModel> .Ok(account.ToBackendContract()));
        }
Ejemplo n.º 3
0
 private void ValidateTradingCondition(string tradingConditionId)
 {
     if (!_tradingConditionsCacheService.IsTradingConditionExists(tradingConditionId))
     {
         throw new ArgumentException("Invalid TradingConditionId");
     }
 }