private static void WriteCsv(Bar[] bars, string path) { CallTimed(() => { using (var w = new StreamWriter(path)) { w.WriteLine("High,Low,Open,Volume"); foreach (var barId in bars) { var sb = new StringBuilder(); sb.Append(barId.High); sb.Append(","); sb.Append(barId.Low); sb.Append(","); sb.Append(barId.Open); sb.Append(","); sb.Append(barId.Volume); w.WriteLine(sb.ToString()); } } }, "Csv generation time"); }
internal static DateTime[] GetBarsTo(Bar[] barData) { return barData.SelectToArray(b => b.To.AddUtc()); }
public static double[] GetBarsVolume(Bar[] barData) { return barData.SelectToArray(b => b == null ? 0.0 : b.Volume); }
public static double[] GetBarsOpen(Bar[] barData) { return barData.SelectToArray(b => b == null ? 0.0 : b.Open); }
public static double[] GetBarsHigh(Bar[] barData) { return barData.SelectToArray(b => b == null ? 0.0 : b.High); }
/// <summary> /// Returns history bars for a specified symbol /// </summary> /// <param name="symbol">a requested symbol</param> /// <param name="period">a requested period</param> /// <returns></returns> public Bar[] GetBars(string symbol, BarPeriod period) { var request = string.Format("{0}:{1}", symbol, period); Bar[] result; this.requestToBars.TryGetValue(request, out result); if (result != null) return result; var priceType = PriceType.Bid; if (symbol.EndsWith(AskSuffix, StringComparison.InvariantCulture)) { symbol = symbol.Substring(0, symbol.Length - AskSuffix.Length); priceType = PriceType.Ask; } if (this.ServerDateTime > DateTime.MinValue) result = storage.Online.GetBars(symbol, priceType, period, this.ServerDateTime, -RequestedBarsNumber); else result = new Bar[0]; this.requestToBars[request] = result; return result; }
internal static DateTime TimeTo(Bar bar) { if (bar == null) return EmptyTime; return bar.To.AddUtc(); }
public BarValues(Bar[] bars, Func<Bar, double> selector) { this.bars = bars; this.selector = selector; }
public static double Time(Bar bar) { var time = new datetime(bar.From); return time.Value; }
public static double Volume(Bar bar) { return bar.Volume; }
public static double High(Bar bar) { return bar.High; }
public static double Low(Bar bar) { return bar.Low; }
public static double Close(Bar bar) { return bar.Open; }
public static double Open(Bar bar) { return bar.Open; }