Example #1
0
        public MarketData DeQueueInfo()
        {
            lock (Queue_Data.GetQueue().SyncRoot)
            {
                if (Queue_Data.GetQueue().Count > 0)
                {
                    EnQueueType OBJ = (EnQueueType)Queue_Data.GetQueue().Dequeue();

                    if (OBJ == null)
                    {
                        return(null);
                    }

                    if (OBJ.Type == "S")
                    {
                        return(new MarketData((TDFMarketData)(OBJ.value)));
                    }
                    else if (OBJ.Type == "I")
                    {
                        return(new MarketData((TDFIndexData)(OBJ.value)));
                    }
                    else if (OBJ.Type == "F")
                    {
                        return(new MarketData((TDFFutureData)(OBJ.value)));
                    }
                    else
                    {
                        return(null);
                    }
                }
                else
                {
                    return(null);
                }
            }
        }
Example #2
0
        //delegate String ToString(String[] args);
        /// <summary>
        /// 行情订阅主线程
        /// </summary>
        static void MainThread()
        {
            TDFServerInfo[] theServers = new TDFServerInfo[4];
            uint iServerNum = 1;

            theServers[0] = new TDFServerInfo()
            {
                //Ip = CHangQingPARA.IP,
                //Port = CHangQingPARA.PORT,
                //Username = CHangQingPARA.USERNAME,
                //Password = CHangQingPARA.PASSWORD

                //Ip = "114.80.154.34",
                //Port = "6231",                              //服务器端口
                //Username = "******",                        //服务器用户名
                //Password = "******"

                Ip = ip,
                Port = port,
                Username = userName,
                Password=password
            };

            /******即使不用,也要初始化******/
            theServers[1] = new TDFServerInfo();
            theServers[2] = new TDFServerInfo();
            theServers[3] = new TDFServerInfo();


            //初始化行情模拟系统
            simulate_trade.InitSimTable(simulate_trade.SimMarketCode);

            /************订阅的类型需要再确认***********/
            var openSetting_ext = new TDFOpenSetting_EXT()
            {
                Servers = theServers,
                ServerNum = iServerNum,
                Markets = "",
                Subscriptions = subscribeList.Replace('\n', ';'),
                ConnectionID = 1,
                Time =0,
                TypeFlags = 0
            };

            using (var dataSource = new TDFSourceImp(openSetting_ext))
            {
                dataSource.SetEnv(EnvironSetting.TDF_ENVIRON_HEART_BEAT_INTERVAL, 0);//环境设置
                dataSource.SetEnv(EnvironSetting.TDF_ENVIRON_MISSED_BEART_COUNT, 0);//环境设置
                dataSource.SetEnv(EnvironSetting.TDF_ENVIRON_OPEN_TIME_OUT, 0);//环境设置

                TDFERRNO nOpenRet = dataSource.Open();

                if (nOpenRet == TDFERRNO.TDF_ERR_SUCCESS)
                {
                    //连接成功
                    Queue_Data.Connected = true;
                }
                else
                {
                    Queue_Data.Connected = false;
                    //连接失败,告警顶级日志
                    //GlobalErrorLog.LogInstance.LogEvent(String.Format("open returned:{0}, program quit", nOpenRet));
                }

                

                while (true)
                {
                    if (webservice.STOP) { break; }
                    Thread.Sleep(1000);

                    //每隔10s发送一次停盘信息
                    if ((DateTime.Now - RunningTime.CurrentTime).TotalSeconds > 10)
                    {
                        foreach (TDFMarketData data in stop_plate_stocks.GetInstance().GetStopList())
                        {
                            EnQueueType obj = new EnQueueType() { Type = "S", value = (object)data };
                            Queue_Data.GetQueue().Enqueue((object)obj);
                        }
                        RunningTime.CurrentTime = DateTime.Now;

                    }

                    if ((simulate_trade.SimSwitch)&&(Queue_Data.Suspend == false))
                    {
                        for (int i = 0; i < simulate_trade.SimMarketPerSecond; i++)
                        {
                            TDFMarketData objs = simulate_trade.GetSimMarketDate();
                            new EnQueueType() { Type = "S", value = (object)objs };
                            if (Queue_Data.Suspend == false)
                            {
                                Queue_Data.GetQueue().Enqueue((object)(new EnQueueType() { Type = "S", value = (object)objs }));
                            }

                            TDFFutureData objf = simulate_trade.GetSimFutureData();
                            Queue_Data.GetQueue().Enqueue((object)(new EnQueueType() { Type = "F", value = (object)objf }));

                        }
                    }
                    continue;
                }
            }

        }
