//public override double GetRSIAtIndex(int index) //{ // lock (this) // { // return _dataBars[index].Rsi; // } //} public override void SaveToFile(string fileName) { BarData[] dataBars; lock (this) { dataBars = _dataBars.ToArray(); } BarDataHelper.SaveToFile(BarDataHelper.FileFormat.CVSDefault, fileName, dataBars); }
public static bool LoadLatestRtd(string fileName, int startingRow, int rowsLimit, out List <BarData> datas, string key) { datas = new List <BarData>(); int i = 0; using (System.IO.TextReader tr = new System.IO.StreamReader(fileName)) { //ICrypta crypta = SecurityService.GetCrypta(); try { List <double> prices = new List <double>(); DateTime time = new DateTime(); for (i = 0; i < startingRow + rowsLimit || rowsLimit == 0; i++) { string lineStr = tr.ReadLine(); if (lineStr == null) { break; } if (i >= startingRow) {// Parse. //lineStr = crypta.decrypt(lineStr); // Parse 1 line - if the CSV format changes, modify this here as well string[] lineSplit = Regex.Split(lineStr, ","); time = BarDataHelper.ParseCSVDateTime(lineSplit[1], lineSplit[2]); prices.Add(Double.Parse(lineSplit[3])); } } double max = double.MinValue; double min = double.MaxValue; foreach (double p in prices) { max = Math.Max(max, p); min = Math.Min(min, p); } double open = prices.First(); double close = prices.Last(); datas.Add(new BarData(time, open, close, min, max, 0)); Console.WriteLine("ccccccccccccccccccccccccccc " + (c++)); } catch (Exception exception) { Console.WriteLine(exception.ToString()); datas.Clear(); return(false); } //crypta = null; } return(true); }
public static List <RealTimeData> ParseRtdMsg(string realTimeMsg) { List <RealTimeData> list = new List <RealTimeData>(); try { string[] rmsgs = Regex.Split((string)realTimeMsg, @"\r\n", RegexOptions.IgnoreCase); foreach (string msg in rmsgs) { if (msg.Trim().Length > 0) { try { string[] msgs = msg.Split(','); //Symbol symbol = (Symbol)Enum.Parse(typeof(Symbol), msgs[0].Trim()); Symbol symbol = ParseSymbol(msgs[0].Trim()); if (symbol == Symbol.UNKNOWN) { Console.WriteLine(" UNKNOWN symbol " + msgs[0]); continue; } DateTime dateTime = BarDataHelper.ParseCSVDateTime(msgs[1].Trim(), msgs[2].Trim()); double[] datas = new double[msgs.Length - 3]; for (int i = 3; i < msgs.Length; i++) { if (msgs[i].Trim().Length > 0) { datas[i - 3] = Double.Parse(msgs[i]); } } RealTimeData realTimeData = new RealTimeData(symbol, dateTime, datas); list.Add(realTimeData); } catch (Exception ex) { Console.WriteLine(ex.StackTrace); continue; } } } } catch (Exception e) { Console.WriteLine(e.StackTrace); } return(list); }
public bool LoadFile(string fileName, int startingRow, int rowsLimit, out List <RealTimeData> datas, bool isDecrypt) { datas = new List <RealTimeData>(); int i = 0; using (System.IO.TextReader tr = new System.IO.StreamReader(fileName)) { try { DateTime time = new DateTime(); RealTimeData rtd = new RealTimeData(); for (i = 0; i < startingRow + rowsLimit || rowsLimit == 0; i++) { string lineStr = tr.ReadLine(); if (lineStr == null) { break; } if (i >= startingRow) {// Parse. //if (isDecrypt) //{ // lineStr = crypta.decrypt(lineStr); //} string[] lineSplit = Regex.Split(lineStr, ","); time = BarDataHelper.ParseCSVDateTime(lineSplit[1], lineSplit[2]); double [] prices = new double[] { Double.Parse(lineSplit[3]) }; rtd.symbol = (Symbol)Enum.Parse(typeof(Symbol), lineSplit[0]); rtd.dateTime = time; rtd.datas = prices; datas.Add(rtd); } } } catch (Exception exception) { Console.WriteLine(exception.ToString()); datas.Clear(); return(false); } } return(true); }
public static bool LoadFromFileCSV(string fileName, int startingRow, int rowsLimit, out List <BarData> datas) { datas = new List <BarData>(); int i = 0; // ICrypta crypta = SecurityService.GetCrypta(); using (System.IO.TextReader tr = new System.IO.StreamReader(fileName)) { try { for (i = 0; i < startingRow + rowsLimit || rowsLimit == 0; i++) { string lineStr = tr.ReadLine(); if (lineStr == null) { break; } if (i >= startingRow) {// Parse. // lineStr = crypta.decrypt(lineStr); // Parse 1 line - if the CSV format changes, modify this here as well string[] lineSplit = Regex.Split(lineStr, ","); DateTime time = BarDataHelper.ParseCSVDateTime(lineSplit[0], lineSplit[1]); int signal = int.Parse(lineSplit[6], new System.Globalization.NumberFormatInfo()); datas.Add(new BarData(time, double.Parse(lineSplit[2], GeneralHelper.NumberFormatInfo), double.Parse(lineSplit[3], GeneralHelper.NumberFormatInfo), double.Parse(lineSplit[4], GeneralHelper.NumberFormatInfo), double.Parse(lineSplit[5], GeneralHelper.NumberFormatInfo), 0d, signal)); } } Console.WriteLine("ccccccccccccccccccccccccccc " + (c++)); } catch (Exception exception) { Console.WriteLine(exception.ToString()); datas.Clear(); return(false); } } //crypta = null; return(true); }