/// <summary> /// Gets a single candle of a DateTime range /// </summary> /// <param name="candleType"></param> /// <param name="tickStart"></param> /// <param name="nextTickStart"></param> /// <param name="pair"></param> /// <returns></returns> public CandleSummary GenerateSingleCandle(CandleTypes candleType, DateTime tickStart, DateTime nextTickStart, BasePair pair) { CandleSummary result = null; using (var cxt = DataStore.CreateDataStore()) { var data = ( from t in cxt.Tick join p in cxt.Pair on t.PairID equals p.PairID where p.PairID == (int)pair && t.TickTime >= tickStart && t.TickTime < nextTickStart select t ).OrderBy(x => x.TickTime).ToList(); if (data.Count > 0) { result = new CandleSummary(); result.High = data.Aggregate((x, y) => x.Bid > y.Bid ? x : y); result.Low = data.Aggregate((x, y) => x.Bid < y.Bid ? x : y); result.Open = data.FirstOrDefault(); result.Close = data.LastOrDefault(); result.FromTime = tickStart; result.ToTime = nextTickStart; result.BasePairID = (int)pair; result.CandleTypeID = (int)candleType; } return(result); } }
public CandleSummary GetCandle(CandleTypes candleType, DateTime tickStart, BasePair pair) { using (var cxt = DataStore.CreateDataStore()) { var data = cxt.Candle.FirstOrDefault(x => x.CandleTypeID == (int)candleType && x.FromTime == tickStart && x.PairID == (int)pair); CandleSummary result = null; if (data != null) { result = ( from c in cxt.Candle join ht in cxt.Tick on c.HighTickID equals ht.TickID join lt in cxt.Tick on c.LowTickID equals lt.TickID join ot in cxt.Tick on c.LowTickID equals ot.TickID join ct in cxt.Tick on c.LowTickID equals ct.TickID where c.CandleID == data.CandleID select new CandleSummary { BasePairID = (int)pair, CandleTypeID = (int)candleType, Close = ct, FromTime = tickStart, High = ht, Low = lt, Open = ot } ).FirstOrDefault(); } return(result); } }