예제 #1
0
        private double GetCrossPairsAmountInBase(
            string assetFrom,
            double amount,
            string assetTo,
            Dictionary <string, NodeInfo> pricesData)
        {
            if (assetFrom == assetTo)
            {
                return(amount);
            }

            if (Math.Abs(amount) < double.Epsilon)
            {
                return(0);
            }

            var convertedAmount = _crossPairsCalculator.Convert(
                assetFrom,
                assetTo,
                amount,
                pricesData);

            var toAsset = _assetsReadModelRepository.TryGet(assetTo);

            if (toAsset == null)
            {
                _log.WriteWarning(nameof(GetCrossPairsAmountInBase), assetFrom, $"Couldn't find asset by id = {assetTo}");
                return(convertedAmount);
            }
            return(convertedAmount.TruncateDecimalPlaces(toAsset.Accuracy));
        }
예제 #2
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
            });
        }
 private void InitializeAssetsDisplayIds()
 {
     foreach (var assetId in _assetIdsPublicApi.Keys.ToList())
     {
         var asset = _assetsReadModelRepository.TryGet(assetId);
         if (asset != null)
         {
             _assetIdsDisplayIds[assetId] = asset.DisplayId;
         }
         else
         {
             _assetIdsDisplayIds[assetId] = _cryptoIndexServiceClientInstancesSettings.Instances
                                            .Single(x => x.AssetId == assetId).IndexName;
             _log.Warning($"Did not find assetId '{assetId}' in the Assets Service. Assigned 'IndexName' from the settings.");
         }
     }
 }
예제 #4
0
        /// <summary>
        /// Get the asset if it is enabled. Returns null, if the asset is disabled.
        /// </summary>
        public static Asset TryGetIfEnabled(this IAssetsReadModelRepository readModelRepository, string id)
        {
            var asset = readModelRepository.TryGet(id);

            return(asset != null && !asset.IsDisabled ? asset : null);
        }