예제 #1
0
        public async Task <ResponseModel> DeleteWatchList(string id)
        {
            var clientId = User.GetClaim(AuthConsts.SubjectClaim);

            if (clientId == null)
            {
                return(ResponseModel <List <WatchListContract> > .CreateFail(ResponseModel.ErrorCodeType.NoAccess, "Wrong token"));
            }

            var result = await _watchListService.DeleteAsync(clientId, id);

            switch (result.Status)
            {
            case WatchListStatus.NotFound:
                return(ResponseModel.CreateFail(ResponseModel.ErrorCodeType.NoData, "Watch list not found"));

            case WatchListStatus.ReadOnly:
                return(ResponseModel.CreateFail(ResponseModel.ErrorCodeType.InconsistentData, "Readonly watch list can't be deleted"));
            }

            return(ResponseModel.CreateOk());
        }
예제 #2
0
        public async Task <ResponseModel> AddLot([FromBody] AuctionLot model)
        {
            if (string.IsNullOrEmpty(model.ClientId))
            {
                return(ResponseModel.CreateFail(ResponseModel.ErrorCodeType.InvalidInputField,
                                                $"{nameof(model.ClientId)} is required"));
            }

            if (string.IsNullOrEmpty(model.AssetId))
            {
                return(ResponseModel.CreateFail(ResponseModel.ErrorCodeType.InvalidInputField,
                                                $"{nameof(model.AssetId)} is required"));
            }

            if (!_settings.Assets.Contains(model.AssetId))
            {
                return(ResponseModel.CreateFail(ResponseModel.ErrorCodeType.InvalidInputField,
                                                $"wrong {nameof(model.AssetId)}"));
            }

            if (model.Price <= 0)
            {
                return(ResponseModel.CreateFail(ResponseModel.ErrorCodeType.InvalidInputField,
                                                $"wrong {nameof(model.Price)}"));
            }

            if (model.Volume <= 0)
            {
                return(ResponseModel.CreateFail(ResponseModel.ErrorCodeType.InvalidInputField,
                                                $"wrong {nameof(model.Volume)}"));
            }

            //TODO: validate model.ClientId
            await _auctionLotManager.AddAsync(model.ClientId, model.AssetId, model.Price, model.Volume);

            return(ResponseModel.CreateOk());
        }
예제 #3
0
 private ResponseModel ConvertToApiModel(MeStatusCodes status)
 {
     return(status == MeStatusCodes.Ok
         ? ResponseModel.CreateOk()
         : ResponseModel.CreateFail(ErrorCodeType.Rejected, status.ToString()));
 }
예제 #4
0
 public static ResponseModel <T> UserNotFoundError <T>(this Controller controller)
 {
     return(ResponseModel <T> .CreateFail(ResponseModel.ErrorCodeType.NoAccess, "User not found"));
 }
        public async Task <IActionResult> PlaceStopLimitOrder([FromBody] PlaceStopLimitOrderModel order)
        {
            var assetPair = _assetPairsReadModel.TryGetIfEnabled(order.AssetPairId);

            if (assetPair == null)
            {
                return(NotFound($"Asset-pair {order.AssetPairId} could not be found or is disabled."));
            }

            if (!_requestValidator.ValidateAssetPair(order.AssetPairId, assetPair, out var badRequestModel))
            {
                return(BadRequest(badRequestModel));
            }

            var asset = _assetsReadModel.TryGetIfEnabled(assetPair.BaseAssetId);

            if (asset == null)
            {
                throw new InvalidOperationException($"Base asset '{assetPair.BaseAssetId}' for asset pair '{assetPair.Id}' not found.");
            }


            var lowerPrice = order.LowerPrice;

            if (lowerPrice.HasValue && !_requestValidator.ValidatePrice(lowerPrice.Value, out badRequestModel, nameof(PlaceStopLimitOrderModel.LowerPrice)))
            {
                return(BadRequest(badRequestModel));
            }

            var lowerLimitPrice = order.LowerLimitPrice;

            if (lowerLimitPrice.HasValue && !_requestValidator.ValidatePrice(lowerLimitPrice.Value, out badRequestModel, nameof(PlaceStopLimitOrderModel.LowerLimitPrice)))
            {
                return(BadRequest(badRequestModel));
            }

            if ((lowerPrice.HasValue && !lowerLimitPrice.HasValue) ||
                (!lowerPrice.HasValue && lowerLimitPrice.HasValue))
            {
                return(BadRequest(ResponseModel.CreateInvalidFieldError(nameof(order.LowerPrice), "When lower price is send then also lower limit price is required and vice versa.")));
            }

            var upperPrice = order.UpperPrice;

            if (upperPrice.HasValue && !_requestValidator.ValidatePrice(upperPrice.Value, out badRequestModel, nameof(PlaceStopLimitOrderModel.UpperPrice)))
            {
                return(BadRequest(badRequestModel));
            }

            var upperLimitPrice = order.UpperLimitPrice;

            if (upperLimitPrice.HasValue && !_requestValidator.ValidatePrice(upperLimitPrice.Value, out badRequestModel, nameof(PlaceStopLimitOrderModel.UpperLimitPrice)))
            {
                return(BadRequest(badRequestModel));
            }

            if ((upperPrice.HasValue && !upperLimitPrice.HasValue) ||
                (!upperPrice.HasValue && upperLimitPrice.HasValue))
            {
                return(BadRequest(ResponseModel.CreateInvalidFieldError(nameof(order.UpperPrice), "When upper price is send then also upper limit price is required and vice versa.")));
            }

            if (new[] { lowerPrice, lowerLimitPrice, upperPrice, upperLimitPrice }.All(x => !x.HasValue))
            {
                return(BadRequest(ResponseModel.CreateFail(ErrorCodeType.Rejected,
                                                           "At least lower or upper prices are needed for a stop order.")));
            }

            var volume    = order.Volume;
            var minVolume = assetPair.MinVolume;

            if (!_requestValidator.ValidateVolume(volume, minVolume, asset.DisplayId, out badRequestModel))
            {
                return(BadRequest(badRequestModel));
            }

            var walletId = User.GetUserId();
            var response = await _matchingEngineAdapter.PlaceStopLimitOrderAsync(
                clientId : walletId,
                assetPair : assetPair,
                orderAction : order.OrderAction,
                volume : volume,
                lowerPrice : lowerPrice,
                lowerLimitPrice : lowerLimitPrice,
                upperPrice : upperPrice,
                upperLimitPrice : upperLimitPrice);

            if (response.Error != null)
            {
                return(BadRequest(response));
            }

            return(Ok(response.Result));
        }