Example #3
0
        //delegate String ToString(String[] args);
        /// <summary>
        /// 行情订阅主线程
        /// </summary>
        static void MainThread()
        {
            TDFServerInfo[] theServers = new TDFServerInfo[4];
            uint            iServerNum = 1;

            theServers[0] = new TDFServerInfo()
            {
                //Ip = CHangQingPARA.IP,
                //Port = CHangQingPARA.PORT,
                //Username = CHangQingPARA.USERNAME,
                //Password = CHangQingPARA.PASSWORD

                //Ip = "114.80.154.34",
                //Port = "6231",                              //服务器端口
                //Username = "******",                        //服务器用户名
                //Password = "******"

                Ip       = ip,
                Port     = port,
                Username = userName,
                Password = password
            };

            /******即使不用,也要初始化******/
            theServers[1] = new TDFServerInfo();
            theServers[2] = new TDFServerInfo();
            theServers[3] = new TDFServerInfo();


            //初始化行情模拟系统
            simulate_trade.InitSimTable(simulate_trade.SimMarketCode);

            /************订阅的类型需要再确认***********/
            var openSetting_ext = new TDFOpenSetting_EXT()
            {
                Servers       = theServers,
                ServerNum     = iServerNum,
                Markets       = "",
                Subscriptions = subscribeList.Replace('\n', ';'),
                ConnectionID  = 1,
                Time          = 0,
                TypeFlags     = 0
            };

            using (var dataSource = new TDFSourceImp(openSetting_ext))
            {
                dataSource.SetEnv(EnvironSetting.TDF_ENVIRON_HEART_BEAT_INTERVAL, 0); //环境设置
                dataSource.SetEnv(EnvironSetting.TDF_ENVIRON_MISSED_BEART_COUNT, 0);  //环境设置
                dataSource.SetEnv(EnvironSetting.TDF_ENVIRON_OPEN_TIME_OUT, 0);       //环境设置

                TDFERRNO nOpenRet = dataSource.Open();

                if (nOpenRet == TDFERRNO.TDF_ERR_SUCCESS)
                {
                    //连接成功
                    Queue_Data.Connected = true;
                }
                else
                {
                    Queue_Data.Connected = false;

                    MessageBox.Show(nOpenRet.ToString());
                    //连接失败,告警顶级日志
                    //GlobalErrorLog.LogInstance.LogEvent(String.Format("open returned:{0}, program quit", nOpenRet));
                }



                while (true)
                {
                    if (webservice.STOP)
                    {
                        break;
                    }
                    Thread.Sleep(1000);

                    //每隔10s发送一次停盘信息
                    if ((DateTime.Now - RunningTime.CurrentTime).TotalSeconds > 10)
                    {
                        foreach (TDFMarketData data in stop_plate_stocks.GetInstance().GetStopList())
                        {
                            EnQueueType obj = new EnQueueType()
                            {
                                Type = "S", value = (object)data
                            };



                            if (simulate_trade.MarketRecorder)
                            {
                                MarketInfoQueue.EnQueueNew(data);
                            }
                            else
                            {
                                Queue_Data.GetQueue().Enqueue((object)obj);
                            }
                        }
                        RunningTime.CurrentTime = DateTime.Now;
                    }



                    if ((simulate_trade.SimSwitch) && (Queue_Data.Suspend == false))
                    {
                        for (int i = 0; i < simulate_trade.SimMarketPerSecond; i++)
                        {
                            TDFMarketData objs = simulate_trade.GetSimMarketDate();
                            new EnQueueType()
                            {
                                Type = "S", value = (object)objs
                            };
                            if (Queue_Data.Suspend == false)
                            {
                                Queue_Data.GetQueue().Enqueue((object)(new EnQueueType()
                                {
                                    Type = "S", value = (object)objs
                                }));
                            }

                            TDFFutureData objf = simulate_trade.GetSimFutureData();
                            Queue_Data.GetQueue().Enqueue((object)(new EnQueueType()
                            {
                                Type = "F", value = (object)objf
                            }));
                        }
                    }
                    continue;
                }
            }
        }
