public async Task <IActionResult> CancelLimitOrder(string orderId)
        {
            var tradingSession = await _clientSessionsClient.GetTradingSession(_requestContext.SessionId);

            var confirmationRequired = _baseSettings.EnableSessionValidation && !(tradingSession?.Confirmed ?? false);

            if (confirmationRequired)
            {
                return(BadRequest("Session confirmation is required"));
            }

            if (!Guid.TryParse(orderId, out var id))
            {
                return(BadRequest());
            }

            var clientId = _requestContext.ClientId;

            var order = await _historyClient.OrdersApi.GetOrderAsync(id);

            if (order.WalletId != Guid.Parse(clientId))
            {
                return(NotFound());
            }

            var meResult = await _matchingEngineClient.CancelLimitOrderAsync(orderId);

            if (meResult.Status != MeStatusCodes.Ok)
            {
                throw new Exception($"{orderId} order cancelation failed with {meResult.ToJson()}");
            }

            return(Ok());
        }
示例#2
0
        public async Task <IActionResult> CancelLimitOrder(string orderId)
        {
            var tradingSession = await _clientSessionsClient.GetTradingSession(_lykkePrincipal.GetToken());

            var confirmationRequired = _baseSettings.EnableSessionValidation && !(tradingSession?.Confirmed ?? false);

            if (confirmationRequired)
            {
                return(BadRequest("Session confirmation is required"));
            }

            var clientId = _requestContext.ClientId;

            var activeOrders = await _limitOrdersRepository.GetActiveByClientIdAsync(clientId);

            if (activeOrders.All(x => x.Id != orderId))
            {
                return(NotFound());
            }

            await _limitOrdersRepository.CancelByIdAsync(orderId);

            await _matchingEngineClient.CancelLimitOrderAsync(orderId);

            return(Ok());
        }
示例#3
0
        public async Task <IActionResult> ConfirmTradingSession([FromBody] TradingSessionConfirmModel model)
        {
            var sessionId = _requestContext.SessionId;

            var tradingSession = await _clientSessionsClient.GetTradingSession(sessionId);

            if (tradingSession == null)
            {
                throw LykkeApiErrorException.BadRequest(LykkeApiErrorCodes.Service.InconsistentState);
            }

            if (tradingSession.Confirmed.HasValue && tradingSession.Confirmed.Value)
            {
                throw LykkeApiErrorException.BadRequest(LykkeApiErrorCodes.Service.InconsistentState);
            }

            try
            {
                var codeIsValid =
                    await _confirmationCodesClient.Google2FaCheckCodeAsync(_requestContext.ClientId,
                                                                           model.Confirmation);

                if (codeIsValid)
                {
                    var session = await _clientSessionsClient.GetAsync(sessionId);

                    await _clientSessionsClient.ConfirmTradingSession(_requestContext.ClientId, session.AuthId.ToString());

                    await _clientSessionsClient.ConfirmSessionAsync(sessionId);
                }
                else
                {
                    throw LykkeApiErrorException.BadRequest(LykkeApiErrorCodes.Service.SecondFactorCodeIncorrect);
                }

                return(Ok());
            }
            catch (ApiException e)
            {
                switch (e.StatusCode)
                {
                case HttpStatusCode.BadRequest:
                    throw LykkeApiErrorException.BadRequest(LykkeApiErrorCodes.Service.TwoFactorRequired);

                case HttpStatusCode.Forbidden:
                    throw LykkeApiErrorException.BadRequest(LykkeApiErrorCodes.Service.SecondFactorCheckForbiden);
                }

                throw;
            }
        }
示例#4
0
        public async Task <FeaturesResponseModel> Features()
        {
            var features = await _clientAccountService.GetFeaturesAsync(_requestContext.ClientId);

            var tradingSession = await _clientSessionsClient.GetTradingSession(_lykkePrincipal.GetToken());

            return(new FeaturesResponseModel
            {
                AffiliateEnabled = features.AffiliateEnabled,
                TradingSession = new TradingSessionResponseModel
                {
                    Enabled = _baseSettings.EnableSessionValidation,
                    Confirmed = tradingSession?.Confirmed,
                    Ttl = tradingSession?.Ttl?.TotalMilliseconds
                }
            });
        }
示例#5
0
        public async Task <FeaturesResponseModel> Features()
        {
            var featuresTask       = _clientAccountService.ClientSettings.GetFeaturesSettingsAsync(_requestContext.ClientId);
            var tradingSessionTask = _clientSessionsClient.GetTradingSession(_requestContext.SessionId);

            await Task.WhenAll(featuresTask, tradingSessionTask);

            return(new FeaturesResponseModel
            {
                AffiliateEnabled = featuresTask.Result.AffiliateEnabled,
                TradingSession = new TradingSessionResponseModel
                {
                    Enabled = _baseSettings.EnableSessionValidation,
                    Confirmed = tradingSessionTask.Result?.Confirmed,
                    Ttl = tradingSessionTask.Result?.Ttl?.TotalMilliseconds
                }
            });
        }