Exemple #1
0
        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();

                var healths = Pull <BittrexResponse <List <BittrexCurrencyHealth> > >(HealthUrl, session);

                ParallelFor(prices, bc =>
                {
                    var health = healths?.result?.FirstOrDefault(h => h.Currency.Currency == bc.To);

                    //request last minute and daily ticker
                    var responseMinute =
                        Pull <BittrexResponse <List <BittrexTicker> > >(string.Format(MinutePriceUrl, bc.From, bc.To), session);
                    //var responseDaily = Pull<BittrexResponse<BittrexTicker>>(string.Format(DailyPriceUrl, bc.From, bc.To)).Result;

                    if (responseMinute.success && responseMinute.result.Count > 0)
                    {
                        var data = responseMinute.result[0];
                        //var dataDaily = responseDaily.result[0];
                        if (data != null /*&& dataDaily != null*/)
                        {
                            var job = new PriceUpdaterJob(bc.Id, data.C, data.V, 1)
                                      .UpdatePriceData(data.O, data.H, data.L, data.C);
                            if (health != null)
                            {
                                job.UpdateHealth(health.Health.IsActive && health.Health.MinutesSinceBHUpdated <= 30,
                                                 health.Health.IsActive && health.Health.MinutesSinceBHUpdated <= 30);
                            }
                            DatabaseService.Enqueue(job);
                            //.UpdatePrice24Data(dataDaily.O, dataDaily.H, dataDaily.L, dataDaily.C));
                            DatabaseService.Enqueue(new UsdGeneratorJob(ExchangeId, bc.FromId, bc.ToId, bc.Price));
                        }
                    }
                    else
                    {
                        Console.WriteLine("Could not pull {0}-{1} from {2}: {3}", bc.To, bc.From, Name, responseMinute.message);
                    }
                }).Wait();
            }
        }
Exemple #3
0
        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 =>
                {
                    //request last minute and daily ticker

                    var responsePrice = Pull <GdaxTicker>(string.Format(PriceUrl, bc.To, bc.From), session);
                    //var responseVolume = Pull<JArray[]>(string.Format(VolumeUrl, bc.To, bc.From)).Result;

                    var job = new PriceUpdaterJob(bc.Id, Convert.ToDecimal(responsePrice.last));
                    //if (responseVolume.Length > 0)
                    //{
                    //  var data = responseVolume[0];
                    //var mv = Convert.ToDecimal(data.Last.Value<string>());
                    var dv  = Convert.ToDecimal(responsePrice.volume);
                    var dbv = 0;
                    //job.UpdateVolume(mv, 1);
                    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();
            }
        }
        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();


                var response = Pull <JObject>(MarketPriceUrl, session);
                var healths  = Pull <JObject>(HealthUrl, session);
                foreach (var obj in response.Children <JProperty>())
                {
                    var from_to       = obj.Name.Split("_");
                    var from          = from_to[0];
                    var to            = from_to[1];
                    var ticker        = obj.Value.ToObject <PoloniexTicker>();
                    var borsaCurrency = prices.FirstOrDefault(bc => bc.From == from && bc.To == to);
                    if (borsaCurrency != null)
                    {
                        var health = healths?.Children <JProperty>().FirstOrDefault(h => h.Name == borsaCurrency.To)?.Value.ToObject <PoloniexHealth>();

                        var job = new PriceUpdaterJob(borsaCurrency.Id, Convert.ToDecimal(ticker.last), 0,
                                                      1, Convert.ToDecimal(ticker.baseVolume), Convert.ToDecimal(ticker.quoteVolume))
                                  .UpdatePrice24Data(0, Convert.ToDecimal(ticker.high24hr), Convert.ToDecimal(ticker.low24hr), 0);

                        if (health != null)
                        {
                            job.UpdateHealth(health.frozen == 0 && health.disabled == 0, health.frozen == 0 && health.disabled == 0);
                        }
                        DatabaseService.Enqueue(job);
                        DatabaseService.Enqueue(new UsdGeneratorJob(ExchangeId, borsaCurrency.FromId, borsaCurrency.ToId, borsaCurrency.Price));
                    }
                }
            }
        }
Exemple #5
0
        private async Task OnPullingPrices(PullerSession session)
        {
            var response = Pull <List <HitbtcTicker> >(PriceUrl, 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();

                var healths = Pull <List <HitbtcHealth> >(HealthUrl, session);
                ParallelFor(prices, bc =>
                {
                    var health = healths?.FirstOrDefault(h => h.id == bc.To);
                    var key    = bc.To + bc.From;
                    var market = response.FirstOrDefault(d => d.symbol == key);
                    if (market != null)
                    {
                        var job = new PriceUpdaterJob(bc.Id, Convert.ToDecimal(market.last))
                                  .UpdateVolume24(Convert.ToDecimal(market.volume),
                                                  Convert.ToDecimal(market.volumeQuote));

                        if (health != null)
                        {
                            job.UpdateHealth(health.transferEnabled && health.payinEnabled, health.transferEnabled && health.payoutEnabled);
                        }

                        //var responseVolume = Pull<List<HitbtcCandle>>(string.Format(VolumeUrl, key)).Result;
                        //if (responseVolume.Count > 0)
                        //    job.UpdateVolume(Convert.ToDecimal(responseVolume[0].volume), 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();
            }
        }