Exemple #1
0
        private async Task OnPullingOrders(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();

                ParallelFor(prices, bc =>
                {
                    var key            = bc.To + bc.From;
                    var responseOrders = Pull <HitbtcOrders>(string.Format(OrderUrl, key), session);
                    DatabaseService.Enqueue(new OrderUpdaterJob(bc.Id)
                                            .UpdateBuy(responseOrders.bid.Take(10).ToList(), c => Convert.ToDecimal(c.price), c => Convert.ToDecimal(c.size))
                                            .UpdateSell(responseOrders.ask.Take(10).ToList(), c => Convert.ToDecimal(c.price), c => Convert.ToDecimal(c.size)));
                }).Wait();
            }
        }
        private async Task OnPullingMarkets(PullerSession session)
        {
            var response = Pull <List <BinancePrice> >(PriceUrl, session);

            using (var db = DatabaseService.CreateContext())
            {
                //get all prices from db
                var prices = db.BorsaCurrencyT
                             .Include(bc => bc.FromCurrency).Include(bc => bc.ToCurrency)
                             .Where(bc => bc.BorsaId == ExchangeId)
                             .ToList();

                //get markets
                foreach (var market in response)
                {
                    var isUsdt = market.symbol.EndsWith("USDT");
                    var from   = market.symbol.Substring(market.symbol.Length - (isUsdt ? 4 : 3));
                    var to     = market.symbol.Substring(0, market.symbol.Length - (isUsdt ? 4 : 3));

                    new MarketUpdaterJob(ExchangeId, from, to, true, prices).Execute(db);
                }
                new MarketUpdaterJob(prices).Execute(db);

                db.SaveChanges();
            }
        }
Exemple #3
0
        private async Task OnPullingCurrencies(PullerSession session)
        {
            var response = Pull <KucoinResponse <List <KucoinMarket> > >(MarketUrl, session);

            //get coin names
            var coinNames = response.data.SelectMany(p =>
            {
                var from = p.coinTypePair;
                var to   = p.coinType;
                return(new List <string>()
                {
                    from, to
                });
            }).Where(c => !string.IsNullOrEmpty(c))
                            .Distinct()
                            .ToList();

            foreach (var coin in coinNames)
            {
                DatabaseService.Enqueue(new CurrencyUpdaterJob(
                                            ExchangeId,
                                            coin,
                                            coin,
                                            true,
                                            null));
            }
        }
Exemple #4
0
        private async Task OnPullingHealth(PullerSession session)
        {
            ConcurrentDictionary <string, KucoinResponse <KucoinHealth> > cache = new ConcurrentDictionary <string, KucoinResponse <KucoinHealth> >();

            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,
                    To = bc.ToCurrencyName,
                }).ToList();
                int i = 0;

                ParallelFor(prices, bc =>
                {
                    KucoinResponse <KucoinHealth> health = cache.GetOrAdd(bc.To,
                                                                          s => Pull <KucoinResponse <KucoinHealth> >(string.Format(HealthUrl, bc.To), session));

                    if (health != null)
                    {
                        DatabaseService.Enqueue(new PriceUpdaterJob(bc.Id)
                                                .DontUpdateDate()
                                                .UpdateHealth(health.data.enableDeposit, health.data.enableWithdraw));
                    }
                }).Wait();
            }
        }
Exemple #5
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;


                Parallel.ForEach(prices, bc =>
                {
                    var response = Pull <JToken>(string.Format(PriceUrl, bc.To.ToLower(), bc.From.ToLower()), session);
                    var data     = response.Children <JProperty>().First().Value.ToObject <YobitTicker>();

                    DatabaseService.Enqueue(new PriceUpdaterJob(bc.Id, data.last).UpdateVolume24(data.vol, data.vol_cur));
                    DatabaseService.Enqueue(new UsdGeneratorJob(ExchangeId, bc.FromId, bc.ToId, bc.Price));
                });
            }
        }
