/// <summary> /// 通达信接口-交易数据查询 /// </summary> /// <param name="o">券商</param> /// <param name="tradeDataType">表示查询信息的种类,0资金 1股份 2当日委托 3当日成交 4可撤单 5股东代码 6融资余额 7融券余额 8可融证券</param> /// <returns></returns> public static DataTable QueryTradeData(券商 o, int tradeDataType) { DataTable dt = null; StringBuilder ErrInfo = new StringBuilder(256); StringBuilder result = new StringBuilder(1024 * 1024); if (o.营业部代码 == 8888 && (DateTime.Now.Hour > 15 || DateTime.Now.Hour < 9)) { o.营业部代码 = 24; o.IP = "124.74.242.150"; o.Port = 443; } var ClientID = TdxApi.Logon(o.IP, o.Port, o.版本号, o.营业部代码, o.登录帐号, o.交易帐号, o.TradePsw, o.CommunicatePsw, ErrInfo); if (ErrInfo.Length > 0) { CommonUtils.ShowMsg(ErrInfo.ToString()); } else { TdxApi.QueryData(ClientID, tradeDataType, result, ErrInfo); if (ErrInfo.Length == 0) { dt = CommonUtils.ChangeDataStringToTable(result.ToString()); } else { CommonUtils.ShowMsg(ErrInfo.ToString()); } } TdxApi.Logoff(ClientID); return(dt); }
/// <summary> /// 通达信接口-历史数据查询(默认查询交割单) /// </summary> /// <param name="st">开始时间</param> /// <param name="et">结束时间</param> /// <param name="o">券商</param> /// <param name="historyDataType">表示查询信息的种类,0历史委托 1历史成交 2交割单</param> /// <returns></returns> public static DataTable QueryHisData(DateTime st, DateTime et, 券商 o, int historyDataType = 2, bool originalData = false) { DataTable dt = null; StringBuilder ErrInfo = new StringBuilder(256); //StringBuilder result = new StringBuilder(1024 * 1024); queryHisResult.Clear(); if (o.营业部代码 == 8888) { if (DateTime.Today.DayOfWeek == DayOfWeek.Sunday || DateTime.Today.DayOfWeek == DayOfWeek.Saturday || DateTime.Now.Hour <= 9 || DateTime.Now.Hour >= 15) { o.营业部代码 = 24; o.IP = "124.74.242.150"; o.Port = 443; } } var ClientID = TdxApi.Logon(o.IP, o.Port, o.版本号, o.营业部代码, o.登录帐号, o.交易帐号, o.TradePsw, o.CommunicatePsw, ErrInfo); if (ErrInfo.Length > 0) { CommonUtils.Log(string.Format("通达信接口登录失败, 组合号:{0}, 起始日期:{1},结束日期:{2} ,错误信息:{3}", o.称, st.ToString(), et.ToString(), ErrInfo.ToString())); } else { DateTime searchEndDate = et; if (StrangeGroups.Contains(o.称) && st == et) { searchEndDate = et.AddDays(1); } TdxApi.QueryHistoryData(ClientID, historyDataType, st.ToString("yyyyMMdd"), searchEndDate.ToString("yyyyMMdd"), queryHisResult, ErrInfo); if (ErrInfo.Length == 0) { dt = CommonUtils.ChangeDataStringToTable(queryHisResult.ToString()); if (!originalData && historyDataType == 2) { FilteTableData(o, st, et, dt); CheckDataIntegrity(st, et, o, dt, ErrInfo, queryHisResult, ClientID); RepairData(o, dt); } } else { CommonUtils.Log("通达信接口查询失败,错误信息" + ErrInfo.ToString()); } } TdxApi.Logoff(ClientID); return(dt); }