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)); }
private void btnGet_Click(object sender, System.EventArgs e) { string[] ss = DownloadData("http://eoddata.com/SymbolList.asp?e=" + Exchange); DbParam[] dps = new DbParam[] { new DbParam("@QuoteCode", DbType.String, ""), new DbParam("@QuoteName", DbType.String, ""), new DbParam("@Exchange", DbType.String, Exchange), }; int succ = 0; int failed = 0; BaseDb bd = DB.Open(false); try { for (int i = 1; i < ss.Length; i++) { string[] rr = ss[i].Split('\t'); if (rr.Length != 2) { continue; } if (Exchange == "INDEX") { dps[0].Value = "^" + rr[0].Trim(); } else { dps[0].Value = rr[0].Trim(); } dps[1].Value = rr[1].Trim(); try { if (bd.GetFirstRow("select QuoteCode from StockData where QuoteCode=?", new DbParam[] { dps[0] }) == null) { bd.DoCommand("insert into stockdata (QuoteCode,QuoteName,Exchange) values (?,?,?)", dps); succ++; } } catch { failed++; } } } finally { bd.Close(); } lExchangeMsg.Text = "succ: " + succ + "; failed " + failed; }
public override void SaveSymbolList(string[] ss, out int succ, out int failed) { DbParam[] dps = new DbParam[] { new DbParam("@QuoteCode", DbType.String, ""), new DbParam("@QuoteName", DbType.String, ""), new DbParam("@Exchange", DbType.String, ""), }; succ = 0; failed = 0; // false to support mysql BaseDb bd = DB.Open(false); try { for (int i = 0; i < ss.Length; i++) { string[] rr = ss[i].Trim().Split(';'); if (rr.Length != 3) { continue; } dps[0].Value = rr[0].Trim(); dps[1].Value = rr[1].Trim(); dps[2].Value = rr[2].Trim(); try { if (bd.GetFirstRow("select QuoteCode from StockData where QuoteCode=?", new DbParam[] { dps[0] }) == null) { bd.DoCommand("insert into StockData (QuoteCode,QuoteName,Exchange) values (?,?,?)", dps); succ++; } } catch { failed++; } } } finally { bd.Close(); }; }
private void btnScan_Click(object sender, System.EventArgs e) { CurrentFullName = ddlFormula.SelectedItem.Value; Exchange = ddlExchange.SelectedItem.Value; string Param = ""; foreach (string s in Request.Form) { if (s.StartsWith("__Param")) { if (Param != "") { Param += ","; } Param += double.Parse(Request.Form[s]); } } Condition = CurrentFullName; if (Param != "") { Condition = CurrentFullName + "(" + Param + ")"; } DbParam[] dps = new DbParam[] { new DbParam("@Condition", DbType.String, Condition), new DbParam("@Exchange", DbType.String, Exchange), new DbParam("@StartTime", DbType.DateTime, DateTime.Now.AddHours(- Tools.ToIntDef(ConfigurationManager.AppSettings["ScanCacheTime"], 0))) }; bool b = true; BaseDb bd = DB.Open(true); try { DataRow dr = bd.GetFirstRow("select * from condition where Condition=? and Exchange=? and StartTime>?", dps); if (dr != null && !Config.KeepLatestScanResultOnly) { ConditionId = dr["ConditionId"].ToString(); b = false; } else { dps[2] = null; if (Config.KeepLatestScanResultOnly) { DataTable dt = bd.GetDataTable("select ConditionId from condition where Condition=? and Exchange=?", dps); foreach (DataRow drDel in dt.Rows) { bd.DoCommand("delete from ScanedQuote where ConditionId = " + drDel["ConditionId"]); } bd.DoCommand("delete from condition where Condition=? and Exchange=?", dps); } bd.DoCommand("insert into condition (Condition,Exchange,Scaned) values (?,?,0)", dps); ConditionId = bd.GetFirstRow("select max(ConditionId) from condition")[0].ToString(); } } finally { bd.Close(); } if (b) { ThreadPool.QueueUserWorkItem(new WaitCallback(Scanning), new ScanId(ConditionId, Condition, Exchange)); Response.Redirect("Progress.aspx?ConditionId=" + ConditionId); } else { Response.Redirect("StockList.aspx?ConditionId=" + ConditionId); } }
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)); }