Exemple #6
0
        private async Task OnPullingOrders(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();


                ParallelFor(prices, bc =>
                {
                    var responseOrders = Pull <KucoinResponse <KucoinOrders> >(string.Format(OrderUrl, bc.To, bc.From), session);
                    DatabaseService.Enqueue(new OrderUpdaterJob(bc.Id)
                                            .UpdateBuy(responseOrders.data.BUY, c => c[0], c => c[1])
                                            .UpdateSell(responseOrders.data.SELL, c => c[0], c => c[1]));
                }).Wait();
            }
        }
        private async Task OnPullingMarkets(PullerSession session)
        {
            var response = Pull <List <string> >(MarketUrl, session);

            using (var db = DatabaseService.CreateContext())
            {
                //get all prices from db
                var prices = db.BorsaCurrencyT
                             .Include(bc => bc.FromCurrency).Include(bc => bc.ToCurrency)
                             .Where(bc => bc.BorsaId == ExchangeId)
                             .ToList();

                //get markets
                foreach (var market in response)
                {
                    var from = market.Substring(3).ToUpper();
                    var to   = market.Substring(0, 3).ToUpper();

                    new MarketUpdaterJob(ExchangeId, from, to, true, prices).Execute(db);
                }
                new MarketUpdaterJob(prices).Execute(db);

                db.SaveChanges();
            }
        }
        private async Task OnPullingCurrencies(PullerSession session)
        {
            var response = Pull <List <BinancePrice> >(PriceUrl, session);

            //get coin names
            var coinNames = response.SelectMany(p =>
            {
                var isUsdt = p.symbol.EndsWith("USDT");
                var from   = p.symbol.Substring(p.symbol.Length - (isUsdt ? 4 : 3));
                var to     = p.symbol.Substring(0, p.symbol.Length - (isUsdt ? 4 : 3));
                return(new List <string>()
                {
                    from, to
                });
            }).Where(c => !string.IsNullOrEmpty(c) && c != "123" && c != "456")
                            .Distinct()
                            .ToList();

            foreach (var coin in coinNames)
            {
                DatabaseService.Enqueue(new CurrencyUpdaterJob(
                                            ExchangeId,
                                            coin,
                                            coin,
                                            true,
                                            null));
            }
        }
        private async Task OnPullingOrders(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();

                ParallelFor(prices, bc =>
                {
                    var responseOrders = Pull <BittrexResponse <BittrexOrders> >(string.Format(OrderUrl, bc.From, bc.To), session);
                    DatabaseService.Enqueue(new OrderUpdaterJob(bc.Id)
                                            .UpdateBuy(responseOrders.result.buy.Take(10).ToList(), c => c.Rate, c => c.Quantity)
                                            .UpdateSell(responseOrders.result.sell.Take(10).ToList(), c => c.Rate, c => c.Quantity));
                }).Wait();
            }
        }
Exemple #10
0
        private async Task OnPullingCurrencies(PullerSession session)
        {
            var response = Pull <List <HitbtcMarket> >(MarketUrl, session);

            var coinNames = response.SelectMany(p =>
            {
                var from = p.quoteCurrency;
                var to   = p.baseCurrency;
                return(new List <string>()
                {
                    from, to
                });
            }).Distinct()
                            .ToList();

            foreach (var currency in coinNames)
            {
                DatabaseService.Enqueue(new CurrencyUpdaterJob(
                                            ExchangeId,
                                            currency,
                                            currency,
                                            true,
                                            null));
            }
        }
Exemple #11
0
        private async Task OnPullingMarkets(PullerSession session)
        {
            var response = Pull <BittrexResponse <List <BittrexMarketSummary> > >(MarketUrl, session);

            if (response.success)
            {
                using (var db = DatabaseService.CreateContext())
                {
                    //get all prices from db
                    var prices = db.BorsaCurrencyT
                                 .Include(bc => bc.FromCurrency).Include(bc => bc.ToCurrency)
                                 .Where(bc => bc.BorsaId == ExchangeId)
                                 .ToList();

                    foreach (var ms in response.result)
                    {
                        var from = ms.Market.BaseCurrency;
                        var to   = ms.Market.MarketCurrency;

                        new MarketUpdaterJob(ExchangeId, from, to, ms.Market.IsActive, prices).Execute(db);
                    }

                    new MarketUpdaterJob(prices).Execute(db);

                    db.SaveChanges();
                }
            }
            else
            {
                Console.WriteLine(string.Format("Could not pull currencies from {0}: {1}", Name, response.message));
            }
        }
Exemple #12
0
        private async Task OnPullingCurrencies(PullerSession session)
        {
            var response = Pull <YobitResponse>(CurrencyMarketUrl, session);


            //get coin names
            var coinNames = response.pairs.Children <JProperty>().SelectMany(p =>
            {
                var data   = p.Value.ToObject <YobitMarket>();
                var fromTo = p.Name.Split('_');
                var from   = fromTo[1].ToUpper();
                var to     = fromTo[0].ToUpper();
                return(new[] { Tuple.Create(from, data.fee, data.hidden == 0), Tuple.Create(to, data.fee, data.hidden == 0) });
            }).Where(c => !string.IsNullOrEmpty(c.Item1))
                            .Distinct()
                            .ToList();

            foreach (var obj in coinNames)
            {
                DatabaseService.Enqueue(new CurrencyUpdaterJob(
                                            ExchangeId,
                                            obj.Item1,
                                            obj.Item1,
                                            obj.Item3,
                                            obj.Item2));
            }
        }
