Example #1
0
        private void threadproc()
        {
            while (true)
            {

                Thread.Sleep(1);

                if ((DateTime.Now - GlobalHeartBeat.GetGlobalTime()).TotalMinutes > 5)
                {
                    log.LogEvent("由于供血不足,委托查询线程即将退出。");
                    break;
                }

                //单次循环最多查询100个交易的委托情况
                int maxCount = 100;

                if (!_classTradeStock.getConnectStatus())
                {
                    _classTradeStock.Init(login, ErrorMsg);
                }

                if (lastmessagetime.Second != DateTime.Now.Second)
                {
                    KeyValuePair<string, object> message1 = new KeyValuePair<string, object>("THREAD_ENTRUST_WORKER", (object)(DateTime.Now));
                    queue_system_status.GetQueue().Enqueue((object)message1);
                    lastmessagetime = DateTime.Now;
                }


                while (maxCount > 0 && queue_query_entrust.GetQueueNumber() > 0)
                {
                    maxCount--;

                    //获取新委托
                    QueryEntrustOrderStruct_M item = (QueryEntrustOrderStruct_M)queue_query_entrust.GetQueue().Dequeue();
                    string err = string.Empty;

                    //查询委托及获取实例
                    managedEntrustreturnstruct ret = new managedEntrustreturnstruct();

                    //ordersysid 首字母 为 'T'  是测试交易
                     if (item.OrderSysID.Length > 0 && item.OrderSysID[0] == 'T')
                     {
                         var temps = test.QueryEntrust(item);
                         ret = temps;
                     }
                     else
                     {
                         var temps = _classTradeStock.QueryEntrust(item, err);
                         if (temps.Length == 0) continue;

                         ret = temps.ToList()[0];
                     }

                    
                   

                    if (ret == null) continue;

                    String USERNAME = UserRequestMap.GetInstance()[item.OrderRef];

                    if (ret == null) continue;


                    OrderViewItem order = new OrderViewItem(
                        item.OrderRef.ToString(),
                        ret.cOrderSysID,
                        ret.cSecurity_code,
                        item.Direction.ToString(),
                        "NA",
                        ret.nVolumeTotalOriginal.ToString(),
                        ret.nVolumeTotal.ToString(),
                        item.OrderPrice.ToString(),
                        GetStatusWord(ret.cOrderStatus),
                        ret.cInsertTime);

                    String JSONString = JsonConvert.SerializeObject(order);
                    TradeMonitor.Instance.updateOrderList(USERNAME, JSONString);


                    //目前仅考虑 1对1 返回的情况,不考虑出现1对多 ,类似基金交易的情况
                    //将委托变动返回更新数据库
                    if (DBAccessLayer.DBEnable == true)
                    {
                        //更新数据,记录入数据库
                        ThreadPool.QueueUserWorkItem(new WaitCallback(DBAccessLayer.UpdateERRecord), (object)(ret));

                        //此处判断,相应代码的委托是否完成
                        //此处逻辑需要待返回报文内容确认后修改
                        //测试使用
                        if ((ret.cOrderStatus.ToString() != ((int)(EntrustStatus.Dealed)).ToString()) && (!(ret.cOrderStatus.ToString() == ((int)EntrustStatus.Canceled).ToString() && ret.nVolumeTotal == 0)))
                        {
                            queue_query_entrust.GetQueue().Enqueue((object)item);
                            continue;
                        }


                        //委托已经完成,进入成交状态查询
                        managedBargainreturnstruct bargin = new managedBargainreturnstruct();
                        if (item.OrderSysID.Length > 0 && item.OrderSysID[0] == 'T')
                        {
                            bargin = test.QueryTrader(item);

                        }
                        else
                        {
                            var retbargin = _classTradeStock.QueryTrader(item, err).ToList();
                            //将查询信息记录成交表
                            if (retbargin.Count > 0)
                            {
                                bargin = retbargin.ToList()[0];
                            }
                        }

                        bargin.strategyId = item.StrategyId;
                        bargin.direction = item.Direction;

                        ThreadPool.QueueUserWorkItem(new WaitCallback(DBAccessLayer.CreateDLRecord), (object)bargin);

                        //更新持仓列表
                        //ThreadPool.QueueUserWorkItem(new WaitCallback(DBAccessLayer.UpdateCCRecords), (object)bargin);

                    }
                }

            }
        }
Example #2
0
        public managedBargainreturnstruct QueryTrader(QueryEntrustOrderStruct_M queryEntrust)
        {
            managedBargainreturnstruct bargain = new managedBargainreturnstruct();

            bargain.bargain_money = 0;
            bargain.bargain_price = 0;
            bargain.bargain_time = DateTime.Now.Hour.ToString() + DateTime.Now.Minute + DateTime.Now.Second;
            bargain.bargain_no = queryEntrust.OrderRef;
            bargain.direction = queryEntrust.Direction;
            bargain.OrderStatus = Convert.ToSByte(EntrustStatus.Dealed);
            bargain.OrderSysID = queryEntrust.OrderSysID;
            bargain.OrderType = queryEntrust.SecurityType;
            bargain.Security_code = queryEntrust.Code;
            bargain.Security_name = "TEST CODE";
            bargain.stock_amount = 0;
            bargain.strategyId = queryEntrust.StrategyId;

            return bargain;
        }