Ejemplo n.º 1
0
        public static Currency?ToCurrency(Asset?value)
        {
            if (value == null || !value.HasValue)
            {
                return(null);
            }

            return(Kraken.ToCurrency(value.GetEnumName()));
        }
Ejemplo n.º 2
0
        public Kraken.Currency[] AvailableCurrency()
        {
            var balances = this.AvailableBalances();

            if (balances.IsNullOrEmpty())
            {
                return(null);
            }

            string[] keys = Balances.Keys.ToArray();
            List <Kraken.Currency> result = new List <Kraken.Currency>();

            foreach (var b in balances)
            {
                result.AddIfValueIsNotNull(Kraken.ToCurrency(b.AssetName));
            }

            return(result.ToArray());
        }
Ejemplo n.º 3
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);
        }
Ejemplo n.º 4
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());
        }
Ejemplo n.º 5
0
 public static Currency ToCurrency(Asset value)
 {
     return(Kraken.ToCurrency(value.GetEnumName()).Value);
 }
Ejemplo n.º 6
0
 public Kraken.Currency[] TradableCurrency(string _sasset)
 {
     return(Kraken.ToCurrency(TradableAsset(_sasset)));
 }