public void Run()
        {
            using zcryptoContext ctx   = new zcryptoContext();
            using BinanceClient client = new BinanceClient();

            List <LowPriceSymbolScan> symbolsToScan = ctx.LowPriceSymbolScans.ToList();

            foreach (LowPriceSymbolScan symbol in symbolsToScan)
            {
                List <IBinanceKline> klines = client.Spot.Market.GetKlines(symbol.Symbol, KlineInterval.FiveMinutes, null, null, symbol.LastKlines).Data.ToList();
                decimal goingDown           = CheckItsGoingDown(klines, symbol.PercentThreshold, symbol.Symbol);
                if (goingDown > 0)
                {
                    List <LowPriceSymbolScanAlert> alerts = ctx.LowPriceSymbolScanAlerts.ToList();
                    if (alerts.Count(x => x.LowPriceSymbolScanId == symbol.Id && x.ActiveDuration >= DateTime.Now) > 0)
                    {
                        foreach (var alert in ctx.LowPriceSymbolScanAlerts.Where(x => x.LowPriceSymbolScanId == symbol.Id && x.ActiveDuration >= DateTime.Now))
                        {
                            alert.ActiveDuration = DateTime.Now.AddMinutes(15);
                        }
                    }
                    else
                    {
                        ctx.LowPriceSymbolScanAlerts.Add(new LowPriceSymbolScanAlert()
                        {
                            ActiveDuration       = DateTime.Now.AddMinutes(15),
                            LowPriceSymbolScanId = symbol.Id,
                            PercentLow           = goingDown
                        });
                    }

                    ctx.SaveChanges();
                }
            }
        }
Beispiel #2
0
        public void Run()
        {
            using PaprikaApiClient client = new PaprikaApiClient();
            using zcryptoContext ctx      = new zcryptoContext();
            List <Buy> activeBuys = DataConsistentController.GetActiveBuys();

            foreach (Buy b in activeBuys)
            {
                API_Market_Price price = client.GetMarketPrice(b.CoinId);
                if (price is not null)
                {
                    if (ctx.ReportedExchangeRates.Where(x => x.BuyId == b.Id).Count() > 1000)
                    {
                        ctx.ReportedExchangeRates.RemoveRange(ctx.ReportedExchangeRates.Where(x => x.BuyId == b.Id));
                        ctx.SaveChanges();
                    }
                    ctx.ReportedExchangeRates.Add(new ReportedExchangeRate()
                    {
                        BuyId         = b.Id,
                        PlnExchange   = price.quotes.PLN.price,
                        ApiUpdateTime = price.last_updated,
                        ExchangeDiff  = (price.quotes.PLN.price * (double)b.Count) - (double)(b.ExchangeRatePln * b.Count)
                    });
                    ctx.SaveChanges();
                }
            }
        }
Beispiel #3
0
 public static List <Buy> GetActiveBuysWithReportedExchangeRates()
 {
     using zcryptoContext ctx = new zcryptoContext();
     return(ctx.Buys.Where(x => x.Active.HasValue && x.Active.Value)
            .Include(x => x.Coin)
            .Include(x => x.ReportedExchangeRates.OrderByDescending(c => c.Id).Take(1)).ToList().OrderBy(x => x.Id).ToList());
 }
Beispiel #4
0
        public static void UpsertCoin(API_Coin coin)
        {
            using (zcryptoContext ctx = new zcryptoContext())
            {
                Coin foundCoin = ctx.Coins.Where(x => x.Id.Equals(coin.id)).FirstOrDefault();
                if (foundCoin is null)
                {
                    ctx.Coins.Add(new Coin()
                    {
                        Id       = coin.id,
                        IsActive = coin.is_active,
                        IsNew    = coin.is_new,
                        Name     = coin.name,
                        Rank     = coin.rank,
                        Symbol   = coin.symbol,
                        Type     = coin.type
                    });
                }
                else
                {
                    foundCoin.IsActive = coin.is_active;
                    foundCoin.IsNew    = coin.is_new;
                    foundCoin.Name     = coin.name;
                    foundCoin.Rank     = coin.rank;
                    foundCoin.Symbol   = coin.symbol;
                    foundCoin.Type     = coin.type;
                }

                ctx.SaveChanges();
            }
        }