Example #4
0
        //重载OnRecvDataMsg方法,接收行情数据
        // 请注意:
        //  1. 不要在这个函数里做耗时操作
        //  2. 只在这个函数里做数据获取工作 -- 将数据复制到其它数据缓存区,由其它线程做业务逻辑处理
        public override void OnRecvDataMsg(TDFMSG msg)
        {
            if (msg.MsgID == TDFMSGID.MSG_DATA_MARKET)
            {
                //行情消息
                TDFMarketData[] marketDataArr = msg.Data as TDFMarketData[];

                foreach (TDFMarketData data in marketDataArr)
                {
                    EnQueueType obj = new EnQueueType() { Type = "S", value = (object)data };
                    if (Queue_Data.Suspend == false)
                    {
                        Queue_Data.GetQueue().Enqueue((object)obj);
                        if (data.Status == 68)
                        {
                            stop_plate_stocks.GetInstance().updateStopList(data);
                        }
                    }
                }
            }
            else if (msg.MsgID == TDFMSGID.MSG_DATA_FUTURE)
            {
                //期货行情数据
                TDFFutureData[] futureDataArr = msg.Data as TDFFutureData[];

                foreach (TDFFutureData data in futureDataArr)
                {
                    EnQueueType obj = new EnQueueType() { Type = "F", value = (object)data };
                    if (Queue_Data.Suspend == false)
                    {
                        Queue_Data.GetQueue().Enqueue((object)obj);
                    }
                }

            }
            else if (msg.MsgID == TDFMSGID.MSG_DATA_INDEX)
            {
                //指数消息
                TDFIndexData[] indexDataArr = msg.Data as TDFIndexData[];

                foreach (TDFIndexData data in indexDataArr)
                {
                    EnQueueType obj = new EnQueueType() { Type = "I", value = (object)data };
                    if (Queue_Data.Suspend == false)
                    {
                        Queue_Data.GetQueue().Enqueue((object)obj);
                    }
                }
            }
        }
Example #5
0
        //重载OnRecvDataMsg方法,接收行情数据
        // 请注意:
        //  1. 不要在这个函数里做耗时操作
        //  2. 只在这个函数里做数据获取工作 -- 将数据复制到其它数据缓存区,由其它线程做业务逻辑处理
        public override void OnRecvDataMsg(TDFMSG msg)
        {
            if (Queue_Data.GetQueueNumber() > 2000)
            {
                Queue_Data.GetQueue().Clear();
                GlobalMarketLog.LogInstance.LogEvent("Queue_Data超量自动删除,时间:" + DateTime.Now.ToString());
            }

            if (MarketInfoQueue.GetQueueLength() > 2000)
            {
                MarketInfoQueue.ClearQueue();
                GlobalMarketLog.LogInstance.LogEvent("MarketInfoQueue超量自动删除,时间:" + DateTime.Now.ToString());
            }

            if (msg.MsgID == TDFMSGID.MSG_DATA_MARKET)
            {
                //行情消息
                TDFMarketData[] marketDataArr = msg.Data as TDFMarketData[];

                foreach (TDFMarketData data in marketDataArr)
                {
                    EnQueueType obj = new EnQueueType()
                    {
                        Type = "S", value = (object)data
                    };
                    if (Queue_Data.Suspend == false)
                    {
                        if (!simulate_trade.MarketRecorder)
                        {
                            Queue_Data.GetQueue().Enqueue((object)obj);
                        }
                        if (data.Status == 68)
                        {
                            stop_plate_stocks.GetInstance().updateStopList(data);
                        }

                        if (simulate_trade.MarketRecorder)
                        {
                            MarketInfoQueue.EnQueueNew(data);
                        }
                    }
                }
            }
            else if (msg.MsgID == TDFMSGID.MSG_DATA_FUTURE)
            {
                //期货行情数据
                TDFFutureData[] futureDataArr = msg.Data as TDFFutureData[];

                foreach (TDFFutureData data in futureDataArr)
                {
                    EnQueueType obj = new EnQueueType()
                    {
                        Type = "F", value = (object)data
                    };
                    if (Queue_Data.Suspend == false)
                    {
                        Queue_Data.GetQueue().Enqueue((object)obj);
                    }
                }
            }
            else if (msg.MsgID == TDFMSGID.MSG_DATA_INDEX)
            {
                //指数消息
                TDFIndexData[] indexDataArr = msg.Data as TDFIndexData[];

                foreach (TDFIndexData data in indexDataArr)
                {
                    EnQueueType obj = new EnQueueType()
                    {
                        Type = "I", value = (object)data
                    };
                    if (Queue_Data.Suspend == false)
                    {
                        Queue_Data.GetQueue().Enqueue((object)obj);
                    }
                }
            }
        }