public async Task <IActionResult> CancelAllOrders([FromQuery] string assetPairId = null, [FromQuery] OrderAction?side = null) { var assetPairResult = await _validationService.ValidateAssetPairAsync(assetPairId); if (assetPairResult != null) { throw HftApiException.Create(assetPairResult.Code, assetPairResult.Message).AddField(assetPairResult.FieldName); } bool?isBuy; switch (side) { case OrderAction.Buy: isBuy = true; break; case OrderAction.Sell: isBuy = false; break; default: isBuy = null; break; } var model = new LimitOrderMassCancelModel { Id = Guid.NewGuid().ToString(), AssetPairId = assetPairId, ClientId = User.GetWalletId(), IsBuy = isBuy }; MeResponseModel response = await _matchingEngineClient.MassCancelLimitOrdersAsync(model); 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); }
public async Task <ResponseModel> CancelAllAsync(string clientId, AssetPair pair, bool?isBuy) { var model = new LimitOrderMassCancelModel { Id = GetNextRequestId().ToString(), AssetPairId = pair?.Id, ClientId = clientId, IsBuy = isBuy }; var response = await _matchingEngineClient.MassCancelLimitOrdersAsync(model); CheckResponseAndThrowIfNull(response); return(ConvertToApiModel(response.Status)); }
public async Task <IActionResult> CancelMultipleLimitOrders([FromBody] LimitOrderCancelMultipleRequest model) { var tradingSession = await _clientSessionsClient.GetTradingSession(_requestContext.SessionId); var confirmationRequired = _baseSettings.EnableSessionValidation && !(tradingSession?.Confirmed ?? false); if (confirmationRequired) { return(BadRequest("Session confirmation is required")); } if (!string.IsNullOrEmpty(model.AssetPairId)) { var pair = _assetsServiceClient.AssetPairs.Get(model.AssetPairId); if (pair == null) { return(BadRequest($"Asset pair '{model.AssetPairId}' not found.")); } } var clientId = _requestContext.ClientId; var activeOrders = await _historyClient.OrdersApi.GetActiveOrdersByWalletAsync(Guid.Parse(clientId), 0, 1); if (!activeOrders.Any()) { return(Ok()); } var cancelModel = new LimitOrderMassCancelModel { AssetPairId = model.AssetPairId, ClientId = clientId, Id = Guid.NewGuid().ToString(), IsBuy = null }; var meResult = await _matchingEngineClient.MassCancelLimitOrdersAsync(cancelModel); if (meResult.Status != MeStatusCodes.Ok) { throw new Exception($"{cancelModel.ToJson()} request failed with {meResult.ToJson()}"); } return(Ok()); }
public override async Task <CancelOrderResponse> CancelAllOrders(CancelOrdersRequest request, ServerCallContext context) { var result = await _validationService.ValidateAssetPairAsync(request.AssetPairId); if (result != null) { return(new CancelOrderResponse { Error = new Error { Code = (int)result.Code, Message = result.Message } }); } bool?isBuy; switch (request.Side) { case Side.Buy: isBuy = true; break; case Side.Sell: isBuy = false; break; default: isBuy = null; break; } var model = new LimitOrderMassCancelModel { Id = Guid.NewGuid().ToString(), AssetPairId = request.AssetPairId, ClientId = context.GetHttpContext().User.GetWalletId(), IsBuy = isBuy }; MeResponseModel response = await _matchingEngineClient.MassCancelLimitOrdersAsync(model); 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 } }); }