void SyncStockInfo_SH() { int con = Convert.ToInt32(DicConSH["Con"]); short shortResult = (short)Convert.ToInt32(DicConSH["Count"]); short Count; bool bool1 = TdxApi.TdxHq_Multi_GetSecurityCount(con, 0, ref shortResult, ErrInfo); Console.WriteLine(bool1 ? shortResult.ToString() : ErrInfo.ToString()); int num = shortResult / 1000; int sum = 0; for (int x = 0; x <= num; x++) { int start = x * 1000; Count = shortResult; bool1 = TdxApi.TdxHq_Multi_GetSecurityList(con, 1, (short)start, ref Count, Result, ErrInfo); string[] strRow = Result.ToString().Split("\n".ToCharArray(), StringSplitOptions.RemoveEmptyEntries); //分解行的字符串 //string[] strCol=strRow[0].Split("\t".ToCharArray(), StringSplitOptions.RemoveEmptyEntries); Dictionary <string, string> Message = new Dictionary <string, string>(); Message.Add("Result", ""); Message.Add("ErrInfo", ""); for (int i = 1; i < strRow.Length; i++) { //分解行的字符串 //StockInfo属性 每列数据 string[] strCol = strRow[i].Split("\t".ToCharArray(), StringSplitOptions.RemoveEmptyEntries); if (strCol[6] == "0" || strCol[2].Contains("指数")) { continue; } StockInfo stock = new StockInfo(); stock.stockcode = strCol[0]; stock.Type = "1"; stock.OneHand = strCol[1]; stock.Name = strCol[2]; stock.PointIndex = strCol[4]; stock.YestClose = decimal.Parse(strCol[5]); stock.Unknow1 = strCol[3]; stock.Unknow2 = strCol[6]; stock.Unknow3 = strCol[7]; int ID = _Stockmanager.Add(stock); if (ID > 0) { sum += 1; string message = "Current sum is: " + start.ToString(); Message["Result"] = Result.ToString(); Message["ErrInfo"] = ErrInfo.ToString(); } else { //记录日志 Message["Result"] = Result.ToString(); Message["ErrInfo"] = ErrInfo.ToString(); continue; } } } }
public void DataAccess() { int ConnectionID = TdxApi.TdxHq_Multi_Connect(m_Server.IP, m_Server.Port, Result, ErrInfo); OverlistCon.Add(ConnectionID); _StockMinInfo.Clear(); Thread tdStockMinInfo = new Thread(SyncStocMinInfo); tdStockMinInfo.Start(); }
public void DataAccess() { bool bool1 = TdxApi.OpenTdx(ErrInfo); int ConnectionID = TdxApi.TdxHq_Multi_Connect(m_Server.IP, m_Server.Port, Result, ErrInfo); OverlistCon.Add(ConnectionID); int conSZ = OverlistCon[0]; OverlistCon.RemoveAt(0); bool1 = TdxApi.TdxHq_Multi_GetFinanceInfo(ConnectionID, 0, "000002", Result, ErrInfo); Console.WriteLine(bool1 ? Result.ToString() : ErrInfo.ToString()); _StockFinanceInfo.Clear(); Thread tdStock5MinInfo = new Thread(SyncStocFinanceInfo); tdStock5MinInfo.Start(); }
public void DataAccess() { #region 连接tdx服务器 bool bool1 = TdxApi.OpenTdx(ErrInfo); int ConnectionID = TdxApi.TdxHq_Multi_Connect(m_Server.IP, m_Server.Port, Result, ErrInfo); int ConnectionID2 = TdxApi.TdxHq_Multi_Connect(m_Server.IP, m_Server.Port, Result, ErrInfo); ALLlistCon.Add(ConnectionID); OverlistCon.Add(ConnectionID); #endregion int conSZ = OverlistCon[0]; OverlistCon.RemoveAt(0); short Count = 0; //SZ 后台查询Count bool1 = TdxApi.TdxHq_Multi_GetSecurityCount(conSZ, 0, ref Count, ErrInfo); DicCon.Add("Con", conSZ.ToString()); DicCon.Add("Count", Count.ToString()); //SZ 后台执行 ALLlistCon.Add(ConnectionID2); OverlistCon.Add(ConnectionID2); int conSH = OverlistCon[0]; OverlistCon.RemoveAt(0); //SH 后台查询Count bool1 = TdxApi.TdxHq_Multi_GetSecurityCount(conSH, 1, ref Count, ErrInfo); DicConSH.Add("Con", conSH.ToString()); DicConSH.Add("Count", Count.ToString()); //SZ 后台执行 _Stockmanager.Clear(); Thread tdSyncStock_SH = new Thread(SyncStockInfo_SH); tdSyncStock_SH.Start(); Thread tdSyncStock_SZ = new Thread(SyncStockInfo_SZ); tdSyncStock_SZ.Start(); }
public DataAccessFromTdx() { bool bool1 = TdxApi.OpenTdx(ErrInfo); }
void SyncStoc5MinkInfo() { bool bool1 = TdxApi.OpenTdx(ErrInfo); int ConnectionID = TdxApi.TdxHq_Multi_Connect(m_Server.IP, m_Server.Port, Result, ErrInfo); ALLlistCon.Add(ConnectionID); OverlistCon.Add(ConnectionID); //设置 这个bk 在工作 List <StockInfo> stockList = _oStockInfo.GetStockCodeList("TYPE=0"); Dictionary <string, string> Message = new Dictionary <string, string>(); Message.Add("Result", ""); Message.Add("ErrInfo", ""); foreach (StockInfo s in stockList) { //try //{ short Count = 10; bool1 = TdxApi.TdxHq_Multi_GetSecurityBars(ConnectionID, 0, 0, s.stockcode, 0, ref Count, Result, ErrInfo); if (Count != 0) { string[] strRow = Result.ToString().Split("\n".ToCharArray(), StringSplitOptions.RemoveEmptyEntries); //分解行的字符串 //string[] strColX = strRow[1].Split("\t".ToCharArray(), StringSplitOptions.RemoveEmptyEntries); //时间 开盘价 收盘价 最高价 最低价 成交量 成交额 涨家数 跌家数 for (int i = 1; i < strRow.Length; i++) { string[] strCol = strRow[i].Split("\t".ToCharArray(), StringSplitOptions.RemoveEmptyEntries); Stock5MinInfo stock = new Stock5MinInfo(); if (!PublicTool.CanDateTime(strCol[0].Replace("--", "-"))) { continue; } int IsHave = _oStock5MinInfo.GetRecordCount("Symbol='" + s.stockcode + "' and Time=CONVERT(datetime,'" + strCol[0].Replace("--", "-") + "',102)"); if (IsHave > 0) { continue; } stock.StockCode = s.stockcode; stock.Time = Convert.ToDateTime(strCol[0].Replace("--", "-")); stock.open = decimal.Parse(PublicTool.IsNumElseToZero(strCol[1])); stock.Close = decimal.Parse(PublicTool.IsNumElseToZero(strCol[2])); stock.High = decimal.Parse(PublicTool.IsNumElseToZero(strCol[3])); stock.Low = decimal.Parse(PublicTool.IsNumElseToZero(strCol[4])); stock.Volume = strCol[5]; stock.Turnover = strCol[6]; //stock.UpNum = strCol[7]; //stock.DownNum = strCol[8]; int ID = _oStock5MinInfo.Add(stock); if (ID > 0) { string message = "Current tiem is: " + Convert.ToDateTime(strCol[0].Replace("--", "-")); //ReportProgress 方法把信息传递给 ProcessChanged 事件处理函数。 //第一个参数类型为 int,表示执行进度。 //如果有更多的信息需要传递,可以使用 ReportProgress 的第二个参数。 //这里我们给第二个参数传进去一条消息。 Message["Result"] = Result.ToString(); Message["ErrInfo"] = ErrInfo.ToString(); Message["Message"] = message.ToString(); } else { //记录日志 Message["Result"] = Result.ToString(); Message["ErrInfo"] = ErrInfo.ToString(); Message["Message"] = ""; continue; } } } else { Count = 10; bool1 = TdxApi.TdxHq_Multi_GetSecurityBars(ConnectionID, 0, 0, s.stockcode, 0, ref Count, Result, ErrInfo); } } ALLlistCon.Remove(ConnectionID); OverlistCon.Remove(ConnectionID); TdxApi.TdxHq_Multi_Disconnect(ConnectionID); }
void SyncStocFinanceInfo() { //IsFinanceWork = true; int ConnectionID = TdxApi.TdxHq_Multi_Connect("222.73.49.4", 7709, Result, ErrInfo); ALLlistCon.Add(ConnectionID); OverlistCon.Add(ConnectionID); List <StockInfo> stockList = new List <StockInfo>(); stockList = _oStockInfo.GetStockCodeList(""); Dictionary <string, string> Message = new Dictionary <string, string>(); Message.Add("Result", ""); Message.Add("ErrInfo", ""); bool bool1; #region foreach foreach (StockInfo s in stockList) { //try //{ bool1 = TdxApi.TdxHq_Multi_GetFinanceInfo(ConnectionID, Convert.ToByte(s.Type), s.stockcode, Result, ErrInfo); ///出错 if (!bool1 || Result.ToString() == "") { //记录日志 continue; } string[] strRow = Result.ToString().Split("\n".ToCharArray(), StringSplitOptions.RemoveEmptyEntries); //分解行的字符串 string[] strColX = strRow[1].Split("\t".ToCharArray(), StringSplitOptions.RemoveEmptyEntries); //Console.WriteLine(Result.ToString()); for (int i = 1; i < strRow.Length; i++) { string[] strCol = strRow[i].Split("\t".ToCharArray(), StringSplitOptions.RemoveEmptyEntries); if (!(strCol[5].Replace("--", "-") != "0" && strCol[6].Replace("--", "-") != "0")) { continue; } int IsHave = _StockFinanceInfo.GetRecordCount("Symbol='" + s.stockcode + "' and CWUpdateTime=CONVERT(datetime,'" + strCol[5].Replace("--", "-") + "',102)"); if (IsHave > 0) { continue; } StockFinanceInfo stock = new StockFinanceInfo(); stock.Type = strCol[0]; stock.Code = strCol[1]; stock.GBLT = strCol[2]; stock.SSSF = strCol[3]; stock.SSHY = strCol[4]; stock.CWUpdateTime = DateTime.ParseExact(strCol[5], "yyyyMMdd", System.Globalization.CultureInfo.CurrentCulture); stock.ListingDate = DateTime.ParseExact(strCol[6], "yyyyMMdd", System.Globalization.CultureInfo.CurrentCulture); stock.AllGB = strCol[7]; stock.GJG = strCol[8]; stock.FQRFRG = strCol[9]; stock.FRG = strCol[10]; stock.BG = strCol[11]; stock.HG = strCol[12]; stock.ZhGG = strCol[13]; stock.AllZC = strCol[14]; stock.LDZC = strCol[15]; stock.GDZC = strCol[16]; stock.WXZC = strCol[17]; stock.GDRS = strCol[18]; stock.LDFZ = strCol[19]; stock.CQFZ = strCol[20]; stock.ZBGJJ = strCol[21]; stock.JZC = strCol[22]; stock.ZYSR = strCol[23]; stock.ZYLR = strCol[24]; stock.YSZK = strCol[25]; stock.YYLR = strCol[26]; stock.TZSY = strCol[27]; stock.JYXJL = strCol[28]; stock.ZXJL = strCol[29]; stock.CH = strCol[20]; stock.LRZE = strCol[31]; stock.SHLR = strCol[32]; stock.JLR = strCol[33]; stock.WFLR = strCol[34]; stock.Unknow1 = strCol[35]; stock.unknow2 = strCol[36]; int ID = _StockFinanceInfo.Add(stock); if (ID > 0) { string message = "Current tiem is: " + s.stockcode + " type:" + s.Type; //ReportProgress 方法把信息传递给 ProcessChanged 事件处理函数。 //第一个参数类型为 int,表示执行进度。 //如果有更多的信息需要传递,可以使用 ReportProgress 的第二个参数。 //这里我们给第二个参数传进去一条消息。 Message["Result"] = Result.ToString(); Message["ErrInfo"] = ErrInfo.ToString(); Message["Message"] = message.ToString(); //bk_FinanceInfo.ReportProgress(i, Message); } else { //记录日志 Message["Result"] = Result.ToString(); Message["ErrInfo"] = ErrInfo.ToString(); Message["Message"] = ""; //bk_FinanceInfo.ReportProgress(i, Message); continue; } } //} //catch //{ // //记录日志 // continue; //} //finally //{ //} } #endregion ALLlistCon.Remove(ConnectionID); OverlistCon.Remove(ConnectionID); TdxApi.TdxHq_Multi_Disconnect(ConnectionID); //IsFinanceWork = false; }
void SyncStocMinInfo() { byte[] Market = { 0, 1 }; string[] Zqdm = { "000001", "600030" }; short ZqdmCount = 2; int ConnectionID = TdxApi.TdxHq_Multi_Connect(m_Server.IP, m_Server.Port, Result, ErrInfo); ALLlistCon.Add(ConnectionID); OverlistCon.Add(ConnectionID); List <StockInfo> stockList = new List <StockInfo>(); stockList = _oStockInfo.GetStockCodeList(""); Dictionary <string, string> Message = new Dictionary <string, string>(); Message.Add("Result", ""); Message.Add("ErrInfo", ""); bool bool1; bool1 = TdxApi.TdxHq_Multi_GetSecurityQuotes(ConnectionID, Market, Zqdm, ref ZqdmCount, Result, ErrInfo); #region foreach foreach (StockInfo s in stockList) { //try //{ bool1 = TdxApi.TdxHq_Multi_GetMinuteTimeData(ConnectionID, Convert.ToByte(s.Type), s.stockcode, Result, ErrInfo); //bool1 = TdxApi.TdxHq_Multi_GetHistoryMinuteTimeData(ConnectionID, Convert.ToByte(s.Type), s.stockcode, 20180111, Result, ErrInfo); //bool1 = TdxApi.TdxHq_Multi_GetTransactionData(ConnectionID, Convert.ToByte(s.Type), s.stockcode, 1, ref sssss, Result, ErrInfo); ///出错 if (!bool1 || Result.ToString() == "") { //记录日志 continue; } string[] strRow = Result.ToString().Split("\n".ToCharArray(), StringSplitOptions.RemoveEmptyEntries); //分解行的字符串 string[] strColX = strRow[1].Split("\t".ToCharArray(), StringSplitOptions.RemoveEmptyEntries); //Console.WriteLine(Result.ToString()); for (int i = 1; i < strRow.Length; i++) { string[] strCol = strRow[i].Split("\t".ToCharArray(), StringSplitOptions.RemoveEmptyEntries); if (!(strCol[5].Replace("--", "-") != "0" && strCol[6].Replace("--", "-") != "0")) { continue; } int IsHave = _StockMinInfo.GetRecordCount("Symbol='" + s.stockcode + "' and CWUpdateTime=CONVERT(datetime,'" + strCol[5].Replace("--", "-") + "',102)"); if (IsHave > 0) { continue; } StockMinInfo stock = new StockMinInfo(); stock.Type = strCol[0]; int ID = _StockMinInfo.Add(stock); if (ID > 0) { string message = "Current tiem is: " + s.stockcode + " type:" + s.Type; //ReportProgress 方法把信息传递给 ProcessChanged 事件处理函数。 //第一个参数类型为 int,表示执行进度。 //如果有更多的信息需要传递,可以使用 ReportProgress 的第二个参数。 //这里我们给第二个参数传进去一条消息。 Message["Result"] = Result.ToString(); Message["ErrInfo"] = ErrInfo.ToString(); Message["Message"] = message.ToString(); //bk_FinanceInfo.ReportProgress(i, Message); } else { //记录日志 Message["Result"] = Result.ToString(); Message["ErrInfo"] = ErrInfo.ToString(); Message["Message"] = ""; //bk_FinanceInfo.ReportProgress(i, Message); continue; } } //} //catch //{ // //记录日志 // continue; //} //finally //{ //} } #endregion ALLlistCon.Remove(ConnectionID); OverlistCon.Remove(ConnectionID); TdxApi.TdxHq_Multi_Disconnect(ConnectionID); //IsFinanceWork = false; }