Beispiel #1
0
        /// <summary>
        /// this pair must be confirmed with ticker or assetpairs to be valid
        /// </summary>
        /// <param name="_base"></param>
        /// <param name="_quote"></param>
        /// <returns></returns>
        public static string ToPairString(Kraken.Asset _base, Kraken.Asset _quote)
        {
            string sbase  = _base.GetEnumName();
            string squote = _quote.GetEnumName();

            if (sbase.IsNullOrEmpty() || squote.IsNullOrEmpty())
            {
                return(null);
            }

            if (Kraken.IsCurrency(_base))
            {
                sbase = "Z" + sbase;
            }
            else if (Kraken.IsCryptocurrency(_base))
            {
                sbase = "X" + sbase;
            }

            if (Kraken.IsCurrency(_quote))
            {
                squote = "Z" + squote;
            }
            else if (Kraken.IsCryptocurrency(_quote))
            {
                squote = "X" + squote;
            }

            return(sbase + squote);
        }
Beispiel #2
0
 public static bool IsCurrency(this Asset asset)
 {
     if (asset == null)
     {
         return(false);
     }
     return(Kraken.IsCurrency(asset.GetEnumName()));
 }
Beispiel #3
0
        public static bool IsAsset(string value)
        {
            if (Kraken.IsCryptocurrency(value) || Kraken.IsCurrency(value))
            {
                return(true);
            }

            return(false);
        }
Beispiel #4
0
        /// <summary>
        /// returns unit value (ask) of asset in units of specified currency
        /// </summary>
        /// <param name="tickers"></param>
        /// <param name="_asset"></param>
        /// <param name="_currency"></param>
        /// <returns></returns>
        public static decimal?GetValueInCurrency(this Ticker[] tickers, Kraken.Asset _asset, Kraken.Currency _currency, decimal assetAmount = 1)
        {
            if (tickers == null || tickers.Length <= 0)
            {
                return(null);
            }

            if (_asset == Kraken.ToAsset(_currency))
            {
                return(1);
            }

            if (Kraken.IsCurrency(_asset))
            {
                decimal?ask1 = tickers.GetValueInCurrency(Kraken.Asset.XBT, Kraken.ToCurrency(_asset), 1);
                decimal?ask2 = tickers.GetValueInCurrency(Kraken.Asset.XBT, _currency, 1);
                if (ask1.IsNull() || ask2.IsNull())
                {
                    return(null);
                }

                return((decimal)ask2.Value / ask1.Value);
            }

            Kraken.Asset acurrency = Kraken.ToAsset(_currency);
            Ticker       ticker    = tickers.GetAny(_asset, acurrency);

            if (ticker == null)
            {
                return(null);
            }

            if (ticker.IsBase(_asset) && ticker.IsQuote(acurrency))
            {
                return(ticker.Ask[0] * assetAmount);
            }
            else if (ticker.IsBase(acurrency) && ticker.IsQuote(_asset))
            {
                return(((decimal)1 / ticker.Ask[0]) * assetAmount);
            }

            return(null);
        }
Beispiel #5
0
        public static Currency[] ToCurrency(Asset[] values)
        {
            if (values == null)
            {
                return(null);
            }

            List <Currency> results = new List <Currency>();

            foreach (Asset a in values)
            {
                string name = a.GetEnumName();

                if (Kraken.IsCurrency(a))
                {
                    results.Add(Kraken.ToCurrency(a));
                }
            }

            return(results.ToArray());
        }