Beispiel #5
0
        public void IsCointBlacklisted()
        {
            zcryptoContext ctx = new zcryptoContext();

            foreach (Coin c in ctx.Coins)
            {
                Assert.DoesNotThrow(() => { DataConsistentController.IsCoinBlacklisted(c.Id); });
            }
        }
Beispiel #6
0
 public void GetMarketPrices()
 {
     using (zcryptoContext ctx = new zcryptoContext())
     {
         List <Coin> coins = ctx.Coins.Where(x => x.IsActive).ToList();
         using (PaprikaApiClient client = new PaprikaApiClient())
         {
             foreach (Coin c in coins)
             {
                 API_Market_Price marketPrice = client.GetMarketPrice(c.Id);
                 if (marketPrice != null)
                 {
                     Assert.IsTrue(marketPrice.quotes.EUR != null);
                     Assert.IsTrue(marketPrice.quotes.EUR.price != 0);
                     Assert.IsTrue(marketPrice.quotes.PLN != null);
                     Assert.IsTrue(marketPrice.quotes.PLN.price != 0);
                 }
             }
         }
     }
 }
        public IActionResult AddBuy([FromBody] Buy buy, [FromHeader] string securityCode)
        {
            if (securityCode == null || !securityCode.Equals("secret"))
            {
                return(Unauthorized());
            }

            try
            {
                using (zcryptoContext ctx = new zcryptoContext())
                {
                    ctx.Buys.Add(buy);
                    ctx.SaveChanges();
                }

                return(Ok());
            }
            catch (Exception e)
            {
                return(BadRequest(e.Message));
            }
        }
Beispiel #8
0
        public API_Market_Price GetMarketPrice(string coinId)
        {
            using zcryptoContext dbCtx = new zcryptoContext();
            if (DataConsistentController.IsCoinBlacklisted(coinId))
            {
                return(null);
            }

            System.Diagnostics.Debug.WriteLine(coinId);
            IRestResponse response = restClient.Get(new RestRequest($"v1/coins/{coinId}/markets?quotes=PLN,EUR", Method.GET));

            try
            {
                ValidateResponse(response);
            }catch (Exception)
            {
                if (response.StatusCode == System.Net.HttpStatusCode.NotFound)
                {
                    dbCtx.CoinBlacklistIntegrations.Add(new CoinBlacklistIntegration()
                    {
                        CoinId = coinId,
                        Reason = "Not found by markets endpoint"
                    });
                    dbCtx.SaveChanges();
                    return(null);
                }
                else
                {
                    throw;
                }
            }
            string           jsonCoinList     = response.Content;
            API_Market_Price foundMarketPrice = JsonConvert.DeserializeObject <List <API_Market_Price> >(jsonCoinList)
                                                .Where(x => x.exchange_id.Equals(DEFAULT_EXCHANGE_ID)).FirstOrDefault();

            return(foundMarketPrice);
        }
Beispiel #9
0
 public static List <string> GetActiveCoinsIds()
 {
     using zcryptoContext ctx = new zcryptoContext();
     return(ctx.Coins.Where(x => x.IsActive).Select(x => x.Id).ToList());
 }
Beispiel #10
0
 public static List <Buy> GetActiveBuys()
 {
     using zcryptoContext ctx = new zcryptoContext();
     return(ctx.Buys.Where(x => x.Active.HasValue && x.Active.Value).ToList());
 }
Beispiel #11
0
 public static bool IsCoinBlacklisted(string coinId)
 {
     using zcryptoContext dbCtx = new zcryptoContext();
     return(dbCtx.CoinBlacklistIntegrations.Any(x => x.CoinId.Equals(coinId)));
 }