private void QueryImsData() { try { StringBuilder Result = new StringBuilder(1024 * 1024); StringBuilder ErrInfo = new StringBuilder(1024); ImsApi.ImsPbClient_QueryProductOrder(lastOrderUpdateTime, Result, ErrInfo); QueryInfo.SearchOperatorError = ErrInfo.ToString(); QueryInfo.SearchOperatorResult = Result.ToString(); if (QueryInfo.SearchOperatorError.Contains("网络已中断, 请重新连接")) { this.ClientID = -1; this.Logoff(); return; } //if (!string.IsNullOrEmpty(QueryInfo.SearchOperatorResult)) //{ // var tableWT = Tool.ChangeDataStringToTable(Result.ToString()); // if (tableWT.Rows.Count > 0) // { // lastOrderUpdateTime = tableWT.Rows[0]["lastupdatetime"].ToString(); // } //} Thread.Sleep(查询间隔时间 / 2); ImsApi.ImsPbClient_QueryProductKnock(serialNumm, Result, ErrInfo); QueryInfo.SearchTradeErrInfo = ErrInfo.ToString(); QueryInfo.SearchTradeResult = Result.ToString(); if (QueryInfo.SearchTradeErrInfo.Contains("网络已中断, 请重新连接")) { this.ClientID = -1; this.Logoff(); return; } //if (!string.IsNullOrEmpty(QueryInfo.SearchTradeResult)) //{ // var tableCJ = Tool.ChangeDataStringToTable(Result.ToString()); // if (tableCJ.Rows.Count > 0) // { // serialNumm = (int)tableCJ.Rows[0]["serialNum"]; // } //} Thread.Sleep(查询间隔时间 / 2); } catch (Exception ex) { CommonUtils.Log("QueryImsData Exception:", ex); } //如何计算 serialNumm }
private void Button_SearchAccountInfo_Click(object sender, RoutedEventArgs e) { var entity = this.GetPageEntity(); ImsApi.Init(ImsNotify); string errMsg = string.Empty; bool isLogin = ImsApi.Login(entity.交易帐号, Cryptor.MD5Decrypt(entity.交易密码), entity.版本号, out errMsg); if (!string.IsNullOrEmpty(errMsg) || isLogin) { MessageBox.Show(errMsg); return; } StringBuilder Result = new StringBuilder(1024); StringBuilder ErrInfo = new StringBuilder(1024); if (string.IsNullOrEmpty(txt产品信息.Text)) { ImsApi.ImsPbClient_RequestProductList(0, Result, ErrInfo); lblErrInfo产品信息.Text = ErrInfo.ToString(); var dt = CommonUtils.ChangeDataStringToTable(Result.ToString()); if (dt != null && dt.Rows.Count > 0 && dt.Columns.Contains("productid")) { this.txt产品信息.Text = dt.Rows[0]["productid"] + ""; } } if (string.IsNullOrEmpty(txt资产单元.Text)) { ImsApi.ImsPbClient_RequestProductList(1, Result, ErrInfo); //this.txt资产单元.Text = Result.ToString(); this.lblErrInfo资产单元.Text = ErrInfo.ToString(); var dt = CommonUtils.ChangeDataStringToTable(Result.ToString()); if (dt != null && dt.Rows.Count > 0 && dt.Columns.Contains("productunitid")) { this.txt资产单元.Text = dt.Rows[0]["productunitid"] + ""; } } if (string.IsNullOrEmpty(txt投资组合.Text)) { ImsApi.ImsPbClient_RequestProductList(2, Result, ErrInfo); //this.txt投资组合.Text = Result.ToString(); this.lblErrInfo投资组合.Text = ErrInfo.ToString(); var dt = CommonUtils.ChangeDataStringToTable(Result.ToString()); if (dt != null && dt.Rows.Count > 0 && dt.Columns.Contains("portfolioid")) { this.txt投资组合.Text = dt.Rows[0]["portfolioid"] + ""; } } btnSave.IsEnabled = true; }
/// <summary> /// /// </summary> /// <param name="BSFlag">B 买, S 卖</param> /// <param name="Market">上海0 深圳1 港股H 沪港通0H 沪股通H0 深港通1H 深股通H1</param> /// <param name="Zqdm"></param> /// <param name="Price"></param> /// <param name="Quantity"></param> /// <param name="result"></param> /// <param name="errInfo"></param> public void SendOrderIMS(string BSFlag, string Market, string Zqdm, float Price, int Quantity, StringBuilder result, StringBuilder errInfo) { try { ImsApi.ImsPbClient_RequestNormalOrder(this.产品信息, this.资产单元, this.投资组合, Market, Zqdm, BSFlag, Quantity, Convert.ToDouble(Price.ToString()), "LIMIT", string.Empty, "我的备注", result, errInfo); CommonUtils.Log("SendOrderIMS Result:{0}, ErrorInfo{1}", result.ToString(), errInfo.ToString()); } catch (Exception ex) { errInfo.Append("SendOrderIMS Exception:" + ex.Message); } }
public string Logon() { StringBuilder ErrInfo = new StringBuilder(256); if (IsIMSAccount) { string Msg; ImsApi.Init(ImsNotify); bool isLogin = ImsApi.Login(this.交易帐号, Cryptor.MD5Decrypt(this.交易密码), this.版本号, out Msg); if (isLogin) { this.ClientID = 0; return("登录成功"); } else { return(Msg); } } else { try { this.ClientID = TdxApi.Logon(this.IP, this.Port, this.版本号, this.营业部代码, this.登录帐号, this.交易帐号, Cryptor.MD5Decrypt(this.交易密码), Cryptor.MD5Decrypt(this.通讯密码), ErrInfo); } catch (Exception ex) { CommonUtils.Log("组合号登录异常", ex); } string strError = ErrInfo.ToString(); if (!string.IsNullOrEmpty(strError)) { //交易中心(-10016):您使用的版本太低已因为安全原因停止使用,请到官网上下载最新版本重新安装。 if (strError.Contains("密码") || strError.Contains("您使用的版本太低已因为安全原因停止使用")) { //ErrInfo.Append("登录异常,将自动禁用,请检查组合号信息!"); CommonUtils.Log("登录密码错误或版本过低导致登录失败,将自动停用,错误信息:{0}", strError); this.启用 = false; } return("登录失败:" + ErrInfo.ToString()); } else { return("登录成功"); } } }
public void Logoff() { try { if (this.IsIMSAccount) { ImsApi.ImsPbClient_Disconnect(); } else { TdxApi.Logoff(this.ClientID); } } catch { } this.ClientID = -1; }
void worker_DoWork(object sender, DoWorkEventArgs e) { CommonUtils.Log("启动服务中…"); TdxApi.OpenTdx(); InitService(); adapter.Start(); this.Dispatcher.BeginInvoke(DispatcherPriority.Normal, new Action(() => { this.dgState.ItemsSource = Adapter.GroupLogonList; })); while (!this.worker.CancellationPending) { //try //{ // this.Dispatcher.BeginInvoke(DispatcherPriority.Normal, new Action(() => // { // this.dgState.Items.Refresh(); // })); //} //catch (Exception) { } Thread.Sleep(1000); } CommonUtils.Log("服务关闭中…"); adapter.Stop(); TdxApi.CloseTdx(); ImsApi.Close(); if (this.ServiceHost1.State != CommunicationState.Faulted) { this.ServiceHost1.Close(); } CommonUtils.Log("服务已关闭!"); }
/// <summary> /// /// </summary> /// <param name="market">上海0 深圳1</param> /// <param name="zqdm"></param> /// <param name="orderID"></param> /// <param name="Result"></param> /// <param name="ErrInfo"></param> public void CancelImsOrder(string market, string zqdm, string orderID, StringBuilder Result, StringBuilder ErrInfo) { ImsApi.ImsPbClient_CancelNormalOrder(this.资产单元, this.投资组合, market, zqdm, orderID, string.Empty, Result, ErrInfo); }