Esempio n. 1
0
        public static AssetPair ToAssetPair(this string pair, IDescribesAssets provider, char delimiter)
        {
            if (string.IsNullOrWhiteSpace(pair) || pair.IndexOf(delimiter) == -1)
            {
                return(AssetPair.Empty);
            }

            var p = pair.Split(delimiter);

            return(p.Length != 2 ? AssetPair.Empty : new AssetPair(p[0], p[1], provider));
        }
Esempio n. 2
0
        /// <summary>
        /// Creates asset pair from string basing on base asset length.
        /// </summary>
        /// <param name="pair">Asset pair code.</param>
        /// <param name="provider">Asset code converter.</param>
        /// <param name="firstAssetLength">The length of base asset.</param>
        /// <returns>Asset pair from specified string.</returns>
        public static AssetPair ToAssetPair(this string pair, IDescribesAssets provider, int firstAssetLength)
        {
            if (string.IsNullOrWhiteSpace(pair) || firstAssetLength < 1 || firstAssetLength > pair.Length - 1)
            {
                return(AssetPair.Empty);
            }

            var assetCode1 = pair.Substring(0, firstAssetLength);
            var assetCode2 = pair.Replace(assetCode1, "");

            return(new AssetPair(assetCode1, assetCode2, provider));
        }
Esempio n. 3
0
        public AssetPairs(int length, string csv, IDescribesAssets provider)
        {
            foreach (var i in csv.ToCsv(true))
            {
                if (i.Length != length * 2)
                {
                    continue;
                }

                var c1 = i.Substring(0, length);
                var c2 = i.Substring(length);
                _pairs.Add(new AssetPair(c1, c2, provider));
            }
        }
Esempio n. 4
0
        public static string ToRemoteCode(this Asset asset, IDescribesAssets provider)
        {
            if (provider == null)
            {
                throw new ArgumentException(nameof(provider));
            }

            var cv = provider.GetAssetCodeConverter();

            if (cv == null)
            {
                return(asset.ShortCode);
            }

            return(ToRemoteCode(asset, cv));
        }
Esempio n. 5
0
        public static Asset ToAsset(this string assetCode, IDescribesAssets provider)
        {
            if (provider == null)
            {
                throw new ArgumentException(nameof(provider));
            }

            var cv = provider.GetAssetCodeConverter();

            if (cv == null)
            {
                return(Assets.I.Get(assetCode, provider));
            }

            return(Assets.I.Get(cv.ToLocalCode(assetCode), provider));
        }
Esempio n. 6
0
        public Asset Get(string assetCode, IDescribesAssets provider)
        {
            if (string.IsNullOrWhiteSpace(assetCode))
            {
                return(Asset.None);
            }

            if (provider == null)
            {
                throw new ArgumentException(nameof(provider));
            }

            var cv = provider.GetAssetCodeConverter();

            if (cv == null)
            {
                return(GetRaw(assetCode));
            }

            assetCode = cv.ToLocalCode(assetCode);

            return(_cache.GetOrAdd(assetCode, Asset.InstanceRaw));
        }
Esempio n. 7
0
 public string RemotePairOrNull(IDescribesAssets provider)
 {
     return(HasPair ?  Pair.ToTicker(provider) : null);
 }
Esempio n. 8
0
 public string ToTicker(IDescribesAssets converter, char separator)
 {
     return(separator == '\0' ?
            $"{Asset1.ToRemoteCode(converter)}{Asset2.ToRemoteCode(converter)}" :
            $"{Asset1.ToRemoteCode(converter)}{separator}{Asset2.ToRemoteCode(converter)}");
 }
Esempio n. 9
0
        public string ToTicker(IDescribesAssets converter)
        {
            var separator = converter.CommonPairSeparator ?? '\0';

            return(ToTicker(converter, separator));
        }
Esempio n. 10
0
 public string ToTicker(IDescribesAssets converter, string separator)
 {
     return(separator == string.Empty ?
            ToTicker(converter, '\0') :
            $"{Asset1.ToRemoteCode(converter)}{separator}{Asset2.ToRemoteCode(converter)}");
 }
Esempio n. 11
0
 public AssetPair(string asset, string quote, IDescribesAssets provider) : this(Assets.I.Get(asset, provider), Assets.I.Get(quote, provider))
 {
 }
Esempio n. 12
0
        public static AssetPair ToAssetPair(this string pair, IDescribesAssets provider)
        {
            var delimiter = provider.CommonPairSeparator ?? '_';

            return(pair.ToAssetPair(provider, delimiter));
        }