示例#1
0
        private void btnStart_Click(object sender, EventArgs e)
        {
            ChinaMarketValue.isStartMarket = true;
            if (ChinaMarketValue.threadMarket == null)
            {
                ChinaMarketValue.threadMarket = new Thread(UpdateMarkets);
                ChinaMarketValue.threadMarket.IsBackground = true;
                ChinaMarketValue.threadMarket.Start();
            }


            if (openSettins == null)
            {
                openSettins = new TDFOpenSetting()
                {
                    Ip             = System.Configuration.ConfigurationManager.AppSettings["IP"],                         //服务器Ip
                    Port           = System.Configuration.ConfigurationManager.AppSettings["Port"],                       //服务器端口
                    Username       = System.Configuration.ConfigurationManager.AppSettings["Username"],                   //服务器用户名
                    Password       = System.Configuration.ConfigurationManager.AppSettings["Password"],                   //服务器密码
                    Subscriptions  = System.Configuration.ConfigurationManager.AppSettings["SubScriptions"],              //订阅列表,以 ; 分割的代码列表,例如:if1406.cf;if1403.cf;如果置为空,则全市场订阅
                    Markets        = System.Configuration.ConfigurationManager.AppSettings["Markets"],                    //市场列表,以 ; 分割,例如: sh;sz;cf;shf;czc;dce
                    ReconnectCount = uint.Parse(System.Configuration.ConfigurationManager.AppSettings["ReconnectCount"]), //当连接断开时重连次数,断开重连在TDFDataSource.Connect成功之后才有效
                    ReconnectGap   = uint.Parse(System.Configuration.ConfigurationManager.AppSettings["ReconnectGap"]),   //重连间隔秒数
                    ConnectionID   = uint.Parse(System.Configuration.ConfigurationManager.AppSettings["ConnectionID"]),   //连接ID,标识某个Open调用,跟回调消息中TDFMSG结构nConnectionID字段相同
                    Date           = uint.Parse(System.Configuration.ConfigurationManager.AppSettings["Date"]),           //请求的日期,格式YYMMDD,为0则请求今天
                    Time           = (uint)int.Parse(System.Configuration.ConfigurationManager.AppSettings["Time"]),      //请求的时间,格式HHMMSS,为0则请求实时行情,为(uint)-1从头请求
                    TypeFlags      = (uint)int.Parse(System.Configuration.ConfigurationManager.AppSettings["TypeFlags"])  //unchecked((uint)DataTypeFlag.DATA_TYPE_ALL);   //为0请求所有品种,或者取值为DataTypeFlag中多种类别,比如DATA_TYPE_MARKET | DATA_TYPE_TRANSACTION
                };
            }


            if (dataSource == null)
            {
                dataSource = new TDFSourceImp(openSettins);
                dataSource.SetEnv(EnvironSetting.TDF_ENVIRON_OUT_LOG, 1);
                TDFERRNO nOpenRet = dataSource.Open();
                if (nOpenRet == TDFERRNO.TDF_ERR_SUCCESS)
                {
                    PrintHelper.PrintText("connect success!\n");
                }
                else
                {
                    //这里判断错误代码,进行对应的操作,对于 TDF_ERR_NETWORK_ERROR,用户可以选择重连
                    PrintHelper.PrintText(string.Format("open returned:{0}, program quit", nOpenRet));
                }
            }

            btnStart.Enabled = false;
            btnClose.Enabled = true;
        }
示例#2
0
        private void btnClose_Click(object sender, EventArgs e)
        {
            ChinaMarketValue.isStartMarket = false;
            if (dataSource != null)
            {
                dataSource.Close();
                dataSource.Dispose();
                dataSource = null;
            }
            try
            {
                if (ChinaMarketValue.threadMarket != null)
                {
                    ChinaMarketValue.threadMarket.Abort();
                    ChinaMarketValue.threadMarket = null;
                }
            }
            catch { }


            btnStart.Enabled = true;
            btnClose.Enabled = false;
        }