Exemplo n.º 1
0
        public GroupService.Queryinfo SendOrderHK(int Category, int PriceType, string Gddm, string Zqdm, float Price, int Quantity, StringBuilder result, StringBuilder errInfo)
        {
            GroupClient.GroupService.Queryinfo response = new GroupService.Queryinfo();
            try
            {
                TdxApi.QueryHKData(ClientID, 2, result, errInfo);
                var 单前ErrInfo = errInfo.ToString();
                if (单前ErrInfo != string.Empty)
                {
                    response.Result = result.ToString();
                    response.Error  = errInfo.ToString();
                }
                else
                {
                    response.Other = result.ToString();
                    TdxApi.SendHKOrder(ClientID, Category, 2, 0, Gddm, Zqdm, Price.ToString(), Quantity.ToString(), result, errInfo);
                }
            }
            catch (Exception ex)
            {
                response.Error += "下单异常:" + ex.Message;
            }

            return(response);
        }
Exemplo n.º 2
0
        public string Logon()
        {
            StringBuilder ErrInfo = new StringBuilder(256);

            try
            {
                this.ClientID = TdxApi.Logon(this.IP, this.Port, this.版本号, this.营业部代码, this.登录帐号, this.交易帐号, Cryptor.MD5Decrypt(this.交易密码), Cryptor.MD5Decrypt(this.通讯密码), ErrInfo);
            }
            catch (Exception ex)
            {
                this.ClientID = -1;
                ErrInfo.Append("登录异常,将自动禁用,请检查组合号信息!");
                this.启用 = false;
                CommonUtils.Log("组合号登录异常", ex);
            }

            if (ErrInfo.ToString() != string.Empty)
            {
                if (this.ClientID != -1)
                {
                    this.ClientID = -1;
                }
                return("登录失败:" + ErrInfo.ToString());
            }
            else
            {
                return("登录成功");
            }
        }
Exemplo n.º 3
0
        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);
                }
            }
        }
Exemplo n.º 4
0
        private void QueryData()
        {
            StringBuilder result  = new StringBuilder(1024 * 1024);
            StringBuilder errInfo = new StringBuilder(256);

            if (QueryInfo == null)
            {
                QueryInfo = new GroupService.QueryDataObj();
            }
            if (this.Multithreading == true)
            {
                QueryFilterData();
            }
            else
            {
                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();
                Thread.Sleep(查询间隔时间 / 2);
            }
        }
Exemplo n.º 5
0
        public Queryinfo QueryData(string GroupName, int Category)
        {
            StringBuilder result  = new StringBuilder(1024 * 1024);
            StringBuilder errInfo = new StringBuilder(256);

            if (Adapter.GroupsDict.ContainsKey(GroupName))
            {
                var group = Adapter.GroupsDict[GroupName];
                if (group.ClientID > -1)
                {
                    var dtStart = DateTime.Now;
                    TdxApi.QueryData(group.ClientID, Category, result, errInfo);

                    var logonInfoItem = Adapter.GroupLogonList.First(_ => _.Name == GroupName);
                    logonInfoItem.Times = (DateTime.Now - dtStart).TotalSeconds.ToString();
                }
                else
                {
                    errInfo.Append("查询失败,组合号" + GroupName + " ClientID为-1");
                }
            }
            else
            {
                errInfo.Append("查询失败:未找到该组合号对应的配置信息!");
            }

            return(new Queryinfo()
            {
                Result = result.ToString(), Error = errInfo.ToString()
            });
        }
