Bars IBars2WLBars(string symbol, WealthLab.BarScale scale, int barInterval, IBars bars, bool includePartialBar) { l.Debug("IBars2WLBars"); WealthLab.Bars result = new WealthLab.Bars(symbol, scale, barInterval); IBar b = bars.First; while (b != bars.Last) { result.Add(b.GetDateTime(), b.Open, b.High, b.Low, b.Close, b.Volume); b = bars.GetNext(b); } // bars.NewBarEvent += bars_NewBarEvent; if (b != null) // а значит указывает на Last { if ((!includePartialBar) && ((result.Date[result.Count - 1] + bars.scale.ToTimeSpan()) < (DateTime.Now - sec3))) { result.Add(b.GetDateTime(), b.Open, b.High, b.Low, b.Close, b.Volume); } if (includePartialBar) { result.Open.PartialValue = b.Open;; result.Close.PartialValue = b.Close; result.High.PartialValue = b.High; result.Low.PartialValue = b.Low; result.Volume.PartialValue = b.Volume; } } l.Debug("IBars2WLBars result.Count " + result.Count); return(result); }
public override Bars RequestData(DataSource ds, string symbol, DateTime startDate, DateTime endDate, int maxBars, bool includePartialBar) { l.Debug("RequestData " + symbol + " from " + startDate.ToString("yy.MM.dd hh:mm:ss") + " to " + endDate.ToString("yy.MM.dd hh:mm:ss") + " maxBars=" + maxBars.ToString() + " includePartialBar=" + includePartialBar.ToString()); // Пытаюсь получить Bars из кэша WealthLab.Bars bars = null; OpenWealth.ISymbol owSymbol = data.GetSymbol(symbol); OpenWealth.IScale owScale = WLScale2Scale(ds.Scale, ds.BarInterval); OpenWealth.IBars owBars = data.GetBars(owSymbol, owScale); lock (barsCache) { if (barsCache.ContainsKey(owBars)) { l.Debug("bars содержится в Cache"); bars = barsCache[owBars].Target as Bars; if (bars == null) { l.Debug("ссылка в Cache истекла"); bars = IBars2WLBars(symbol, ds.Scale, ds.BarInterval, owBars, includePartialBar); barsCache[owBars].Target = bars; } } else { l.Debug("bars НЕ содержится в Cache"); bars = IBars2WLBars(symbol, ds.Scale, ds.BarInterval, owBars, includePartialBar); // barsCache.Add(owBars, new WeakReference(bars)); } } return(bars); }
Bars IBars2WLBars(string symbol, WealthLab.BarScale scale, int barInterval, IBars bars, bool includePartialBar) { l.Debug("IBars2WLBars"); WealthLab.Bars result = new WealthLab.Bars(symbol, scale, barInterval); IBar b = bars.First; while (b != bars.Last) { result.Add(b.GetDateTime(), b.Open, b.High, b.Low, b.Close, b.Volume); b = bars.GetNext(b); } // bars.NewBarEvent += bars_NewBarEvent; if (b != null) // а значит указывает на Last { if ((!includePartialBar)&&((result.Date[result.Count - 1] + bars.scale.ToTimeSpan()) < (DateTime.Now - sec3))) result.Add(b.GetDateTime(), b.Open, b.High, b.Low, b.Close, b.Volume); if (includePartialBar) { result.Open.PartialValue = b.Open;; result.Close.PartialValue = b.Close; result.High.PartialValue = b.High; result.Low.PartialValue = b.Low; result.Volume.PartialValue = b.Volume; } } l.Debug("IBars2WLBars result.Count " + result.Count); return result; }