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())); } //} }
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); } }
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); } }
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)); } }
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); }
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)); }
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); }
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); } } }
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()); } }
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()); } }
public UnitOfWork(InfraContext context) { _context = context; }
public TenantRepository(InfraContext context) { _context = context; }
protected Repository() { Db = new InfraContext(); DbSet = Db.Set <TEntity>(); }
public PortfolioRepository(InfraContext context) { _context = context; }
public PortfolioMap(InfraContext context) { _context = context; }