public override async Task <AssetTradesResponse> GetAssetTrades(AssetTradesRequest request, ServerCallContext context) { var response = new AssetTradesResponse() { }; return(response); }
public override async Task <AssetTradesResponse> GetAssetTrades(AssetTradesRequest request, ServerCallContext context) { var result = new AssetTradesResponse(); var token = context.GetBearerToken(); var wallets = await _clientAccountClient.Wallets.GetClientWalletsFilteredAsync(context.GetClientId(), WalletType.Trading); var walletId = wallets.FirstOrDefault()?.Id; var response = await _walletApiV2Client.GetByWalletIdAsync( walletId, new List <string> { }, request.AssetId, null, request.Take, request.Skip, token); var assetPairs = await _assetsService.AssetPairGetAllAsync(); if (response != null) { foreach (var group in response.GroupBy(x => x.Id)) { var pair = group.ToList(); if (pair.Count == 0 || pair.Count != 2) { continue; } string assetPairId = pair[0].AssetPair; var assetPair = assetPairs.FirstOrDefault(x => x.Id == assetPairId); if (assetPair == null) { continue; } var assetTrade = new AssetTradesResponse.Types.AssetTradeModel { Id = pair[0].Id, AssetPairId = assetPairId, BaseAssetId = assetPair.BaseAssetId, QuoteAssetId = assetPair.QuotingAssetId, Price = pair[0].Price?.ToString() ?? string.Empty, Timestamp = Timestamp.FromDateTime(pair[0].DateTime.UtcDateTime) }; foreach (var item in pair) { if (item.Asset == assetPair.BaseAssetId) { assetTrade.BaseVolume = item.Amount.ToString(CultureInfo.InvariantCulture); } else { assetTrade.QuoteVolume = item.Amount.ToString(CultureInfo.InvariantCulture); } } result.Body = new AssetTradesResponse.Types.Body(); result.Body.Trades.Add(assetTrade); } } return(result); }