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)); }
/// <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)); }
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)); } }
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)); }
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)); }
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)); }
public string RemotePairOrNull(IDescribesAssets provider) { return(HasPair ? Pair.ToTicker(provider) : null); }
public string ToTicker(IDescribesAssets converter, char separator) { return(separator == '\0' ? $"{Asset1.ToRemoteCode(converter)}{Asset2.ToRemoteCode(converter)}" : $"{Asset1.ToRemoteCode(converter)}{separator}{Asset2.ToRemoteCode(converter)}"); }
public string ToTicker(IDescribesAssets converter) { var separator = converter.CommonPairSeparator ?? '\0'; return(ToTicker(converter, separator)); }
public string ToTicker(IDescribesAssets converter, string separator) { return(separator == string.Empty ? ToTicker(converter, '\0') : $"{Asset1.ToRemoteCode(converter)}{separator}{Asset2.ToRemoteCode(converter)}"); }
public AssetPair(string asset, string quote, IDescribesAssets provider) : this(Assets.I.Get(asset, provider), Assets.I.Get(quote, provider)) { }
public static AssetPair ToAssetPair(this string pair, IDescribesAssets provider) { var delimiter = provider.CommonPairSeparator ?? '_'; return(pair.ToAssetPair(provider, delimiter)); }