public string Test(string IP, short Port, string Version, short YybID, string AccountNo, string TradeAccount, string JyPassword, string TxPassword) { try { StringBuilder Result = new StringBuilder(1024 * 1024); StringBuilder ErrInfo = new StringBuilder(256); int ClientID = TdxApi.Logon(IP, Port, Version, YybID, AccountNo, TradeAccount, JyPassword, TxPassword, ErrInfo); if (ClientID == -1) { return(string.Format("{0}|{1}", ClientID, ErrInfo)); } TdxApi.QueryData(ClientID, 5, Result, ErrInfo); TdxApi.Logoff(ClientID); return(string.Format("{0}|{1}", Result, ErrInfo)); } catch (Exception ex) { return(ex.Message); } }
private void QueryCJMain() { StringBuilder resultCJ = new StringBuilder(1024 * 1024); StringBuilder errInfoCJ = new StringBuilder(256); while (true) { DateTime dt = DateTime.Now; if ((DateTime.Parse(CommonUtils.GetConfig("开始查询时间", "8:15")) <= DateTime.Now && DateTime.Now <= DateTime.Parse(CommonUtils.GetConfig("结束查询时间", "15:30")))) { try { TdxApi.QueryData(ClientID, 3, resultCJ, errInfoCJ); queueCj.Enqueue(resultCJ.ToString()); QueryInfo.SearchTradeErrInfo = errInfoCJ.ToString(); } catch (Exception ex) { CommonUtils.Log("成交查询异常", ex); } Thread.Sleep(查询间隔时间); } else { Thread.Sleep(10000); } } }
/// <summary> /// /// </summary> /// <param name="dataType">表示查询信息的种类,0资金 1股份 2当日委托 3当日成交 4可撤单 5股东代码 6融资余额 7融券余额 8可融证券</param> /// <returns></returns> internal void QueryAccountData(int dataType, GroupClient.GroupService.Queryinfo QueryResult) { StringBuilder result = new StringBuilder(1024 * 1024); StringBuilder errInfo = new StringBuilder(256); try { if (this.ClientID == -1) { this.ClientID = TdxApi.Logon(this.IP, this.Port, this.版本号, this.营业部代码, this.登录帐号, this.交易帐号, Cryptor.MD5Decrypt(this.交易密码), Cryptor.MD5Decrypt(this.通讯密码), errInfo); isLogonInterim = this.ClientID > -1; } if (this.ClientID > -1) { TdxApi.QueryData(this.ClientID, dataType, result, errInfo); } } catch (Exception ex) { errInfo.AppendFormat("查询接口异常:{0}", ex.Message); } QueryResult.Error = errInfo.ToString(); QueryResult.Result = result.ToString(); if (isLogonInterim) { isLogonInterim = false; } }
public bool Test(string IP, short Port, string Version, short YybID, string AccountNo, string TradeAccount, string JyPassword, string TxPassword) { try { StringBuilder Result = new StringBuilder(1024 * 1024); StringBuilder ErrInfo = new StringBuilder(256); int ClientID = TdxApi.Logon(IP, Port, Version, YybID, AccountNo, TradeAccount, JyPassword, TxPassword, ErrInfo); if (ClientID == -1) { MessageBox.Show("登录测试失败:" + ErrInfo.ToString()); return(false); } TdxApi.QueryData(ClientID, 5, Result, ErrInfo); TdxApi.Logoff(ClientID); return(true); } catch (Exception ex) { CommonUtils.Log("组合号添加异常:" + ex.Message); return(false); } }
private void QueryFilterData() { StringBuilder resultWt = new StringBuilder(1024 * 1024); StringBuilder errInfoWt = new StringBuilder(256); DateTime dt1 = DateTime.Now; TdxApi.QueryData(this.ClientID, 2, resultWt, errInfoWt); var span = DateTime.Now - dt1; var costsSeconds = span.TotalSeconds; //CommonUtils.Log("{0}委托查询单次耗时{1}", this.名称, costsSeconds.ToString()); queueWt.Enqueue(resultWt.ToString()); QueryInfo.SearchOperatorError = errInfoWt.ToString(); Thread.Sleep(查询间隔时间); #region 其他线程 if (QeuryCJThread == null) { QeuryCJThread = new Thread(new ThreadStart(QueryCJMain)) { IsBackground = true }; QeuryCJThread.Start(); } if (FilteWtDataThread == null) { FilteWtDataThread = new Thread(new ThreadStart(FilterWtDataMain)) { IsBackground = true }; FilteWtDataThread.Start(); } if (FilteCjDataThread == null) { FilteCjDataThread = new Thread(new ThreadStart(FilterCjDataMain)) { IsBackground = true }; FilteCjDataThread.Start(); } #endregion }
private void QueryData() { if (QueryInfo == null) { QueryInfo = new GroupService.QueryDataObj(); } if (this.IsIMSAccount) { QueryImsData(); return; } if (this.Multithreading == true) { QueryFilterData(); } else { StringBuilder result = new StringBuilder(1024 * 1024); StringBuilder errInfo = new StringBuilder(256); TdxApi.QueryData(this.ClientID, 3, result, errInfo); QueryInfo.SearchTradeResult = result.ToString(); QueryInfo.SearchTradeErrInfo = errInfo.ToString(); Thread.Sleep(查询间隔时间 / 2); TdxApi.QueryData(this.ClientID, 2, result, errInfo); QueryInfo.SearchOperatorResult = result.ToString(); QueryInfo.SearchOperatorError = errInfo.ToString(); if (QueryInfo.SearchTradeErrInfo.Contains("请尝试其它交易服务器") && QueryInfo.SearchOperatorError.Contains("请尝试其它交易服务器")) { CommonUtils.Log("检测到{0}连接交易服务器失败信息,尝试注销登录后重新登录", this.称); this.Logoff(); this.Logon(); } Thread.Sleep(查询间隔时间 / 2); } }