public override IDataProvider GetData(string Code, int Count) { string str = GetFileName(Code); byte[] bs1 = new byte[0]; CommonDataProvider commonDataProvider = new CommonDataProvider(this); if (File.Exists(str)) { commonDataProvider.LoadBinary(str); } else { commonDataProvider.LoadBinary(bs1); } if (SymbolTable != null) { DataRow dataRow = (DataRow)SymbolTable[Code]; if (dataRow != null) { commonDataProvider.SetStringData("Code", Code); commonDataProvider.SetStringData("Name", dataRow["Name"].ToString()); commonDataProvider.SetStringData("Exchange", dataRow["Exchange"].ToString()); } } IDataProvider iDataProvider = commonDataProvider; return(iDataProvider); }
public static void UpdateForNewSymbol(string Code, CommonDataProvider cdp, bool Save) { Utils.UpdateRealtime(Code, cdp); if (Save) { Impersonate.ChangeToAdmin(); cdp.SaveBinary(GetHisDataFile(Code)); } RefreshSymbolList(); string[] ss = YahooDataManager.GetStockName(Code); if (ss.Length == 3) { try { DB.DoCommand("insert into StockData (QuoteCode,QuoteName,Exchange) values (?,?,?)", new DbParam[] { new DbParam("@Code", DbType.String, Code), new DbParam("@Name", DbType.String, ss[1]), new DbParam("@Exchange", DbType.String, ss[2]), }); } catch { } } cdp.SetStringData("Code", ss[0]); cdp.SetStringData("Name", ss[1]); cdp.SetStringData("Exchange", ss[2]); }
public override IDataProvider GetData(string Code, int Count) { try { CommonDataProvider cdp = new CommonDataProvider(this); DbParam[] dps = new DbParam[] { new DbParam("@Q1", DbType.DateTime, StartTime), new DbParam("@Q2", DbType.DateTime, EndTime), }; BaseDb bd = DB.Open(false); try { DataTable dt = bd.GetDataTable("select Tick,tstamp from " + Code + "_tick where tstamp>=? and tstamp<=? order by tstamp", dps); dps[1].Value = ((DateTime)dps[0].Value).AddSeconds(-1); dps[0].Value = ((DateTime)dps[0].Value).AddDays(-30); DataRow drr = bd.GetFirstRow("select Tick from " + Code + "_tick where tstamp>=? and tstamp<=? order by tstamp desc", dps); if (dt.Rows.Count > 0) { cdp.SetStringData("LastTradeTime", ((DateTime)dt.Rows[dt.Rows.Count - 1]["tstamp"]).ToString()); } if (drr != null) { cdp.SetStringData("LastPrice", drr[0].ToString()); } if (dt.Rows.Count == 0) { dt.Rows.Add(new object[] { Single.NaN, StartTime }); } double[] CLOSE = new double[dt.Rows.Count]; double[] VOLUME = new double[dt.Rows.Count]; double[] DATE = new double[dt.Rows.Count]; for (int i = 0; i < dt.Rows.Count; i++) { CLOSE[i] = ToDouble(dt.Rows[i]["Tick"]); VOLUME[i] = 0; DATE[i] = ((DateTime)dt.Rows[i]["tstamp"]).ToOADate(); } cdp.LoadBinary("CLOSE", CLOSE); cdp.LoadBinary("DATE", DATE); cdp.LoadBinary("VOLUME", VOLUME); } finally { bd.Close(); } return(cdp); } catch { } return(base.GetData(Code, Count)); }
public override IDataProvider GetData(string Code, int Count) { string FileName = Config.CSVDataPath + Code + Config.CSVExt; if (File.Exists(FileName)) { FileStream fs = new FileStream(FileName, FileMode.Open, FileAccess.Read, FileShare.ReadWrite); StreamReader sr = new StreamReader(fs); try { string s = sr.ReadToEnd(); CommonDataProvider cdp = GetDataFromString(s); if (cdp != null) { cdp.SetStringData("Code", Code); } return(cdp); } finally { sr.Close(); fs.Close(); } } return(base.GetData(Code, Count)); }
public override IDataProvider GetData(string Code, int Count) { CommonDataProvider cdp = new CommonDataProvider(this); cdp.SetStringData("Code", Code); DataTable dt = DB.GetDataTable("SELECT top " + Count + " * FROM WEBCHARTX_DATA where Symbol='" + Code + "' ORDER BY Store_Date"); double[] OPEN = new double[dt.Rows.Count]; double[] HIGH = new double[dt.Rows.Count]; double[] LOW = new double[dt.Rows.Count]; double[] CLOSE = new double[dt.Rows.Count]; double[] VOLUME = new double[dt.Rows.Count]; double[] AMOUNT = new double[dt.Rows.Count]; double[] DATE = new double[dt.Rows.Count]; for (int i = 0; i < dt.Rows.Count; i++) { OPEN[i] = ToDecimalDouble(dt.Rows[i]["Open_Price"]); HIGH[i] = ToDecimalDouble(dt.Rows[i]["HIGHT_PRICE"]); LOW[i] = ToDecimalDouble(dt.Rows[i]["LOW_PRICE"]); CLOSE[i] = ToDecimalDouble(dt.Rows[i]["CLOSE_PRICE"]); VOLUME[i] = ToInt(dt.Rows[i]["VOLUME"]); DATE[i] = ((DateTime)dt.Rows[i]["STORE_DATE"]).ToOADate(); } cdp.LoadBinary(new double[][] { OPEN, HIGH, LOW, CLOSE, VOLUME, DATE }); return(cdp); }
public override IDataProvider GetData(string Code, int Count) { CommonDataProvider cdp = new CommonDataProvider(this); cdp.SetStringData("Code", Code); string s = FormulaHelper.Root + "Data\\" + Code + ".txt"; if (File.Exists(s)) { using (StreamReader sr = File.OpenText(s)) { string r = sr.ReadToEnd(); string[] ss = r.Trim().Split('\n'); int N = ss.Length; double[] CLOSE = new double[N]; double[] VOLUME = new double[N]; double[] DATE = new double[N]; for (int i = 0; i < ss.Length; i++) { int j = N - i - 1; string[] sss = ss[i].Split(' '); DATE[j] = DateTime.ParseExact(sss[0], "yyyy.MM.dd", DateTimeFormatInfo.InvariantInfo).ToOADate(); CLOSE[j] = double.Parse(sss[2]); VOLUME[j] = 0; } cdp.LoadBinary(new double[][] { CLOSE, CLOSE, CLOSE, CLOSE, VOLUME, DATE }); return(cdp); } } return(base.GetData(Code, Count)); }
public CommonDataProvider GetCachedHistoricalData(string Symbol) { string CacheRoot = Environment.CurrentDirectory + "\\Cache\\"; if (!Directory.Exists(CacheRoot)) { Directory.CreateDirectory(CacheRoot); } string Cache = CacheRoot + Symbol + ".dat"; CommonDataProvider cdp = null; if (Symbol != "") { if (File.Exists(Cache) && File.GetLastWriteTime(Cache).Date == DateTime.Now.Date) { cdp = new CommonDataProvider(null); cdp.LoadBinary(Cache); cdp.SetStringData("Code", Symbol.ToUpper()); } else { cdp = GetHistoricalData(Symbol); if (cdp != null && cdp.Count > 0) { cdp.SaveBinary(Cache); } } } return(cdp); }
public override IDataProvider GetData(string Code, int Count) { CommonDataProvider cdp = new CommonDataProvider(this); cdp.SetStringData("Code", Code); DataTable dt = DB.GetDataTable("SELECT * FROM EndOfDay where Symbol='" + Code + "' ORDER BY Date"); double[] OPEN = new double[dt.Rows.Count]; double[] HIGH = new double[dt.Rows.Count]; double[] LOW = new double[dt.Rows.Count]; double[] CLOSE = new double[dt.Rows.Count]; double[] VOLUME = new double[dt.Rows.Count]; double[] AMOUNT = new double[dt.Rows.Count]; double[] DATE = new double[dt.Rows.Count]; for (int i = 0; i < dt.Rows.Count; i++) { OPEN[i] = ToDouble(dt.Rows[i]["Open"]); HIGH[i] = ToDouble(dt.Rows[i]["High"]); LOW[i] = ToDouble(dt.Rows[i]["Low"]); CLOSE[i] = ToDouble(dt.Rows[i]["Close"]); VOLUME[i] = ToInt(dt.Rows[i]["Volume"]); DATE[i] = ((DateTime)dt.Rows[i]["Date"]).ToOADate(); } cdp.LoadBinary(new double[][] { OPEN, HIGH, LOW, CLOSE, VOLUME, DATE }); return(cdp); }
public override void SetStrings(CommonDataProvider cdp, string Code) { cdp.SetStringData("Code", Code); switch (Code) { case "^DJI": cdp.SetStringData("Name", "Dow Jones"); break; case "^IXIC": cdp.SetStringData("Name", "Nasdaq"); break; case "^SPX": cdp.SetStringData("Name", "S & P 500"); break; } }
public override IDataProvider GetData(string Code, int Count) { CommonDataProvider cdp = new CommonDataProvider(this); string FileName = FormulaHelper.Root + "Data\\" + Code + ".txt"; if (File.Exists(FileName)) { try { string s = ""; using (FileStream fs = new FileStream(FileName, FileMode.Open, FileAccess.Read, FileShare.ReadWrite)) { using (StreamReader sr = new StreamReader(fs)) s = sr.ReadToEnd(); } string[] ss = s.Trim().Split('\n'); ArrayList al = new ArrayList(); for (int i = 0; i < ss.Length; i++) { al.Add(ss[i].Trim()); } int N = al.Count; double[] CLOSE = new double[N]; double[] OPEN = new double[N]; double[] HIGH = new double[N]; double[] LOW = new double[N]; double[] VOLUME = new double[N]; double[] DATE = new double[N]; DateTimeFormatInfo dtfi = DateTimeFormatInfo.InvariantInfo; NumberFormatInfo nfi = NumberFormatInfo.InvariantInfo; for (int i = 0; i < N; i++) { string[] sss = ((string)al[i]).Split(','); int j = i; DATE[j] = DateTime.ParseExact(sss[1] + " " + sss[2], "MM\\/dd\\/yy HH:mm", dtfi).ToOADate(); OPEN[j] = double.Parse(sss[3]); HIGH[j] = double.Parse(sss[4]); LOW[j] = double.Parse(sss[5]); CLOSE[j] = double.Parse(sss[6]); VOLUME[j] = 0; } cdp.SetStringData("Code", Code); cdp.LoadBinary(new double[][] { OPEN, HIGH, LOW, CLOSE, VOLUME, DATE }); return(cdp); } catch { } } return(CommonDataProvider.Empty); }
public override CommonDataProvider GetData(string symbols, DataCycle dataCycle, DateTime startTime, DateTime endTime) { byte[] bs = DownloadBinary(symbols, "http://subscribe.easychart.net/member/datafeed.aspx?f=BinaryHistory&AddWhenNoSymbol=1&Symbol=" + symbols); if (bs != null) { CommonDataProvider cdp = new CommonDataProvider(null); cdp.LoadByteBinary(bs); cdp.SetStringData("Code", symbols.ToUpper()); return(cdp); } return(null); }
public override IDataProvider GetData(string Code, int Count) { CommonDataProvider cdp = new CommonDataProvider(this); DataRow dr = DB.GetFirstRow("select * from CompanyInfo where TickerSymbolID='" + Code + "'"); if (dr != null) { cdp.SetStringData("Code", dr["Symbol"].ToString()); cdp.SetStringData("Name", dr["CompanyName"].ToString()); cdp.SetStringData("Exchange", dr["Exchange"].ToString()); DataTable dt = DB.GetDataTable( "SELECT S.SessionNUM, S.SessionDate, Q.StockOpen, Q.StockHigh, Q.StockLow, Q.StockClose, Q.StockVolume" + " FROM StockQuotes Q "+ " INNER JOIN Sessions S ON Q.SessionNUM = S.SessionNUM "+ " WHERE Q.TickerSymbolId='"+ Code + "' ORDER BY Q.SessionNUM"); double[] OPEN = new double[dt.Rows.Count]; double[] HIGH = new double[dt.Rows.Count]; double[] LOW = new double[dt.Rows.Count]; double[] CLOSE = new double[dt.Rows.Count]; double[] VOLUME = new double[dt.Rows.Count]; double[] AMOUNT = new double[dt.Rows.Count]; double[] DATE = new double[dt.Rows.Count]; for (int i = 0; i < dt.Rows.Count; i++) { OPEN[i] = (double)dt.Rows[i]["StockClose"]; HIGH[i] = (double)dt.Rows[i]["StockHigh"]; LOW[i] = (double)dt.Rows[i]["StockLow"]; CLOSE[i] = (double)dt.Rows[i]["StockClose"]; VOLUME[i] = (double)(int)dt.Rows[i]["StockVolume"]; DATE[i] = ((DateTime)dt.Rows[i]["SessionDate"]).ToOADate(); } cdp.LoadBinary(new double[][] { OPEN, HIGH, LOW, CLOSE, VOLUME, DATE }); return(cdp); } return(base.GetData(Code, Count)); }
public override IDataProvider GetData(string Code, int Count) { string Filename = Root + Code + ".txt"; if (File.Exists(Filename)) { using (StreamReader sr = new StreamReader(Filename)) { CommonDataProvider cdp = LoadCSV(sr); cdp.SetStringData("Code", Code); return(cdp); } } return(CommonDataProvider.Empty); }
public override IDataProvider GetData(string Code, int Count) { CommonDataProvider cdp = new CommonDataProvider(this); cdp.SetStringData("Code", Code); string s = FormulaHelper.Root + "Data\\" + Code + ".xml"; if (File.Exists(s)) { DataSet ds = new DataSet(); ds.ReadXml(s); if (ds.Tables.Count > 0) { DataTable dt = ds.Tables[0]; int N = dt.Rows.Count; double[] OPEN = new double[N]; double[] HIGH = new double[N]; double[] LOW = new double[N]; double[] CLOSE = new double[N]; double[] VOLUME = new double[N]; double[] AMOUNT = new double[N]; double[] DATE = new double[N]; for (int i = 0; i < N; i++) { OPEN[i] = double.Parse(dt.Rows[i]["Open"].ToString()); HIGH[i] = double.Parse(dt.Rows[i]["High"].ToString()); LOW[i] = double.Parse(dt.Rows[i]["Low"].ToString()); CLOSE[i] = double.Parse(dt.Rows[i]["Close"].ToString()); VOLUME[i] = double.Parse(dt.Rows[i]["Volume"].ToString()); DATE[i] = DateTime.Parse(dt.Rows[i]["Date"].ToString(), DateTimeFormatInfo.InvariantInfo).ToOADate(); } cdp.LoadBinary(new double[][] { OPEN, HIGH, LOW, CLOSE, VOLUME, DATE }); return(cdp); } } return(base.GetData(Code, Count)); }
public override IDataProvider GetData(string Code, int Count) { try { CommonDataProvider cdp = new CommonDataProvider(this); cdp.SetStringData("Code", Code); // cdp.SetStringData("Name",dr["CompanyName"].ToString()); // cdp.SetStringData("Exchange",dr["Exchange"].ToString()); DataTable dt = DB.GetDataTable("SELECT top " + Count + " * from " + Code + "_1da order by tstamp desc"); double[] OPEN = new double[dt.Rows.Count]; double[] HIGH = new double[dt.Rows.Count]; double[] LOW = new double[dt.Rows.Count]; double[] CLOSE = new double[dt.Rows.Count]; double[] VOLUME = new double[dt.Rows.Count]; double[] AMOUNT = new double[dt.Rows.Count]; double[] DATE = new double[dt.Rows.Count]; double LastClose = 0; for (int i = 0; i < dt.Rows.Count; i++) { DataRow dr = dt.Rows[dt.Rows.Count - 1 - i]; HIGH[i] = ToSingle(dr["priceh"]); LOW[i] = ToSingle(dr["pricel"]); CLOSE[i] = ToSingle(dr["pricec"]); OPEN[i] = Math.Min(Math.Max(LOW[i], LastClose), HIGH[i]); VOLUME[i] = 0; DATE[i] = ((DateTime)dr["tstamp"]).ToOADate(); LastClose = CLOSE[i]; } cdp.LoadBinary(new double[][] { OPEN, HIGH, LOW, CLOSE, VOLUME, DATE }); return(cdp); } catch { } return(base.GetData(Code, Count)); }
public override IDataProvider GetData(string Code, int Count) { Code = Code.Trim(); Hashtable htList = GetSymbolListHashtable(); string s = (string)htList[Code]; CommonDataProvider cdpn = new CommonDataProvider(this); byte[] bs = new byte[] {}; string[] ss = null; if (s != null) { ss = s.Split(','); if (ss[3] != "") { string r = (string)htList[ss[3]]; if (r != null) { ss = r.Split(','); } } if (Count > 0) { // Load data from file bs = LoadHisDataFromFile(Code, Count * DataPacket.PacketByteSize); if (DownloadRealTimeQuote) { try { DataPacket dp = DataPacket.DownloadFromYahoo(Code); if (dp != null && !dp.IsZeroValue) { bs = CommonDataProvider.MergeOneQuote(bs, dp); } } catch { } } cdpn.LoadByteBinary(bs); // Update data from yahoo if (AutoYahooToDB) { string FileName = GetHisDataFile(Code); DateTime d = new DateTime(1900, 1, 1); try { d = File.GetLastWriteTime(FileName); // GetLastAccessTime(FileName); } catch { } DateTime d1 = DateTime.Now.Date; DateTime d2 = d.Date; TimeSpan ts = d1 - d2; if (ts.TotalDays > 0) { YahooDataManager ydm = new YahooDataManager(); CommonDataProvider cdpDelta = (CommonDataProvider)ydm[Code, ts.Days + 5]; cdpDelta.Adjusted = false; if (cdpDelta.Count > 0) { double[] dd1 = cdpDelta["DATE"]; double[] dd2 = cdpn["DATE"]; if (cdpn.Count == 0 || (int)dd2[dd2.Length - 1] < (int)dd1[dd1.Length - 1]) { cdpn.Merge(cdpDelta); Impersonate.ChangeToAdmin(); Utils.UpdateRealtime(Code, cdpn); } } cdpn.SaveBinary(FileName); } } } } else { try { // Download data from yahoo if (AutoYahooToDB) { YahooDataManager ydm = new YahooDataManager(); cdpn = (CommonDataProvider)ydm[Code]; if (cdpn.Count > 0) { UpdateForNewSymbol(Code, cdpn, true); } else { throw new Exception("Invalid Quote : " + Code); } } else { cdpn.LoadByteBinary(bs); } } catch (Exception e) { Tools.Log(e.Message); cdpn.LoadByteBinary(bs); } } //cdpn = TrimToEndTime(cdpn); cdpn.SetStringData("Code", Code); if (ss != null && ss.Length > 2) { cdpn.SetStringData("Code", ss[0]); cdpn.SetStringData("Name", ss[1]); cdpn.SetStringData("Exchange", ss[2]); } return(cdpn); }
public override IDataProvider GetData(string Code, int Count) { try { CommonDataProvider cdp = new CommonDataProvider(this); DbParam[] dps = new DbParam[] { new DbParam("@Symbol", DbType.String, Code), new DbParam("@Q1", DbType.DateTime, StartTime), new DbParam("@Q2", DbType.DateTime, EndTime), }; BaseDb bd = DB.Open(false); try { DataTable dt = bd.GetDataTable("select Price,Volume,QuoteTime from Intraday where Symbol=? and QuoteTime>=? and QuoteTime<=? order by QuoteTime", dps); double LastV = -1; foreach (DataRow dr in dt.Rows) { double NowV = (double)dr["Volume"]; if (LastV >= 0) { if (NowV > LastV) { dr["Volume"] = NowV - LastV; } else { dr["Volume"] = (double)0; } } LastV = NowV; } dps[2].Value = ((DateTime)dps[1].Value).AddSeconds(-1); dps[1].Value = ((DateTime)dps[1].Value).AddDays(-30); DataRow drr = bd.GetFirstRow("select Price from Intraday where Symbol=? and QuoteTime>=? and QuoteTime<=? order by QuoteTime desc", dps); if (dt.Rows.Count > 0) { cdp.SetStringData("LastTradeTime", ((DateTime)dt.Rows[dt.Rows.Count - 1]["QuoteTime"]).ToString()); } if (drr != null) { cdp.SetStringData("LastPrice", drr[0].ToString()); } SetStrings(cdp, Code); if (dt.Rows.Count == 0) { dt.Rows.Add(new object[] { double.NaN, 0, StartTime }); } double[] CLOSE = new double[dt.Rows.Count]; double[] VOLUME = new double[dt.Rows.Count]; double[] DATE = new double[dt.Rows.Count]; for (int i = 0; i < dt.Rows.Count; i++) { CLOSE[i] = ToDouble(dt.Rows[i]["Price"]); VOLUME[i] = ToDouble(dt.Rows[i]["Volume"]); DATE[i] = ((DateTime)dt.Rows[i]["QuoteTime"]).ToOADate(); } cdp.LoadBinary("CLOSE", CLOSE); cdp.LoadBinary("DATE", DATE); cdp.LoadBinary("VOLUME", VOLUME); } finally { bd.Close(); } return(cdp); } catch { } return(base.GetData(Code, Count)); }
public CommonDataProvider GetDataFromString(string s) { string[] ss = s.Trim().Split('\n'); ArrayList al = new ArrayList(); for (int i = 0; i < ss.Length; i++) { ss[i] = ss[i].Trim(); if (!ss[i].StartsWith("<!--") && ss[i] != "") { al.Add(ss[i]); } } int N = al.Count; double[] CLOSE = new double[N]; double[] OPEN = new double[N]; double[] HIGH = new double[N]; double[] LOW = new double[N]; double[] VOLUME = new double[N]; double[] DATE = new double[N]; string Code = null; string Name = null; string Exchange = null; DateTimeFormatInfo dtfi = DateTimeFormatInfo.InvariantInfo; NumberFormatInfo nfi = NumberFormatInfo.InvariantInfo; for (int i = 0; i < N; i++) { string[] sss = ((string)al[i]).Split(','); int j = i; //N-i-1; DATE[j] = DateTime.ParseExact(sss[1], "yyyyMMdd", dtfi).ToOADate(); OPEN[j] = ToDoubleDef(sss[2], 0, nfi); HIGH[j] = ToDoubleDef(sss[3], 0, nfi); LOW[j] = ToDoubleDef(sss[4], 0, nfi); CLOSE[j] = ToDoubleDef(sss[5], 0, nfi); VOLUME[j] = ToDoubleDef(sss[6], 0, nfi); Code = sss[0]; if (string.Compare(Code, "PRN", true) == 0) { Code = "PRNN"; } if (sss.Length > 7) { Name = sss[7]; } if (sss.Length > 8) { Exchange = sss[8]; } } CommonDataProvider cdp = new CommonDataProvider(this); if (Code != null) { cdp.SetStringData("Code", Code); } if (Name != null) { cdp.SetStringData("Name", Name); } if (Exchange != null) { cdp.SetStringData("Exchange", Exchange); } cdp.LoadBinary(new double[][] { OPEN, HIGH, LOW, CLOSE, VOLUME, DATE }); return(cdp); }