Beispiel #1
0
        public async Task <ConcurrentBag <CryptsyMarketInfo> > GetOpenMarkets(bool basicInfoOnly = false, CancellationToken token = default(CancellationToken))
        {
            return(await RetryHelper.DoAsync(async() =>
            {
                CryptsyResponse answer = await CryptsyPublicQuery(new Dictionary <string, string> {
                    { "method", "marketdatav2" }
                }, false, token);

                return answer.Success ? CryptsyMarketInfo.ReadMultipleFromJObject(answer.Data as JObject, basicInfoOnly) : null;
            }, TimeSpan.FromMilliseconds(Constant.DefaultRetryInterval)));
        }
Beispiel #2
0
        public async Task <CryptsyMarketInfo> GetMarketInfo(long marketId, CancellationToken token = default(CancellationToken))
        {
            return(await RetryHelper.DoAsync(async() =>
            {
                var args = new Dictionary <string, string>
                {
                    { "marketid", Convert.ToString(marketId) },
                    { "method", "singlemarketdata" }
                };

                CryptsyResponse answer = await CryptsyPublicQuery(args, false, token);

                return answer.Success ? CryptsyMarketInfo.ReadMultipleFromJObject(answer.Data as JObject).SingleOrDefault() : null;
            }, TimeSpan.FromMilliseconds(Constant.DefaultRetryInterval)));
        }
Beispiel #3
0
        //Set basicInfoOnly=true to skip recent trades & top 20 buy and sell orders
        public ConcurrentBag <CryptsyMarketInfo> GetOpenMarketsPeriodically(CryptsyMarket[] markets, bool basicInfoOnly = false)
        {
            var resultList = new ConcurrentBag <CryptsyMarketInfo>();

            var options = new ParallelOptions {
                MaxDegreeOfParallelism = Environment.ProcessorCount * 50
            };
            int marketCounts = markets.Length;

            var sw = new Stopwatch();

            sw.Start();

            Parallel.For(1, marketCounts,
                         options,
                         () => new Tuple <CryptsyResponse>(new CryptsyResponse()),
                         (i, pls, state) =>
            {
                try
                {
                    CryptsyResponse answer = CryptsyPublicQuery(new Dictionary <string, string> {
                        { "method", "singlemarketdata" }, { "marketid", Convert.ToString(markets[i - 1].MarketId) }
                    }, i % 2 == 0).Result;
                    state = new Tuple <CryptsyResponse>(answer);
                }
                catch
                {
                    state = new Tuple <CryptsyResponse>(null);
                }
                return(state);
            },
                         state =>
            {
                if (state.Item1 != null && state.Item1.Success && state.Item1.Data is JObject)
                {
                    var data = CryptsyMarketInfo.ReadMultipleFromJObject((JObject)state.Item1.Data, basicInfoOnly);
                    data.ToList().ForEach(resultList.Add);
                }
            });
            sw.Stop();

            return(resultList);
        }
Beispiel #4
0
        /* Returns marketinfo for the market for these two currencies (order doesn't matter)
         * Returns null if no market was found with these currencies
         * If basicInfoOnly = true, recent trades and top orders will not be loaded
         */
        public async Task <CryptsyMarketInfo> GetMarketInfo(string currencyCode1, string currencyCode2, bool basicInfoOnly = false, CancellationToken token = default(CancellationToken))
        {
            return(await RetryHelper.DoAsync(async() =>
            {
                if (_marketInfos == null)
                {
                    _marketInfos = await GetOpenMarkets(true, token);//Don't load recent trades and orderbook for all markets
                }

                currencyCode1 = currencyCode1.ToUpper();
                currencyCode2 = currencyCode2.ToUpper();
                CryptsyMarketInfo market = _marketInfos.FirstOrDefault(m => currencyCode1 == m.PrimaryCurrencyCode && currencyCode2 == m.SecondaryCurrencyCode || currencyCode2 == m.PrimaryCurrencyCode && currencyCode1 == m.SecondaryCurrencyCode);

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

                return basicInfoOnly ? market : await GetMarketInfo(market.MarketId, token); //Get all info from the requested market
            }, TimeSpan.FromMilliseconds(Constant.DefaultRetryInterval)));
        }