Beispiel #1
0
        private async Task <IList <ExternalBalanceIssueDto> > FindBalancesWithIssues()
        {
            var balanceIssues = new List <ExternalBalanceIssueDto>();

            var neInstance = _nettingEngineInstanceManager.Instances.First();

            if (neInstance == null)
            {
                return(balanceIssues);
            }

            var balanceWarnings = await _externalBalanceWarningRepository.GetExternalBalancesWarnings();

            var task = neInstance.Balances.GetExternalAsync();
            await Task.WhenAll(task);

            var balances = task.Result
                           .ToDictionary(x => GetBalanceDictionaryKey(x.Exchange, x.AssetId), x => x);

            foreach (var balanceWarning in balanceWarnings)
            {
                var key = GetBalanceDictionaryKey(balanceWarning.Exchange, balanceWarning.AssetId);

                var isBalanceFound = balances.TryGetValue(key, out var balance);

                if (isBalanceFound && balance.Amount < balanceWarning.MinBalance ||
                    !isBalanceFound && balanceWarning.MinBalance > 0)
                {
                    balanceIssues.Add(new ExternalBalanceIssueDto
                    {
                        Exchange   = balanceWarning.Exchange,
                        AssetId    = balanceWarning.AssetId,
                        Name       = balanceWarning.Name,
                        AssetName  = balanceWarning.AssetName,
                        Balance    = balance?.Amount ?? 0,
                        MinBalance = balanceWarning.MinBalance
                    });
                }
            }

            return(balanceIssues);
        }
 public async Task <IReadOnlyList <IExternalBalanceWarning> > GetExternalBalancesWarningsAsync()
 {
     return(await _externalBalanceWarningRepository.GetExternalBalancesWarnings());
 }