public async Task <IEnumerable <Pair> > GetSupportedPairs(CancellationToken token = default(CancellationToken))
        {
            return(await RetryHelper.DoAsync(async() =>
            {
                var data = await GetTickers(token);

                var results = data.ToList().Select(x =>
                {
                    var pairs = x.PairStr.Split('_');

                    var supported = SupportedCurrencyHelper.GetSupportedCurrencies();

                    var inCurrency = supported.FirstOrDefault(curency => curency == pairs[0].ToUpper());
                    var outCurrency = supported.FirstOrDefault(curency => curency == pairs[1].ToUpper());

                    if (inCurrency != null && outCurrency != null)
                    {
                        return new Pair(inCurrency, outCurrency);
                    }

                    return null;
                });

                return results.Where(n => n != null).Distinct().ToList();
            }, TimeSpan.FromMilliseconds(Constant.DefaultRetryInterval), 1));
        }
        public async Task <List <Pair> > GetPairs(CancellationToken token = default(CancellationToken))
        {
            return(await RetryHelper.DoAsync(async() =>
            {
                JArray jArray = await JObjectQuery(_baseUri.AbsoluteUri + $"v{Version}/symbols", token);

                return jArray.Select(x =>
                {
                    var data = x.ToString().ToChunks(3);

                    if (data.Length > 1)
                    {
                        var supported = SupportedCurrencyHelper.GetSupportedCurrencies();

                        var inCurrency = supported.FirstOrDefault(curency => curency == data[0].ToUpper());
                        var outCurrency = supported.FirstOrDefault(curency => curency == data[1].ToUpper());

                        if (inCurrency != null && outCurrency != null)
                        {
                            return new Pair(inCurrency, outCurrency);
                        }
                    }

                    return null;
                }).Where(x => x != null).ToList();
            }, TimeSpan.FromMilliseconds(Constant.DefaultRetryInterval)));
        }
        private void GetPair(string value)
        {
            var data = value.Split('_');

            if (data.Count() > 1)
            {
                var supported = SupportedCurrencyHelper.GetSupportedCurrencies();

                var inCurrency  = supported.FirstOrDefault(curency => curency == data[0].ToUpper());
                var outCurrency = supported.FirstOrDefault(curency => curency == data[1].ToUpper());

                if (inCurrency != null && outCurrency != null)
                {
                    Pair = new Pair(inCurrency, outCurrency);
                }
            }
        }
Exemplo n.º 4
0
        public async Task <IEnumerable <AccountChange> > GetAccountHoldings(CancellationToken token = default(CancellationToken))
        {
            return(await RetryHelper.WebDoAsync(async() =>
            {
                try
                {
                    JObject result = await QueryPrivate("Balance", null, token, RequestCategory.AccountHoldings);
                    var accountHoldings = result.ToObject <Dictionary <string, decimal> >();
                    var supportedCurrency = SupportedCurrencyHelper.GetSupportedCurrencies();
                    return accountHoldings.Where(x => supportedCurrency.Contains(String.Join(String.Empty, x.Key.Skip(1))))
                    .Select(ah => new AccountChange(ExchangeName.Kraken, FromKrakenCurrency(ah.Key), ah.Value)).ToArray();
                }
                catch (KrakenInvalidOrderException ex)
                {
                    //_log.Error(ex.Message, ex);
                }
                catch (KrakenRateLimitExceededException ex)
                {
                    IsRestartAfterTime = true;
                    //_log.Error(ex.Message, ex);
                }
                catch (KrakenInvalidKeyException ex)
                {
                    //_log.Error(ex.Message, ex);
                }
                catch (KrakenTemporaryLockOutException ex)
                {
                    IsRestartAfterTime = true;
                    //_log.Error(ex.Message, ex);
                }
                catch (KrakenInvalidNonceException ex)
                {
                    //_log.Error(ex.Message, ex);
                }
                catch (KrakenInsufficientFundsException ex)
                {
                    //_log.Error(ex.Message, ex);
                }

                return null;
            }, TimeSpan.FromMilliseconds(Constant.KrakenRetryInterval)));
        }