Exemplo n.º 1
0
        /// <summary>
        /// A股下单逻辑
        /// </summary>
        public GroupService.Queryinfo SendOrderNormal(int Category, int PriceType, string Gddm, string Zqdm, float Price, int Quantity, string mac, StringBuilder result, StringBuilder errInfo)
        {
            DateTime st = DateTime.Now;

            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);

                var 单前ErrInfo = sbError.ToString();
                if (单前ErrInfo != string.Empty)
                {
                    response.Result = sbResult.ToString();
                    response.Error  = sbError.ToString();
                    CommonUtils.Log("下单前查询异常,组合号{0},证券代码{1},错误信息{2},耗时{3}", this.称, Zqdm, response.Error, (DateTime.Now - st).TotalSeconds.ToString());
                }
                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 = null;
                        if (DataTable1.Columns.Contains("委托编号"))
                        {
                            id = DataTable1.Rows[0]["委托编号"] as string;
                        }
                        else if (DataTable1.Columns.Contains("合同编号"))
                        {
                            id = DataTable1.Rows[0]["合同编号"] as string;
                        }
                        if (id != null && !lstOrderID.Contains(id))
                        {
                            lstOrderID.Add(id);
                            dictOrderSuccessTime[id] = DateTime.Now;
                        }
                    }
                    else
                    {
                        CommonUtils.Log("下单异常,组合号{0},证券代码{1},错误信息{2}", this.称, Zqdm, ErrInfo);
                        if (ErrInfo.Contains("尝试其他交易服务器") || ErrInfo.Contains("超时"))
                        {
                            CommonUtils.Log("开始记录可能存在漏单数据");
                            var mayLostOrder = new OrderInfoCache()
                            {
                                Category  = Category,
                                GroupName = this.称,
                                SendPrice = Price,
                                SendQty   = Quantity,
                                StockID   = Zqdm,
                                SendTime  = DateTime.Now,
                                SendMac   = mac,
                            };
                            CommonUtils.Log("可能存在漏单数据,请求数据{0}", mayLostOrder.ToJson());
                            var table = Tool.ChangeDataStringToTable(this.QueryInfo.SearchOperatorResult);
                            if (table != null && table.Rows.Count > 0)
                            {
                                mayLostOrder.CheckedIndex = table.Rows.Count;
                            }
                            queueMayLostOrder.Enqueue(mayLostOrder);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                CommonUtils.Log("下单异常,组合号{0}, 股票代码{1},异常信息{2}", this.称, Zqdm, ex.Message);
            }
            response.Result = sbResult.ToString();
            response.Error  = sbError.ToString();
            return(response);
        }
Exemplo n.º 2
0
        public string[] FilterDataByOrder(string result, string mac)
        {
            string[]      lstQuery = null;
            StringBuilder strWhere = new StringBuilder();

            try
            {
                string orderColName = string.Empty;
                //CommonUtils.Log(result);
                if (dictMacOrder.ContainsKey(mac))
                {
                    DataTable dtResult = Tool.ChangeDataStringToTable(result);
                    if (dtResult == null || dtResult.Rows.Count == 0)
                    {
                        return(null);
                    }

                    if (dtResult.Columns.Contains("合同编号"))
                    {
                        orderColName = "合同编号";
                    }
                    else if (dtResult.Columns.Contains("委托编号"))
                    {
                        orderColName = "委托编号";
                    }
                    //else if (dtResult.Columns.Contains("contractNum"))
                    //    orderColName = "contractNum";

                    ConcurrentBag <string> order = dictMacOrder[mac];
                    if (string.IsNullOrEmpty(orderColName) || order == null || order.Count == 0)
                    {
                        if (dtResult.Columns.Contains("撤单标志"))
                        {
                            strWhere.AppendFormat(" 撤单标志 <> '1'");
                        }
                        lstQuery = Tool.QueryDataTableByWhere(dtResult, strWhere.ToString());
                    }
                    else
                    {
                        OrderInfoCache mayLostOrd;
                        if (queueMayLostOrder.Count > 0 && queueMayLostOrder.TryPeek(out mayLostOrd))
                        {
                            if ((DateTime.Now - mayLostOrd.SendTime).TotalSeconds > 30)
                            {
                                queueMayLostOrder.TryDequeue(out mayLostOrd);
                            }
                            else if (dtResult.Columns.Contains("证券代码") && dtResult.Columns.Contains("买卖标志") && dtResult.Columns.Contains("委托价格") && dtResult.Columns.Contains("委托数量"))
                            {
                                //验证是否可以进行补漏行为
                                for (int i = Math.Max(0, mayLostOrd.CheckedIndex); i < dtResult.Rows.Count; i++)
                                {
                                    DataRow row = dtResult.Rows[i];
                                    if (!order.Contains(row[orderColName].ToString()))
                                    {
                                        bool isDataSame = mayLostOrd.StockID == row["证券代码"].ToString() &&
                                                          CommonUtils.IsTdxBuy(mayLostOrd.Category) == CommonUtils.IsTdxBuy(int.Parse(row["买卖标志"] + "")) &&
                                                          (mayLostOrd.SendPrice == float.Parse(row["委托价格"] + "")) &&
                                                          (mayLostOrd.SendQty == decimal.Parse(row["委托数量"] + ""));
                                        if (isDataSame)
                                        {
                                            order.Add(row[orderColName].ToString());

                                            CommonUtils.Log("匹配到可能漏单数据{0},已加入返回信息", mayLostOrd.ToJson());
                                            break;
                                        }
                                    }
                                }
                            }
                        }
                        StringBuilder sbOrder = new StringBuilder();
                        sbOrder.Append("'");
                        sbOrder.Append(string.Join("','", order.ToArray()));
                        sbOrder.Append("'");
                        //foreach (var item in order)
                        //{
                        //    sbOrder.AppendFormat(string.Format("'{0}',"), item);
                        //}
                        strWhere.AppendFormat("{0} in ({1})", orderColName, sbOrder.ToString());

                        if (dtResult.Columns.Contains("撤单标志"))
                        {
                            strWhere.AppendFormat(" and 撤单标志 <> '1'");
                        }
                        lstQuery = Tool.QueryDataTableByWhere(dtResult, strWhere.ToString());
                    }
                    //CommonUtils.Log("查询条件strWhere={0},查询结果{1}", strWhere.ToString(), dtQuery.Rows.Count.ToString());
                }
            }
            catch (Exception ex)
            {
                CommonUtils.Log("数据过滤异常-FilterDataByOrder:{0},查询条件strWhere={1}", ex.StackTrace, strWhere.ToString());
            }

            return(lstQuery);
        }