Exemplo n.º 1
0
        public AssetPairInfo GetAssetPairInfo(string assetPairId)
        {
            AssetPair assetPair = _assetPairsService.TryGetIfEnabled(assetPairId);

            if (assetPair == null)
            {
                throw new Exception($"AssetService have returned null for asset pair {assetPairId}");
            }

            Asset baseAsset = _assetsService.TryGet(assetPair.BaseAssetId);

            if (baseAsset == null)
            {
                throw new Exception(
                          $"AssetService have returned null for base asset {assetPair.BaseAssetId} from pair {assetPairId}");
            }

            var assetLinks = _assetLinkService.GetAllAsync().GetAwaiter().GetResult();

            return(new AssetPairInfo
            {
                AssetPairId = assetPairId,
                DisplayName = assetPair.Name,
                MinVolume = assetPair.MinVolume,
                PriceAccuracy = assetPair.Accuracy,
                VolumeAccuracy = baseAsset.Accuracy,
                BaseAssetId = assetLinks.SingleOrDefault(x => x.ExternalAssetId == assetPair.BaseAssetId)?.AssetId ?? assetPair.BaseAssetId,
                QuoteAssetId = assetLinks.SingleOrDefault(x => x.ExternalAssetId == assetPair.QuotingAssetId)?.AssetId ?? assetPair.QuotingAssetId
            });
        }
Exemplo n.º 2
0
        public async Task UpdateBalancesAsync()
        {
            string walletId = _settingsService.GetWalletId();

            if (string.IsNullOrEmpty(walletId))
            {
                return;
            }

            try
            {
                IEnumerable <ClientBalanceResponseModel> exchangeBalances =
                    await _balancesClient.GetClientBalances(walletId);

                IDictionary <string, AssetLink> assetMap = (await _assetLinkService.GetAllAsync())
                                                           .ToDictionary(o => o.ExternalAssetId, o => o);

                IReadOnlyCollection <Balance> balances = exchangeBalances
                                                         .Select(exchangeBalance =>
                {
                    string assetId = assetMap.TryGetValue(exchangeBalance.AssetId, out AssetLink assetLink)
                            ? assetLink.AssetId
                            : exchangeBalance.AssetId;

                    return(new Balance(assetId, exchangeBalance.Balance, exchangeBalance.Reserved));
                })
                                                         .ToArray();

                LogChangedBalances(balances);

                _cache.Set(balances);
            }
            catch (Exception exception)
            {
                _log.Error(exception, "An error occurred while getting balances from Lykke exchange.");
            }
        }