Esempio n. 1
0
        public override async Task <TradesResponse> GetTrades(TradesRequest request, ServerCallContext context)
        {
            var result = await _validationService.ValidateTradesRequestAsync(request.AssetPairId, request.Offset, request.Take);

            if (result != null)
            {
                return(new TradesResponse
                {
                    Error = new Error
                    {
                        Code = (int)result.Code,
                        Message = result.Message
                    }
                });
            }

            DateTime?from = null;
            DateTime?to   = null;

            if (DateTime.TryParse(request.From, out var fromDate))
            {
                from = fromDate;
            }

            if (DateTime.TryParse(request.To, out var toDate))
            {
                to = toDate;
            }

            var orderAction = request.OptionalSideCase == TradesRequest.OptionalSideOneofCase.None
                ? (OrderAction?)null
                : request.Side == Side.Buy ? OrderAction.Buy : OrderAction.Sell;
            var trades = await _historyClient.GetTradersAsync(context.GetHttpContext().User.GetWalletId(),
                                                              request.AssetPairId, request.Offset, request.Take, orderAction, from, to);

            var res  = new TradesResponse();
            var data = _mapper.Map <List <Trade> >(trades);

            res.Payload.AddRange(data);

            return(res);
        }
Esempio n. 2
0
        public async Task <IActionResult> GetTrades(
            [FromQuery] string assetPairId = null,
            [FromQuery] OrderAction?side   = null,
            [FromQuery] int?offset         = 0,
            [FromQuery] int?take           = 100,
            [FromQuery] DateTime?from      = null,
            [FromQuery] DateTime?to        = null
            )
        {
            var result = await _validationService.ValidateOrdersRequestAsync(assetPairId, offset, take);

            if (result != null)
            {
                throw HftApiException.Create(result.Code, result.Message)
                      .AddField(result.FieldName);
            }

            var trades = await _historyClient.GetTradersAsync(User.GetWalletId(), assetPairId, offset, take, side, from, to);

            return(Ok(ResponseModel <IReadOnlyCollection <TradeModel> > .Ok(_mapper.Map <IReadOnlyCollection <TradeModel> >(trades))));
        }