コード例 #1
0
ファイル: TDFMain.cs プロジェクト: fffweb/MoneyFramework
        //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;
                }
            }
        }
コード例 #2
0
ファイル: TDFMain.cs プロジェクト: botvs/MoneyFramework
        //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;
                }
            }

        }
コード例 #3
0
        public int Start()
        {
            if (_isRunning == true)
            {
                App.Logger.Info("TDF数据服务:已启动!");
                return(1);
            }

            try
            {
                TDFServerInfo[] theServers = new TDFServerInfo[4];

                theServers[0] = new TDFServerInfo()
                {
                    Ip       = _config.Ip,                              //服务器Ip
                    Port     = _config.Port.ToString(),                 //服务器端口
                    Username = _config.Username,                        //服务器用户名
                    Password = _config.Password,                        //服务器密码
                };
                //theServers[0].Username = "******";
                //theServers[0].Password = "******";
                //Setting.IsHistory = true;
                theServers[1] = new TDFServerInfo();
                if (_config.Ip == "114.80.154.34")
                {
                    bool isSpec = false;
                    if (_config.Port == 6221)
                    {
                        isSpec             = true;
                        theServers[1].Port = "6231";
                    }
                    else if (_config.Port == 6231)
                    {
                        isSpec             = true;
                        theServers[1].Port = "6221";
                    }
                    if (isSpec)
                    {
                        theServers[1].Ip       = _config.Ip;
                        theServers[1].Username = _config.Username;
                        theServers[1].Password = _config.Password;
                    }
                }

                theServers[2] = new TDFServerInfo();
                theServers[3] = new TDFServerInfo();

                TDFOpenSetting_EXT openSetting = new TDFOpenSetting_EXT()
                {
                    Servers       = theServers,
                    ServerNum     = 1,
                    Subscriptions = "600000.sh;000001.sz",                                                                                                    //订阅列表,以 ; 分割的代码列表,例如:if1406.cf;if1403.cf;如果置为空,则全市场订阅
                    Markets       = "sh-2;sz-2;",                                                                                                             //市场列表,以 ; 分割,例如: sh;sz;cf;shf;czc;dce
                    ConnectionID  = 1,                                                                                                                        //连接ID,标识某个Open调用,跟回调消息中TDFMSG结构nConnectionID字段相同
                    Time          = Setting.IsHistory ? -1 : 0,                                                                                               //请求的时间,格式HHMMSS,为0则请求实时行情,为(uint)-1从头请求
                    TypeFlags     = unchecked ((uint)(DataTypeFlag.DATA_TYPE_ORDER | DataTypeFlag.DATA_TYPE_TRANSACTION | DataTypeFlag.DATA_TYPE_ORDERQUEUE)) //为0请求所有品种,或者取值为DataTypeFlag中多种类别,比如DATA_TYPE_MARKET | DATA_TYPE_TRANSACTION
                };

                if (IsAllCodes)
                {
                    openSetting.Subscriptions = string.Empty;
                    openSetting.Markets       = "SH-2;SZ-2";
                }
                _source = new TDFSourceImp(openSetting);

                _source.NewSysEvent += _source_NewSysEvent;
                TDFERRNO nOpenRet = _source.Open();
                if (nOpenRet == TDFERRNO.TDF_ERR_SUCCESS)
                {
                    App.Logger.Info("TDF数据服务:登陆成功!");
                    _isRunning = true;
                    if (_subCodes.Count > 0)
                    {
                        //重新注册
                        StringBuilder s = new StringBuilder();
                        foreach (string wind in _subCodes)
                        {
                            s.Append(wind);
                            s.Append(";");
                        }
                        string substring = s.ToString().TrimEnd(new char[] { ';' });
                        _source.SetSubscription(substring, SubscriptionType.SUBSCRIPTION_ADD);
                    }
                }
                else
                {
                    App.Logger.Error(string.Format("TDF数据服务:连接失败,错误代码{0}", nOpenRet));
                    return(2);
                }
            }
            catch (Exception ex)
            {
                App.Logger.Error(ex);
                App.Logger.Error("TDF数据服务:初始化错误!" + ex.Message);
                return(100);
            }

            return(0);
        }