public static MeLimitOrderMassCancelModel ToMeModel(this LimitOrderMassCancelModel model) { return(MeLimitOrderMassCancelModel.Create( model.Id, model.ClientId, model.AssetPairId, model.IsBuy)); }
///<inheritdoc cref="IMatchingEngineClient"/> public Task <MeResponseModel> MassCancelLimitOrdersAsync(LimitOrderMassCancelModel model, CancellationToken cancellationToken = default) { return(SendData( model.ToMeModel(), _newTasksManager, x => x.ToDomainModel(), _meResponsePolicy, cancellationToken, model.Id, $"{model.AssetPairId} IsBuy={model.IsBuy}" )); }
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 } }); }
public override async Task <CancelOrderResponse> CancelAllOrders(CancelOrdersRequest request, ServerCallContext context) { MeResponseModel response; if (!string.IsNullOrEmpty(request.AssetPairId)) { var result = await _validationService.ValidateAssetPairAsync(request.AssetPairId); if (result != null) { var res = new CancelOrderResponse { Error = new ErrorResponseBody { Code = ErrorCode.InvalidField, Message = result.Message } }; res.Error.Fields.Add(result.FieldName, result.Message); } bool?isBuy; if (request.OptionalSideCase == CancelOrdersRequest.OptionalSideOneofCase.None) { isBuy = null; } else { 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.GetClientId(), IsBuy = isBuy }; response = await _matchingEngineClient.MassCancelLimitOrdersAsync(model); } else { var orders = await GetOrders(new LimitOrdersRequest(), context); if (orders.Body?.Orders.Any() ?? false) { var orderIds = orders.Body.Orders.Select(x => x.Id).ToList(); response = await _matchingEngineClient.CancelLimitOrdersAsync(orderIds); } else { response = new MeResponseModel { Status = MeStatusCodes.Ok }; } } if (response == null) { return(new CancelOrderResponse { Error = new ErrorResponseBody { Code = ErrorCode.Runtime, Message = ErrorMessages.MeNotAvailable } }); } if (response.Status == MeStatusCodes.Ok) { return new CancelOrderResponse { Body = new CancelOrderResponse.Types.Body { Payload = true } } } ; return(new CancelOrderResponse { Error = new ErrorResponseBody { Code = ErrorCode.Runtime, Message = response.Message ?? response.Status.ToString() } }); }