Ejemplo n.º 1
0
        public async Task <MtBackendResponse <IEnumerable <MarginTradingAccountModel> > > InitAccountGroup(
            [FromBody] InitAccountGroupRequest request)
        {
            var tradingCondition = _tradingConditionsCacheService.GetTradingCondition(request.TradingConditionId);

            if (tradingCondition == null)
            {
                return(MtBackendResponse <IEnumerable <MarginTradingAccountModel> > .Error(
                           $"No trading condition {request.TradingConditionId} found in cache"));
            }

            var accountGroup =
                _accountGroupCacheService.GetAccountGroup(request.TradingConditionId, request.BaseAssetId);

            if (accountGroup == null)
            {
                return(MtBackendResponse <IEnumerable <MarginTradingAccountModel> > .Error(
                           $"No account group {request.TradingConditionId}_{request.BaseAssetId} found in cache"));
            }

            var newAccounts = await _accountManager.CreateAccounts(request.TradingConditionId, request.BaseAssetId);

            return(MtBackendResponse <IEnumerable <MarginTradingAccountModel> > .Ok(
                       newAccounts.Select(a => a.ToBackendContract())));
        }
Ejemplo n.º 2
0
        public async Task <MtBackendResponse <AccountGroupModel> > AddOrReplaceAccountGroup(
            [FromBody] AccountGroupModel model)
        {
            var accountGroup = await _accountGroupManager.AddOrReplaceAccountGroupAsync(model.ToDomainContract());

            return(MtBackendResponse <AccountGroupModel> .Ok(accountGroup.ToBackendContract()));
        }
Ejemplo n.º 3
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.º 4
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.º 5
0
        public MtBackendResponse <bool> RemoveFromBestFxPriceCache(string assetPairId)
        {
            var result = _fxRateCacheService.RemoveQuote(assetPairId);

            return(result == RemoveQuoteErrorCode.None
                ? MtBackendResponse <bool> .Ok(true)
                : MtBackendResponse <bool> .Error(result.Message));
        }
Ejemplo n.º 6
0
        public async Task <MtBackendResponse <IEnumerable <AccountAssetPairModel> > > AssignInstruments(
            [FromBody] AssignInstrumentsRequest model)
        {
            try
            {
                var assetPairs = await _accountAssetsManager.AssignInstruments(model.TradingConditionId, model.BaseAssetId,
                                                                               model.Instruments);

                return(MtBackendResponse <IEnumerable <AccountAssetPairModel> > .Ok(
                           assetPairs.Select(a => a.ToBackendContract())));
            }
            catch (Exception e)
            {
                return(MtBackendResponse <IEnumerable <AccountAssetPairModel> > .Error(e.Message));
            }
        }
Ejemplo n.º 7
0
        public MtBackendResponse <bool> RemoveFromBestPriceCache(string assetPairId)
        {
            var positions = _ordersCache.Positions.GetPositionsByInstrument(assetPairId).ToList();

            if (positions.Any())
            {
                return(MtBackendResponse <bool> .Error(
                           $"Cannot delete [{assetPairId}] best price because there are {positions.Count} opened positions."));
            }

            var orders = _ordersCache.Active.GetOrdersByInstrument(assetPairId).ToList();

            if (orders.Any())
            {
                return(MtBackendResponse <bool> .Error(
                           $"Cannot delete [{assetPairId}] best price because there are {orders.Count} active orders."));
            }

            _quoteCacheService.RemoveQuote(assetPairId);

            return(MtBackendResponse <bool> .Ok(true));
        }
Ejemplo n.º 8
0
        public MtBackendResponse <bool> GetMaintenanceMode()
        {
            var result = _maintenanceModeService.CheckIsEnabled();

            return(MtBackendResponse <bool> .Ok(result));
        }
Ejemplo n.º 9
0
        public MtBackendResponse <bool> SetMaintenanceMode([FromBody] bool enabled)
        {
            _maintenanceModeService.SetMode(enabled);

            return(MtBackendResponse <bool> .Ok(enabled));
        }
Ejemplo n.º 10
0
        public MtBackendResponse <bool> ClearBestBriceCache(string assetPair)
        {
            _quoteCacheService.RemoveQuote(assetPair);

            return(MtBackendResponse <bool> .Ok(true));
        }