Ejemplo n.º 1
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());
        }
        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());
        }
Ejemplo n.º 3
0
        public async Task <ResponseModel> CancelLimitOrderAsync(Guid limitOrderId)
        {
            var response = await _matchingEngineClient.CancelLimitOrderAsync(limitOrderId.ToString());

            CheckResponseAndThrowIfNull(response);

            return(ConvertToApiModel(response.Status));
        }
        public async Task <IActionResult> CancelOrder([FromBody] CancelLimitOrderRequest request)
        {
            if (request?.OrderId == null)
            {
                return(BadRequest("Incorect parameters - null"));
            }
            await _meclient.CancelLimitOrderAsync(request.OrderId);

            var resp = new CancelLimitOrderResponse()
            {
                OrderId = request?.OrderId
            };

            return(Ok(resp));
        }
Ejemplo n.º 5
0
        public async Task <IActionResult> CancelMarketOrder(string orderId)
        {
            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());
        }
Ejemplo n.º 6
0
        public async Task <IActionResult> CancelOrder(string orderId)
        {
            MeResponseModel response = await _matchingEngineClient.CancelLimitOrderAsync(orderId);

            if (response == null)
            {
                throw HftApiException.Create(HftApiErrorCode.MeRuntime, "ME not available");
            }

            (HftApiErrorCode code, string message) = response.Status.ToHftApiError();

            if (code == HftApiErrorCode.Success)
            {
                return(Ok(ResponseModel <string> .Ok(null)));
            }

            throw HftApiException.Create(code, message);
        }
Ejemplo n.º 7
0
        public override async Task <CancelOrderResponse> CancelOrder(CancelOrderRequest request, ServerCallContext context)
        {
            MeResponseModel response = await _matchingEngineClient.CancelLimitOrderAsync(request.OrderId);

            if (response == null)
            {
                return(new CancelOrderResponse
                {
                    Error = new Error
                    {
                        Code = (int)HftApiErrorCode.MeRuntime,
                        Message = "ME not available"
                    }
                });
            }

            (HftApiErrorCode code, string message) = response.Status.ToHftApiError();

            if (code == HftApiErrorCode.Success)
            {
                return new CancelOrderResponse
                       {
                           Payload = true
                       }
            }
            ;

            return(new CancelOrderResponse
            {
                Error = new Error
                {
                    Code = (int)code,
                    Message = message
                }
            });
        }
Ejemplo n.º 8
0
        public async Task CancelLimitOrderAsync(string id)
        {
            MeResponseModel response;

            try
            {
                response = await _matchingEngineClient.CancelLimitOrderAsync(id,
                                                                             new CancellationTokenSource(Consts.MatchingEngineTimeout).Token);
            }
            catch (Exception exception)
            {
                _log.Error(exception, "An error occurred during cancel limit order", new { request = $"id: {id}" });
                throw;
            }

            if (response.Status == MeStatusCodes.Ok)
            {
                _log.Info("ME cancel limit order response", new { response = $"data: {response.ToJson()}" });
            }
            else
            {
                _log.Warning("ME cancel limit order response unsuccessful code.", context: new { response = $"data: {response.ToJson()}" });
            }
        }
        public async Task <MeResponseModel> CancelOrder(string orderId)
        {
            var res = await _meclient.CancelLimitOrderAsync(orderId);

            return(res);
        }