Exemplo n.º 6
0
        /// <summary>
        /// A股下单逻辑
        /// </summary>
        public GroupService.Queryinfo SendOrderNormal(int Category, int PriceType, string Gddm, string Zqdm, float Price, int Quantity, StringBuilder result, StringBuilder errInfo)
        {
            StringBuilder sbResult = new StringBuilder(1024 * 1024);
            StringBuilder sbError  = new StringBuilder(256);

            GroupService.Queryinfo response = new GroupService.Queryinfo();
            try
            {
                sbResult.Append(this.strTitleWt + "\n" + string.Join("\n", dictWt.Values));
                sbError.Append(this.QueryInfo.SearchOperatorError);
                //if (this.Multithreading == true)
                //{
                //    TdxApi.QueryData(ClientID, 0, sbResult, sbError);
                //    sbResult.Clear();
                //    sbError.Clear();
                //    sbResult.Append(this.strTitleWt + "\n" + string.Join("\n", dictWt.Values));
                //    sbError.Append(this.QueryInfo.SearchOperatorError);
                //}
                //else
                //{
                //    TdxApi.QueryData(ClientID, 2, sbResult, sbError);
                //}

                var 单前ErrInfo = sbError.ToString();
                if (单前ErrInfo != string.Empty)
                {
                    response.Result = sbResult.ToString();
                    response.Error  = sbError.ToString();
                    CommonUtils.Log("A股下单前查询异常,证券代码" + Zqdm + ":" + response.Error);
                }
                else
                {
                    response.Other = result.ToString();
                    TdxApi.SendOrder(ClientID, Category, PriceType, Gddm, Zqdm, Price, Quantity, sbResult, sbError);

                    string ErrInfo = sbError.ToString();
                    if (ErrInfo == string.Empty)
                    {
                        DataTable DataTable1 = CommonUtils.ChangeDataStringToTable(sbResult.ToString());
                        string    id         = DataTable1.Rows[0]["委托编号"] as string;
                        if (Regex.IsMatch(id, "^[0-9]+$") && !lstOrderID.Contains(id))
                        {
                            lstOrderID.Add(id);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                CommonUtils.Log("下单异常", ex);
            }
            response.Result = sbResult.ToString();
            response.Error  = sbError.ToString();
            return(response);
        }
Exemplo n.º 7
0
 public void CancelHKOrder(string hth, StringBuilder resultCancel, StringBuilder errCancelInfo)
 {
     if (this.ClientID > -1)
     {
         try
         {
             StringBuilder result  = new StringBuilder(1024 * 1024);
             StringBuilder errInfo = new StringBuilder(256);
             TdxApi.QueryHKData(ClientID, 0, result, errInfo);
             result.Clear();
             errInfo.Clear();
             TdxApi.CancelHKOrder(ClientID, hth, result, errInfo);
         }
         catch (Exception ex)
         {
             CommonUtils.Log("CancelHKOrder Exception", ex);
         }
     }
 }
Exemplo n.º 8
0
        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);

            queueWt.Enqueue(resultWt.ToString());
            QueryInfo.SearchOperatorError = errInfoWt.ToString();
            Thread.Sleep(查询间隔时间 / 2);

            #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
        }
Exemplo n.º 9
0
 public void Logoff()
 {
     try
     {
         if (QeuryCJThread != null)
         {
             QeuryCJThread.Abort();
             FilteCjDataThread.Abort();
             FilteWtDataThread.Abort();
             lstOrderID = new ConcurrentBag <string>();
             dictWt.Clear();
             dictCj.Clear();
         }
         TdxApi.Logoff(this.ClientID);
         this.ClientID     = -1;
         QeuryCJThread     = null;
         FilteCjDataThread = null;
         FilteWtDataThread = null;
     }
     catch (Exception) { }
 }
Exemplo n.º 10
0
        public void CancelOrder(string ExchangeID, string hth, StringBuilder resultCancel, StringBuilder errCancelInfo)
        {
            if (this.ClientID > -1)
            {
                try
                {
                    DateTime dtStart = DateTime.Now;
                    //if (this.Multithreading == true)
                    //{
                    //    CommonUtils.Log(string.Format("{0} 开始撤单前查询", this.名称));
                    //}

                    //TdxApi.QueryData(this.ClientID, 0, resultCancel, errCancelInfo);

                    //if (this.Multithreading == true)
                    //{
                    //    //CommonUtils.Log(string.Format("{0}1.开始撤单前查询", this.名称));
                    //    CommonUtils.Log(string.Format("{0} 查询完毕,开始执行撤单,ExchangeID:{1}, hth:{2}", this.名称, ExchangeID, hth));
                    //}
                    TdxApi.CancelOrder(ClientID, ExchangeID, hth, resultCancel, errCancelInfo);

                    if (this.Multithreading == true)
                    {
                        CommonUtils.Log("{0}执行撤单完成, Result:{1}, Error:{2}, 耗时{3}", this.称, resultCancel.ToString(), errCancelInfo.ToString(), (DateTime.Now - dtStart).TotalSeconds.ToString());
                    }
                }
                catch (Exception ex)
                {
                    CommonUtils.Log(string.Format("{0}执行撤单异常,订单号{1}, Exception{2}", this.称, hth, ex.Message));
                }
            }
            else
            {
                errCancelInfo.AppendFormat("撤单失败,组合号{0} ClientID为-1", this.称);
            }
        }