Exemple #13
0
        private async Task OnPullingMarkets(PullerSession session)
        {
            var response = Pull <YobitResponse>(CurrencyMarketUrl, session);

            using (var db = DatabaseService.CreateContext())
            {
                //get all prices from db
                var prices = db.BorsaCurrencyT
                             .Include(bc => bc.FromCurrency).Include(bc => bc.ToCurrency)
                             .Where(bc => bc.BorsaId == ExchangeId)
                             .ToList();

                foreach (var obj in response.pairs.Children <JProperty>())
                {
                    var data   = obj.Value.ToObject <YobitMarket>();
                    var fromTo = obj.Name.Split('_');
                    var from   = fromTo[1].ToUpper();
                    var to     = fromTo[0].ToUpper();

                    new MarketUpdaterJob(ExchangeId, from, to, data.hidden == 0, prices).Execute(db);
                }

                new MarketUpdaterJob(prices).Execute(db);

                db.SaveChanges();
            }
        }
Exemple #14
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();
            }
        }
Exemple #15
0
        public IActionResult Test()
        {
            var    list = new List <string>();
            string status;

            using (var session = PullerSession.Create())
            {
                status = "Client count: " + session.Clients.Count;
                foreach (var cl in session.Clients)
                {
                    try
                    {
                        var version = cl.Get <string>("version");
                        if (version != "v3")
                        {
                            list.Add(cl.Url);
                        }
                    }
                    catch (Exception exception)
                    {
                        list.Add(cl.Url);
                    }
                }
            }
            string failedInfo = " - No failed connections.";

            if (list.Count > 0)
            {
                failedInfo = " - Failed connections: " + string.Join(", ", list);
            }
            var reqCount = " - Request count: " + SocketManager.ReqCount;

            return(Ok("Bot is running... " + status + failedInfo + reqCount));
        }
Exemple #16
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();

                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();
            }
        }
        private async Task OnPullingCurrencies(PullerSession session)
        {
            var response = Pull <JObject>(CurrencyUrl, session);

            foreach (var obj in response.Children <JProperty>())
            {
                var currencyName = obj.Name;
                var currency     = obj.Value.ToObject <PoloniexCurrency>();
                DatabaseService.Enqueue(new CurrencyUpdaterJob(
                                            ExchangeId,
                                            currencyName,
                                            currency.name,
                                            currency.disabled == 0,
                                            Convert.ToDecimal(currency.txFee)));
            }
        }
Exemple #18
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 #20
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();
            }
        }
Exemple #21
0
        private async Task OnPullingPrices(PullerSession session)
        {
            var response = Pull <CexioResponse <List <CexioPrice> > >(PriceUrl, session);

            if (response.ok == "ok")
            {
                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();

                    //get markets
                    foreach (var bc in prices)
                    {
                        var key    = bc.To + ":" + bc.From;
                        var market = response.data.FirstOrDefault(d => d.pair == key);
                        if (market != null)
                        {
                            DatabaseService.Enqueue(
                                new PriceUpdaterJob(bc.Id, Convert.ToDecimal(market.last))
                                .UpdateVolume24(Convert.ToDecimal(market.volume), 0)
                                .UpdatePriceData(0, Convert.ToDecimal(market.high), Convert.ToDecimal(market.low), 0));
                            DatabaseService.Enqueue(new UsdGeneratorJob(ExchangeId, bc.FromId, bc.ToId, bc.Price));
                        }
                    }
                }
            }
            else
            {
                Console.WriteLine(string.Format("Could not pull currencies from {0}: {1}", Name,
                                                JsonConvert.SerializeObject(response)));
            }
        }
Exemple #22
0
        private async Task OnPullingCurrencies(PullerSession session)
        {
            var response = Pull <BittrexResponse <List <BittrexCurrency> > >(CurrencyUrl, session);

            if (response.success)
            {
                foreach (var currency in response.result.Where(r => r.IsActive))
                {
                    DatabaseService.Enqueue(new CurrencyUpdaterJob(
                                                ExchangeId,
                                                currency.Currency,
                                                currency.CurrencyLong,
                                                null,
                                                currency.TxFee));
                }
            }
            else
            {
                Console.WriteLine(string.Format("Could not pull currencies from {0}: {1}", Name, response.message));
            }
        }
        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();

                ParallelFor(prices, bc =>
                {
                    var symbol = bc.To + bc.From;

                    //var responseTicker = Pull<BitfinexTicker>(string.Format(PriceUrl, symbol)).Result;
                    var responseVolume = Pull <List <decimal> >(string.Format(VolumeUrl, symbol), session);

                    var mv    = responseVolume[5];
                    var open  = responseVolume[1];
                    var close = responseVolume[2];
                    var high  = responseVolume[3];
                    var low   = responseVolume[4];
                    //var dv = Convert.ToDecimal(responseTicker.volume);
                    var dbv = 0;

                    DatabaseService.Enqueue(new PriceUpdaterJob(bc.Id, close, mv, 1)
                                            //.UpdatePrice24Data(0, Convert.ToDecimal(responseTicker.high), Convert.ToDecimal(responseTicker.low), 0)
                                            .UpdatePriceData(open, high, low, close));
                    DatabaseService.Enqueue(new UsdGeneratorJob(ExchangeId, bc.FromId, bc.ToId, bc.Price));
                }).Wait();
            }
        }
Exemple #24
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;

                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();
            }
        }