Exemple #1
0
        public async Task UpdateAsync(ClientProfileSettings model, string username, string correlationId)
        {
            var existing = await _regulatorySettingsRepository.GetByIdsAsync(model.ClientProfileId, model.AssetTypeId);

            if (existing == null)
            {
                throw new ClientSettingsDoNotExistException();
            }

            var regulatorySettings =
                await _regulatorySettingsApi.GetRegulatorySettingsByIdsAsync(existing.RegulatoryProfileId,
                                                                             existing.RegulatoryTypeId);

            //This should not happen when we handle deleting of RegulatorySettings in MDM
            if (regulatorySettings.ErrorCode == RegulationsErrorCodesContract.RegulatorySettingsDoNotExist)
            {
                throw new RegulatorySettingsDoNotExistException();
            }

            if (model.IsAvailable && !regulatorySettings.RegulatorySettings.IsAvailable)
            {
                throw new CannotSetToAvailableException();
            }

            if (model.Margin > 100 || model.Margin < regulatorySettings.RegulatorySettings.MarginMinPercent)
            {
                throw new InvalidMarginValueException();
            }

            if (model.OnBehalfFee < 0)
            {
                throw new InvalidOnBehalfFeeException();
            }

            if (model.ExecutionFeesRate < 0 || model.ExecutionFeesRate > 100)
            {
                throw new InvalidExecutionFeesRateException();
            }

            if (model.ExecutionFeesCap < model.ExecutionFeesFloor)
            {
                throw new InvalidExecutionFeesCapException();
            }

            if (model.ExecutionFeesFloor > model.ExecutionFeesCap || model.ExecutionFeesFloor < 0)
            {
                throw new InvalidExecutionFeesFloorException();
            }

            await _regulatorySettingsRepository.UpdateAsync(model);

            var referenceId = $"ClientProfileId:{model.ClientProfileId},AssetTypeId:{model.AssetTypeId}";

            await _auditService.TryAudit(correlationId, username, referenceId, AuditDataType.ClientProfileSettings,
                                         model.ToJson(), existing.ToJson());

            await _entityChangedSender
            .SendEntityEditedEvent <ClientProfileSettings, ClientProfileSettingsContract,
                                    ClientProfileSettingsChangedEvent>(existing, model, username, correlationId);
        }
Exemple #2
0
        private static void ValidateRegulatoryConstraint(GetRegulatorySettingsByIdsResponse regulatorySettings,
                                                         ClientProfileSettings setting)
        {
            if (regulatorySettings.ErrorCode != RegulationsErrorCodesContract.None)
            {
                throw new RegulatorySettingsDoNotExistException();
            }

            if (!regulatorySettings.RegulatorySettings.IsAvailable && setting.IsAvailable ||
                regulatorySettings.RegulatorySettings.MarginMinPercent > setting.Margin)
            {
                throw new RegulationConstraintViolationException();
            }
        }
 public static ClientProfileSettingsEntity Create(ClientProfileSettings model)
 {
     return(new ClientProfileSettingsEntity
     {
         ExecutionFeesFloor = model.ExecutionFeesFloor,
         IsAvailable = model.IsAvailable,
         Margin = model.Margin,
         ExecutionFeesRate = model.ExecutionFeesRate,
         ExecutionFeesCap = model.ExecutionFeesCap,
         OnBehalfFee = model.OnBehalfFee,
         AssetTypeId = model.AssetTypeId,
         ClientProfileId = model.ClientProfileId,
         FinancingFeesRate = model.FinancingFeesRate,
     });
 }
Exemple #4
0
        public static ClientProfile ToClientProfileWithRate(this ClientProfileSettings source, decimal marginRate)
        {
            if (source == null)
            {
                return(null);
            }

            return(new ClientProfile
            {
                Id = source.ClientProfileId,
                MarginRate = marginRate,
                ExecutionFeesCap = source.ExecutionFeesCap,
                ExecutionFeesFloor = source.ExecutionFeesFloor,
                ExecutionFeesRate = source.ExecutionFeesRate / 100,
                FinancingFeesRate = source.FinancingFeesRate / 100,
                OnBehalfFee = source.OnBehalfFee
            });
        }
        public async Task UpdateAsync(ClientProfileSettings model)
        {
            using (var context = _contextFactory.CreateDataContext())
            {
                var entity = await context.ClientProfileSettings.FindAsync(model.ClientProfileId, model.AssetTypeId);

                if (entity == null)
                {
                    throw new ClientSettingsDoNotExistException();
                }

                entity.Margin             = model.Margin;
                entity.IsAvailable        = model.IsAvailable;
                entity.ExecutionFeesRate  = model.ExecutionFeesRate;
                entity.ExecutionFeesCap   = model.ExecutionFeesCap;
                entity.ExecutionFeesFloor = model.ExecutionFeesFloor;
                entity.FinancingFeesRate  = model.FinancingFeesRate;
                entity.OnBehalfFee        = model.OnBehalfFee;

                context.Update(entity);

                await context.SaveChangesAsync();
            }
        }
Exemple #6
0
 public async Task HandleClientProfileSettingsUpdated(ClientProfileSettings clientProfileSettings, DateTime timestamp)
 {
     await Handle(x => x.Underlying.AssetType == clientProfileSettings.AssetTypeId, timestamp);
 }