示例#1
0
        public async Task <EmdItemPrices> GetItemPricesAsync(int regionId, int stationId, IEnumerable <int> types)
        {
            var prices = new EmdItemPrices();

            prices.Prices = new EveMarketDataRowCollection <EmdItemPrices.ItemPriceEntry>();
            var options = new EveMarketDataOptions();

            if (stationId > 0)
            {
                options.Stations.Add(stationId);
            }
            else if (regionId > 0)
            {
                options.Regions.Add(regionId);
            }
            foreach (int typeId in types)
            {
                options.Items.Add(typeId);
                if (options.Items.Count >= 1000)
                {
                    var result = (await _eveMarketData.GetItemPriceAsync(options, OrderType.Both).ConfigureAwait(false)).Result;
                    result.Prices.Apply(item => prices.Prices.Add(item));
                    options.Items.Clear();
                }
            }
            var finalResult = (await _eveMarketData.GetItemPriceAsync(options, OrderType.Both).ConfigureAwait(false)).Result;

            finalResult.Prices.Apply(item => prices.Prices.Add(item));
            return(prices);
        }
示例#2
0
        public async Task UpdateMarketData(IEnumerable <AssetVm> list, int region, int station, int days)
        {
            List <int>    items       = list.Select(asset => asset.TypeId).ToList();
            EmdItemPrices priceResult =
                await _marketService.GetItemPricesAsync(region, station, items).ConfigureAwait(false);

            IEnumerable <MarketHistoryEntry> historyResult =
                await _marketService.GetItemHistoryAsync(region, items, days).ConfigureAwait(false);

            ILookup <int, EmdItemPrices.ItemPriceEntry> priceLookup   = priceResult.Prices.ToLookup(i => i.TypeId);
            ILookup <int, MarketHistoryEntry>           historyLookup = historyResult.ToLookup(i => i.TypeId);

            foreach (AssetVm asset in list)
            {
                decimal buyPrice =
                    priceLookup[asset.TypeId].Single(price => price.OrderType == OrderType.Buy).Price;
                decimal sellPrice =
                    priceLookup[asset.TypeId].Single(price => price.OrderType == OrderType.Sell).Price;
                asset.Update(historyLookup[asset.TypeId], sellPrice, buyPrice);
            }
        }