private async Task OnPullingPrices(PullerSession session) { using (var db = DatabaseService.CreateContext()) { //get all prices from db var prices = db.BorsaCurrencyT .Where(bc => bc.BorsaId == ExchangeId && !bc.Disabled && bc.AutoGenerated != true) .Select(bc => new { Id = bc.Id, FromId = bc.FromCurrencyId, From = bc.FromCurrencyName, ToId = bc.ToCurrencyId, To = bc.ToCurrencyName, Price = bc.Price, }).ToList(); int i = 0; ParallelFor(prices, bc => { var responsePrice = Pull <KucoinResponse <List <List <object> > > >(string.Format(PriceUrl, bc.To, bc.From), session); var last = responsePrice.data.Last(); var job = new PriceUpdaterJob(bc.Id, Convert.ToDecimal(last[2])); var mv = Convert.ToDecimal(last[3]); job.UpdateVolume(mv, 1); DatabaseService.Enqueue(job); DatabaseService.Enqueue(new UsdGeneratorJob(ExchangeId, bc.FromId, bc.ToId, bc.Price)); }).Wait(); } }
private async Task OnPullingPrices(PullerSession session) { using (var db = DatabaseService.CreateContext()) { //get all prices from db var prices = db.BorsaCurrencyT .Where(bc => bc.BorsaId == ExchangeId && !bc.Disabled && bc.AutoGenerated != true) .Select(bc => new { Id = bc.Id, FromId = bc.FromCurrencyId, From = bc.FromCurrencyName, ToId = bc.ToCurrencyId, To = bc.ToCurrencyName, Price = bc.Price, }).ToList(); int i = 0; var response = Pull <List <BinancePrice> >(PriceUrl, session); var healths = Pull <List <BinanceHealth> >(HealthUrl, session); ParallelFor(prices, bc => { var health = healths?.FirstOrDefault(h => h.assetCode == bc.To); var symbol = bc.To + bc.From; var foundPrice = response.FirstOrDefault(p => p.symbol == symbol); if (foundPrice != null) { var job = new PriceUpdaterJob(bc.Id, Convert.ToDecimal(foundPrice.price)); if (health != null) { job.UpdateHealth(health.enableCharge, health.enableWithdraw); } //request last minute and daily ticker var responseMinute = Pull <JArray[]>(string.Format(MinuteVolumeUrl, symbol), session); //var responseDaily = Pull<JArray[]>(string.Format(DailyVolumeUrl, symbol)).Result; if (responseMinute.Length > 0) { var minuteData = responseMinute[0]; //var dailyData = responseDaily[0]; var mv = Convert.ToDecimal(minuteData[5].Value <string>()); //var dv = Convert.ToDecimal(dailyData[5].Value<string>()); //var dbv = Convert.ToDecimal(dailyData[7].Value<string>()); //var open = Convert.ToDecimal(dailyData[1].Value<string>()); //var high = Convert.ToDecimal(dailyData[2].Value<string>()); //var low = Convert.ToDecimal(dailyData[3].Value<string>()); //var close = Convert.ToDecimal(dailyData[4].Value<string>()); job.UpdateVolume(mv, 1); //job.UpdatePriceData(open, high, low, close); //job.UpdateVolume24(dv, dbv); } else { Console.WriteLine(string.Format("Could not pull {0}-{1} volume from {2}: List was empty", bc.To, bc.From, Name)); } DatabaseService.Enqueue(job); DatabaseService.Enqueue(new UsdGeneratorJob(ExchangeId, bc.FromId, bc.ToId, bc.Price)); } }).Wait(); } }