Exemplo n.º 1
0
        public List <PriceHistoryDay> PriceHistory(int appId, string hashName)
        {
            var url = Urls.Market + $"/pricehistory/?appid={appId}&market_hash_name={Uri.EscapeDataString(hashName)}";

            var resp = this.steam.Request(url, Method.GET, Urls.Market, null, true, proxy: this.Proxy);

            var respDes = JsonConvert.DeserializeObject <JPriceHistory>(resp.Data.Content);

            if (!respDes.Success)
            {
                throw new SteamException($"Cannot get price history for [{hashName}]");
            }

            IEnumerable <dynamic> prices = Enumerable.ToList(respDes.Prices);

            var list = prices.Select(
                (g, index) =>
            {
                var count = 0;
                if (g[2] != null && !int.TryParse(g[2].ToString(), out count))
                {
                    throw new SteamException($"Cannot parse items count in price history. Index: {index}");
                }

                double price = 0;
                if (g[1] != null && !double.TryParse(g[1].ToString(), out price))
                {
                    throw new SteamException($"Cannot parse item price in price history. Index: {index}");
                }

                return(new PriceHistoryItem
                {
                    DateTime = MarketUtils.SteamTimeConvertor(g[0].ToString()),
                    Count = count,
                    Price = Math.Round(price, 2)
                });
            }).GroupBy(x => x.DateTime.Date).Select(
                g => new PriceHistoryDay {
                Date = g.Key, History = g.Select(p => p).ToList()
            }).ToList();

            return(list);
        }