Пример #1
0
        public async Task <IActionResult> GetBalancesByAssetId(string assetId)
        {
            var result = new List <WalletAssetBalanceModel>();

            var wallets = await _clientAccountService.GetWalletsByClientIdAsync(_requestContext.ClientId);

            var clientKeys = await _hftInternalService.GetKeysAsync(_requestContext.ClientId);

            foreach (var wallet in wallets)
            {
                var balance = await _balancesClient.GetClientBalanceByAssetId(
                    new ClientBalanceByAssetIdModel
                {
                    ClientId = wallet.Type == TradingWalletType ? _requestContext.ClientId : wallet.Id,
                    AssetId  = assetId
                });

                result.Add(new WalletAssetBalanceModel
                {
                    Id          = wallet.Id,
                    Type        = wallet.Type,
                    Name        = wallet.Name,
                    Description = wallet.Description,
                    Balances    = balance != null ? ClientBalanceResponseModel.Create(balance) : new ClientBalanceResponseModel {
                        AssetId = assetId, Balance = 0, Reserved = 0
                    },
                    ApiKey = clientKeys.FirstOrDefault(x => x.Wallet == wallet.Id)?.Key
                });
            }

            return(Ok(result));
        }
Пример #2
0
        public async Task <IActionResult> GetWalletBalanceByAssetId(string walletId, string assetId)
        {
            // checking if wallet exists and user owns the specified wallet
            var wallet = await GetClientWallet(walletId);

            if (wallet == null)
            {
                return(NotFound());
            }

            var clientBalanceResult = await _balancesClient.GetClientBalanceByAssetId(
                new ClientBalanceByAssetIdModel
            {
                ClientId = walletId,
                AssetId  = assetId
            });

            var availableAssets = await _assetsHelper.GetAssetsAvailableToClientAsync(_requestContext.ClientId, _requestContext.PartnerId);

            if (!availableAssets.Contains(assetId))
            {
                return(NotFound());
            }

            if (clientBalanceResult != null && string.IsNullOrEmpty(clientBalanceResult.ErrorMessage))
            {
                return(Ok(ClientBalanceResponseModel.Create(clientBalanceResult)));
            }

            return(NotFound());
        }
Пример #3
0
        public async Task <IActionResult> GetTradindWalletBalanceByAssetId(string assetId)
        {
            var clientBalanceResultTask = _balancesClient.GetClientBalanceByAssetId(
                new ClientBalanceByAssetIdModel
            {
                ClientId = _requestContext.ClientId,
                AssetId  = assetId
            });

            var availableAssetsTask = _assetsHelper.GetSetOfAssetsAvailableToClientAsync(_requestContext.ClientId, _requestContext.PartnerId);

            await Task.WhenAll(clientBalanceResultTask, availableAssetsTask);

            if (!availableAssetsTask.Result.Contains(assetId))
            {
                return(NotFound());
            }

            if (clientBalanceResultTask.Result != null && string.IsNullOrEmpty(clientBalanceResultTask.Result.ErrorMessage))
            {
                return(Ok(ClientBalanceResponseModel.Create(clientBalanceResultTask.Result)));
            }

            return(NotFound());
        }
Пример #4
0
        public async Task <IActionResult> GetTradindWalletBalanceByAssetId(string assetId)
        {
            var clientBalanceResult = await _balancesClient.GetClientBalanceByAssetId(
                new ClientBalanceByAssetIdModel
            {
                ClientId = _requestContext.ClientId,
                AssetId  = assetId
            });

            if (clientBalanceResult != null && string.IsNullOrEmpty(clientBalanceResult.ErrorMessage))
            {
                return(Ok(ClientBalanceResponseModel.Create(clientBalanceResult)));
            }

            return(NotFound());
        }
Пример #5
0
        public async Task <IActionResult> GetBalancesByAssetId(string assetId)
        {
            var result = new List <WalletAssetBalanceModel>();

            var walletsTask         = _clientAccountService.Wallets.GetClientWalletsFilteredAsync(_requestContext.ClientId, owner: OwnerType.Spot);
            var clientKeysTask      = _hftInternalService.Keys.GetKeys(_requestContext.ClientId);
            var availableAssetsTask = _assetsHelper.GetSetOfAssetsAvailableToClientAsync(_requestContext.ClientId, _requestContext.PartnerId);
            await Task.WhenAll(walletsTask, clientKeysTask);

            var wallets         = walletsTask.Result;
            var clientKeys      = clientKeysTask.Result;
            var availableAssets = availableAssetsTask.Result;

            if (!availableAssets.Contains(assetId))
            {
                return(NotFound());
            }

            foreach (var wallet in wallets)
            {
                var balance = await _balancesClient.GetClientBalanceByAssetId(
                    new ClientBalanceByAssetIdModel
                {
                    ClientId = wallet.Type == WalletType.Trading ? _requestContext.ClientId : wallet.Id,
                    AssetId  = assetId
                });

                result.Add(new WalletAssetBalanceModel
                {
                    Id          = wallet.Id,
                    Type        = wallet.Type.ToString(),
                    Name        = wallet.Name,
                    Description = wallet.Description,
                    Balances    = balance != null ? ClientBalanceResponseModel.Create(balance) : new ClientBalanceResponseModel {
                        AssetId = assetId, Balance = 0, Reserved = 0
                    },
                    ApiKey = clientKeys.FirstOrDefault(x => x.WalletId == wallet.Id)?.ApiKey
                });
            }

            return(Ok(result));
        }
Пример #6
0
        public async Task <IActionResult> GetWalletBalanceByAssetId(string walletId, string assetId)
        {
            // checking if wallet exists and user owns the specified wallet
            var wallet = await GetClientWallet(walletId);

            if (wallet == null)
            {
                return(NotFound());
            }

            var clientBalanceResult = await _balancesClient.GetClientBalanceByAssetId(
                new ClientBalanceByAssetIdModel
            {
                ClientId = walletId,
                AssetId  = assetId
            });

            if (clientBalanceResult != null && string.IsNullOrEmpty(clientBalanceResult.ErrorMessage))
            {
                return(Ok(ClientBalanceResponseModel.Create(clientBalanceResult)));
            }

            return(NotFound());
        }