Ejemplo n.º 1
0
        public void SaveKlines(List <Kline> klines)
        {
            var numOfKlines = klines.Count();

            _logger.Info(string.Format("{0} updates received, saving data to database", numOfKlines));
            //if (numOfKlines > 0)
            //{
            try
            {
                using (var context = new InfraContext())
                {
                    context.Klines.AddRange(klines);
                    //klines.RemoveRange(0, numOfKlines);
                    context.SaveChanges();
                    context.Klines.RemoveRange(klines);
                }
                _logger.Info(String.Format("{0} klines updated in database for {1} {2}", klines.Count(), klines[0].Symbol, klines[0].Interval));
            }
            catch (Exception e)
            {
                _logger.Error(String.Format("Failed to save klines to database. Symbol: {0}, Interval: {1}.\n{3}", klines[0].Symbol, klines[0].Interval, e.ToString()));
            }

            //}
        }
Ejemplo n.º 2
0
        public long FindKlineLastUpdate(string symbol, string interval)
        {
            try
            {
                long lastupdate = 0;
                using (var context = new InfraContext())
                {
                    try
                    {
                        lastupdate = context.Klines.Where(a => a.Symbol == symbol && a.Interval == interval).Max(a => a.CloseTime);
                    }
                    catch (Exception)
                    {
                        lastupdate = 0;
                    }


                    //var last = context.Klines.FromSql("GetLastUpdateBySymbolAndInterval @Symbol = {0}, @Interval = {1}", symbol, interval);
                    return(lastupdate);
                }
            }
            catch (Exception e)
            {
                _logger.Error("Failed to load last update date for kline.\n" + e.ToString());
                return(-1);
            }
        }
Ejemplo n.º 3
0
 private List <Kline> GetAllTicksForCoinInterval(CoinInterval key)
 {
     using (var context = new InfraContext())
     {
         var klineList = context.Klines.Where(i => i.Symbol == key.Symbol && i.Interval == key.Interval).OrderBy(i => i.OpenTime).ToList();
         return(klineList);
     }
 }
Ejemplo n.º 4
0
 public void SaveMarketData(GlobalMarketData newMd)
 {
     using (var context = new InfraContext())
     {
         context.Set <GlobalMarketData>().Update(newMd);
         context.SaveChanges();
         //Logger.Log(String.Format("New Coin Saved: Id={0}, Symbol = {1}, Name={2}", coin.Id, coin.Symbol, coin.Name));
     }
 }
Ejemplo n.º 5
0
        public Dictionary <string, Coin> LoadCoins()
        {
            var coins = new Dictionary <string, Coin>();

            using (var context = new InfraContext())
            {
                var coinList = from c in context.Coins
                               select c;
                foreach (var coin in coinList)
                {
                    coins.Add(coin.Name, coin);
                }
            }
            return(coins);
        }
Ejemplo n.º 6
0
        public void SaveCoinPairs(List <CoinPair> tickers)
        {
            int numOfRows = 0;

            using (var context = new InfraContext())
            {
                foreach (var ticker in tickers)
                {
                    numOfRows += context.Database.ExecuteSqlCommand
                                     ("UpdateCoinPairs @Symbol={0}, @Value={1}",
                                     ticker.Symbol, ticker.Value);
                }
            }
            _logger.Info(String.Format("{0} Coin Pairs updated in database", numOfRows * -1));
        }
Ejemplo n.º 7
0
        private List <CoinInterval> FindUniqueKeysInKlinesTable()
        {
            var keyList = new List <CoinInterval>();

            using (var context = new InfraContext())
            {
                var data = context.Klines.Select(i => new { i.Symbol, i.Interval }).Distinct().ToList();
                foreach (var item in data)
                {
                    var coinKey = new CoinInterval(item.Symbol, item.Interval);
                    keyList.Add(coinKey);
                }
            }
            return(keyList);
        }
Ejemplo n.º 8
0
 private void SaveKline(Kline kline)
 {
     _logger.Debug("kline received for " + kline.Symbol + "-" + kline.Interval);
     using (var context = new InfraContext())
     {
         try
         {
             context.Klines.Add(kline);
             context.SaveChanges();
         }
         catch (Exception e)
         {
             _logger.Error("Failed to save kline.\n" + e);
         }
     }
 }
Ejemplo n.º 9
0
 private static void SaveCoin(string symbol, string name)
 {
     try
     {
         var coin = new Coin(symbol, name);
         using (var context = new InfraContext())
         {
             context.Coins.Add(coin);
             context.SaveChanges();
         }
         Logger.Log(String.Format("New Coin Saved: Id={0}, Symbol = {1}, Name={2}", coin.Id, coin.Symbol, coin.Name));
     }
     catch (Exception e)
     {
         Logger.Log("Failed to save coin to database.\n" + e.ToString());
     }
 }
Ejemplo n.º 10
0
        public void SaveCoin(string symbol, string name)
        {
            try
            {
                var coin = new Coin(symbol, name);
                using (var context = new InfraContext())
                {
                    var coins = from c in context.Coins
                                where c.Symbol == coin.Symbol
                                select c;

                    if (coins.Count() == 0)
                    {
                        context.Coins.Add(coin);
                        context.SaveChanges();
                        _logger.Info(String.Format("New Coin Saved: Id={0}, Symbol = {1}, Name={2}", coin.Id, coin.Symbol, coin.Name));
                    }
                }
            }
            catch (Exception e)
            {
                _logger.Error("Failed to save coin to database.\n" + e.ToString());
            }
        }
Ejemplo n.º 11
0
 public UnitOfWork(InfraContext context)
 {
     _context = context;
 }
Ejemplo n.º 12
0
 public TenantRepository(InfraContext context)
 {
     _context = context;
 }
Ejemplo n.º 13
0
 protected Repository()
 {
     Db    = new InfraContext();
     DbSet = Db.Set <TEntity>();
 }
Ejemplo n.º 14
0
 public PortfolioRepository(InfraContext context)
 {
     _context = context;
 }
Ejemplo n.º 15
0
 public PortfolioMap(InfraContext context)
 {
     _context = context;
 }