//重载 OnRecvSysMsg 方法,接收系统消息通知 // 请注意: // 1. 不要在这个函数里做耗时操作 // 2. 只在这个函数里做数据获取工作 -- 将数据复制到其它数据缓存区,由其它线程做业务逻辑处理 public override void OnRecvSysMsg(TDFMSG msg) { if (msg.MsgID == TDFMSGID.MSG_SYS_CONNECT_RESULT) { //连接结果 TDFConnectResult connectResult = msg.Data as TDFConnectResult; ConnectResult = connectResult; IsOnline = connectResult.ConnResult; if (NewSysEvent != null) { NewSysEvent("连接状态 " + (IsOnline ? "已连接" : "未连接")); } App.Logger.Info("TDF:连接状态 " + (IsOnline ? "已连接" : "未连接")); } else if (msg.MsgID == TDFMSGID.MSG_SYS_LOGIN_RESULT) { TDFLoginResult loginResult = msg.Data as TDFLoginResult; LoginResult = loginResult; IsLogin = loginResult.LoginResult; if (NewSysEvent != null) { NewSysEvent("登陆状态 " + (IsLogin ? "已登陆" : "未登陆")); } App.Logger.Info("TDF:登陆状态 " + (IsLogin ? "已登陆" : "未登陆")); } else if (msg.MsgID == TDFMSGID.MSG_SYS_CODETABLE_RESULT) { //接收代码表结果 TDFCodeResult codeResult = msg.Data as TDFCodeResult; //客户端请自行保存代码表,本处演示怎么获取代码表内容 if (codeResult != null) { TDFCode[] sh_codes; TDFCode[] sz_codes; GetCodeTable("SH", out sh_codes); GetCodeTable("SZ", out sz_codes); _codes = new TDFCode[sh_codes.Length + sz_codes.Length]; sh_codes.CopyTo(_codes, 0); sz_codes.CopyTo(_codes, sh_codes.Length); if (NewSysEvent != null) { NewSysEvent("已获取代码列表," + _codes.Length); } } else { if (NewSysEvent != null) { NewSysEvent("获取代码列表失败"); } } App.Logger.Info("TDF:获取代码列表消息"); } else if (msg.MsgID == TDFMSGID.MSG_SYS_QUOTATIONDATE_CHANGE) { //行情日期变更。 TDFQuotationDateChange quotationChange = msg.Data as TDFQuotationDateChange; if (NewSysEvent != null) { NewSysEvent("行情日期变更"); } App.Logger.Info("TDF:行情日期变更"); } else if (msg.MsgID == TDFMSGID.MSG_SYS_MARKET_CLOSE) { //闭市消息 TDFMarketClose marketClose = msg.Data as TDFMarketClose; IsClose = true; if (NewSysEvent != null) { NewSysEvent("闭市状态 " + (IsClose ? "闭市" : "未闭市")); } App.Logger.Info("TDF:闭市状态 " + (IsClose ? "闭市" : "未闭市")); } else if (msg.MsgID == TDFMSGID.MSG_SYS_HEART_BEAT) { //心跳消息 AliveTime = DateTime.Now; } }
//重载 OnRecvSysMsg 方法,接收系统消息通知 // 请注意: // 1. 不要在这个函数里做耗时操作 // 2. 只在这个函数里做数据获取工作 -- 将数据复制到其它数据缓存区,由其它线程做业务逻辑处理 public override void OnRecvSysMsg(TDFMSG msg) { try { if (msg.MsgID == TDFMSGID.MSG_SYS_CONNECT_RESULT) { //连接结果 TDFConnectResult connectResult = msg.Data as TDFConnectResult; string strPrefix = connectResult.ConnResult ? "连接成功" : "连接失败"; PrintHelper.PrintText(String.Format("{0}!server:{1}:{2},{3},{4}, connect id:{5}", strPrefix, connectResult.Ip, connectResult.Port, connectResult.Username, connectResult.Password, connectResult.ConnectID)); } else if (msg.MsgID == TDFMSGID.MSG_SYS_LOGIN_RESULT) { TDFLoginResult loginResult = msg.Data as TDFLoginResult; if (loginResult.LoginResult) { //登陆结果 PrintHelper.PrintText(String.Format("登陆成功,市场个数:{0}:", loginResult.Markets.Length)); for (int i = 0; i < loginResult.Markets.Length; i++) { PrintHelper.PrintText(String.Format("market:{0}, dyn-date:{1}", loginResult.Markets[i], loginResult.DynDate[i])); } } else { PrintHelper.PrintText(String.Format("登陆失败!info:{0}", loginResult.Info)); } } else if (msg.MsgID == TDFMSGID.MSG_SYS_CODETABLE_RESULT) { //接收代码表结果 TDFCodeResult codeResult = msg.Data as TDFCodeResult; PrintHelper.PrintText(String.Format("获取到代码表, info:{0},市场个数:{1}", codeResult.Info, codeResult.Markets.Length)); for (int i = 0; i < codeResult.Markets.Length; i++) { PrintHelper.PrintText(String.Format("market:{0}, date:{1}, code count:{2}", codeResult.Markets[i], codeResult.CodeDate[i], codeResult.CodeCount[i])); } //客户端请自行保存代码表,本处演示怎么获取代码表内容 TDFCode[] codeArr; GetCodeTable("", out codeArr); //Console.WriteLine("接收到{0}项代码!, 输出前100项", codeArr.Length); ChinaMarketValue.dicTDFCode.Clear(); for (int i = 0; i < codeArr.Length; i++) { ChinaMarketValue.dicTDFCode.TryAdd(codeArr[i].WindCode, codeArr[i]); } } else if (msg.MsgID == TDFMSGID.MSG_SYS_QUOTATIONDATE_CHANGE) { //行情日期变更。 TDFQuotationDateChange quotationChange = msg.Data as TDFQuotationDateChange; PrintHelper.PrintText(String.Format("接收到行情日期变更通知消息,market:{0}, old date:{1}, new date:{2}", quotationChange.Market, quotationChange.OldDate, quotationChange.NewDate)); } else if (msg.MsgID == TDFMSGID.MSG_SYS_MARKET_CLOSE) { //闭市消息 TDFMarketClose marketClose = msg.Data as TDFMarketClose; PrintHelper.PrintText(String.Format("接收到闭市消息, 交易所:{0}, 时间:{1}, 信息:{2}", marketClose.Market, marketClose.Time, marketClose.Info)); } else if (msg.MsgID == TDFMSGID.MSG_SYS_HEART_BEAT) { //心跳消息 //Console.WriteLine("接收到心跳消息!"); } } catch (Exception ex) { ChinaMarketValue.exceptionLog.log(ChinaMarketValue.logLevel, ex.ToString()); } }
//重载 OnRecvSysMsg 方法,接收系统消息通知 // 请注意: // 1. 不要在这个函数里做耗时操作 // 2. 只在这个函数里做数据获取工作 -- 将数据复制到其它数据缓存区,由其它线程做业务逻辑处理 public override void OnRecvSysMsg(TDFMSG msg) { if (msg.MsgID == TDFMSGID.MSG_SYS_CONNECT_RESULT) { //连接结果 TDFConnectResult connectResult = msg.Data as TDFConnectResult; string strPrefix = connectResult.ConnResult ? "连接成功" : "连接失败"; ;//Console.WriteLine("{0}!server:{1}:{2},{3},{4}, connect id:{5}", strPrefix, connectResult.Ip, connectResult.Port, connectResult.Username, connectResult.Password, connectResult.ConnectID); } else if (msg.MsgID == TDFMSGID.MSG_SYS_LOGIN_RESULT) { TDFLoginResult loginResult = msg.Data as TDFLoginResult; if (loginResult.LoginResult) { //登陆结果 ;//Console.WriteLine("登陆成功,市场个数:{0}:", loginResult.Markets.Length); for (int i = 0; i < loginResult.Markets.Length; i++) { ;//Console.WriteLine("market:{0}, dyn-date:{1}", loginResult.Markets[i], loginResult.DynDate[i]); } } else { ;//Console.WriteLine("登陆失败!info:{0}", loginResult.Info); } } else if (msg.MsgID == TDFMSGID.MSG_SYS_CODETABLE_RESULT) { //接收代码表结果 TDFCodeResult codeResult = msg.Data as TDFCodeResult; ;//Console.WriteLine("获取到代码表, info:{0},市场个数:{1}", codeResult.Info, codeResult.Markets.Length); for (int i = 0; i < codeResult.Markets.Length; i++) { ;//Console.WriteLine("market:{0}, date:{1}, code count:{2}", codeResult.Markets[i], codeResult.CodeDate[i], codeResult.CodeCount[i]); } //客户端请自行保存代码表,本处演示怎么获取代码表内容 TDFCode[] codeArr; GetCodeTable("", out codeArr); ;//Console.WriteLine("接收到{0}项代码!, 输出前100项", codeArr.Length); for (int i = 0; i < 100 && i < codeArr.Length; i++) { if (codeArr[i].Type >= 0x90 && codeArr[i].Type <= 0x95) { // 期权数据 TDFOptionCode code = new TDFOptionCode(); var ret = GetOptionCodeInfo(codeArr[i].WindCode, ref code); ;//PrintHelper.PrintObject(code); } else { ;//PrintHelper.PrintObject(codeArr[i]); } } } else if (msg.MsgID == TDFMSGID.MSG_SYS_QUOTATIONDATE_CHANGE) { //行情日期变更。 TDFQuotationDateChange quotationChange = msg.Data as TDFQuotationDateChange; ;//Console.WriteLine("接收到行情日期变更通知消息,market:{0}, old date:{1}, new date:{2}", quotationChange.Market, quotationChange.OldDate, quotationChange.NewDate); } else if (msg.MsgID == TDFMSGID.MSG_SYS_MARKET_CLOSE) { //闭市消息 TDFMarketClose marketClose = msg.Data as TDFMarketClose; ;//Console.WriteLine("接收到闭市消息, 交易所:{0}, 时间:{1}, 信息:{2}", marketClose.Market, marketClose.Time, marketClose.Info); if (!(marketClose.Market == "CF")) { EvMarketClose(this, null); } } else if (msg.MsgID == TDFMSGID.MSG_SYS_HEART_BEAT) { //心跳消息 ;//Console.WriteLine("接收到心跳消息!"); } }
/// <summary> /// TDFConnectResult /// public int ConnectID; //连接ID /// public bool ConnResult; //为0则表示连接失败,非0则表示连接成功 /// public string Ip; //连接TDFServer主机IP /// public string Password; //登录密码 /// public string Port; //连接TDFServer主机的端口 /// public string Username; //登录用户名 /// TDFLoginResult /// public int[] DynDate; //动态数据日期 /// public string Info; //登录结果文本 /// public bool LoginResult; //true表示登录验证成功,false表示登录验证失败 /// public string[] Markets; //市场代码 SZ, SH, CF, SHF, CZC, DCE /// /// TDFCodeResult /// public int[] CodeCount; //代码表项数 /// public int[] CodeDate; //代码表日期 /// public string Info; //代码表文本结果 /// public string[] Markets;//市场代码 SZ, SH, CF, SHF, CZC, DCE /// --调用GetCodeTable只能获得调用该函数为止的最新代码表,在运行程序中,当在回调函数中接收到新代码时,客户端可以再次调用GetCodeTable获得该新代码信息 /// /// TDFQuotationDateChange /// public string Market; //市场代码 /// public int NewDate; //新行情日期 /// public int OldDate; //原行情日期 /// /// TDFMarketClose /// public string Info; //闭市信息 /// public string Market; //交易所名称 /// public int Time; //时间(HHMMSSmmm) /// /// TDFCode /// public string CNName; //代码中文名称,如:沪银1302 /// public string Code; //原始代码,如:AG1302 /// public string ENName; //代码英文名称 /// public string Market; //交易所名称 /// public string WindCode; //万得代码,如:AG1302.SHF /// public int Type; //证券类型,详细类型 Type位与 0xFF /// //0x00 指数 /// //0x10 股票 (0x10 A股, 0x11中小板股,0x12创业板股) /// //0x20 基金 /// //0x30 债券&可转债 /// //0x40 回购 /// //0x60 权证 /// //0x70 期货(0x70指数期货,0x71商品期货,0x72股票期货) /// //0x80 外汇 /// //0xd0 银行利率 /// //0xe0 贵金属 /// //0xf0 其他 /// </summary> /// <param name="msg"></param> private void OnRecvSysMsg(TDFMSG msg) { switch (msg.MsgID) { case TDFMSGID.MSG_SYS_CONNECT_RESULT: { //连接结果 TDFConnectResult connectResult = msg.Data as TDFConnectResult; if (!connectResult.ConnResult) { string strMsg = string.Format("宏汇行情连接服务器失败: IP:{0} Port:{1} User:{2} Password:{3}", connectResult.Ip, connectResult.Port, connectResult.Username, connectResult.Password); logger.Error(strMsg); //TODO: notify the user to handle the connect failure Stop(); } else { string strMsg = "宏汇行情连接服务器成功!"; logger.Info(strMsg); } } break; case TDFMSGID.MSG_SYS_LOGIN_RESULT: { //登陆结果 TDFLoginResult loginResult = msg.Data as TDFLoginResult; if (!loginResult.LoginResult) { string strMsg = string.Format("宏汇行情登录失败: {0}", loginResult.Info); logger.Error(strMsg); //TODO: notify the user to handle the login failure Stop(); } else { string strMsg = "宏汇行情登录成功"; logger.Info(strMsg); } } break; case TDFMSGID.MSG_SYS_CODETABLE_RESULT: { //接收代码表结果 TDFCodeResult codeResult = msg.Data as TDFCodeResult; string strMsg = string.Format("获取到代码表, info:{0}, 市场个数:{1}", codeResult.Info, codeResult.Markets.Length); logger.Info(strMsg); //获取代码表内容,多个市场使用分号分割:SH;SZ;CF TDFCode[] codeArr; this._dataSource.GetCodeTable("", out codeArr); AddSecurity(codeArr); //if (codeArr[i].Type >= 0x90 && codeArr[i].Type <= 0x95) //{ // // 期权数据 // TDFOptionCode code = new TDFOptionCode(); // var ret = this._tdfImp.GetOptionCodeInfo(codeArr[i].WindCode, ref code); //} } break; case TDFMSGID.MSG_SYS_QUOTATIONDATE_CHANGE: { //行情日期变更。 TDFQuotationDateChange quotationChange = msg.Data as TDFQuotationDateChange; string strMsg = string.Format("接收到行情日期变更通知消息,market:{0}, old date:{1}, new date:{2}", quotationChange.Market, quotationChange.OldDate, quotationChange.NewDate); logger.Info(strMsg); } break; case TDFMSGID.MSG_SYS_MARKET_CLOSE: { //闭市消息 TDFMarketClose marketClose = msg.Data as TDFMarketClose; string strMsg = string.Format("接收到闭市消息, 交易所:{0}, 时间:{1}, 信息:{2}", marketClose.Market, marketClose.Time, marketClose.Info); logger.Info(strMsg); } break; case TDFMSGID.MSG_SYS_HEART_BEAT: { //心跳消息 logger.Info("接收到心跳消息!"); } break; default: break; } }
//重载 OnRecvSysMsg 方法,接收系统消息通知 // 请注意: // 1. 不要在这个函数里做耗时操作 // 2. 只在这个函数里做数据获取工作 -- 将数据复制到其它数据缓存区,由其它线程做业务逻辑处理 public override void OnRecvSysMsg(TDFMSG msg) { if (msg.MsgID == TDFMSGID.MSG_SYS_CONNECT_RESULT) { //连接结果 TDFConnectResult connectResult = msg.Data as TDFConnectResult; string strPrefix = connectResult.ConnResult ? "连接成功" : "连接失败"; Console.WriteLine("{0}!server:{1}:{2},{3},{4}, connect id:{5}", strPrefix, connectResult.Ip, connectResult.Port, connectResult.Username, connectResult.Password, connectResult.ConnectID); } else if (msg.MsgID == TDFMSGID.MSG_SYS_LOGIN_RESULT) { TDFLoginResult loginResult = msg.Data as TDFLoginResult; if (loginResult.LoginResult) { //登陆结果 Console.WriteLine("登陆成功,市场个数:{0}:", loginResult.Markets.Length); for (int i = 0; i < loginResult.Markets.Length; i++) { Console.WriteLine("market:{0}, dyn-date:{1}", loginResult.Markets[i], loginResult.DynDate[i]); } } else { Console.WriteLine("登陆失败!info:{0}", loginResult.Info); } } else if (msg.MsgID == TDFMSGID.MSG_SYS_CODETABLE_RESULT) { //接收代码表结果 TDFCodeResult codeResult = msg.Data as TDFCodeResult; Console.WriteLine("获取到代码表, info:{0},市场个数:{1}", codeResult.Info, codeResult.Markets.Length); for (int i = 0; i < codeResult.Markets.Length; i++) { Console.WriteLine("market:{0}, date:{1}, code count:{2}", codeResult.Markets[i], codeResult.CodeDate[i], codeResult.CodeCount[i]); } //FileStream fsFile = new FileStream(@"d:\log.txt", FileMode.OpenOrCreate); //StreamWriter swWriter = new StreamWriter(fsFile); ////寫入數據 ////swWriter.WriteLine("Hello Wrold."); ////swWriter.WriteLine("It is now {0}", DateTime.Now.ToLongDateString()); ////客户端请自行保存代码表,本处演示怎么获取代码表内容 //TDFCode[] codeArr; //GetCodeTable("", out codeArr); ////Console.WriteLine("接收到{0}项代码!, 输出前100项", codeArr.Length); ////for (int i = 0; i < 100 && i < codeArr.Length; i++) //for (int i = 0; i < codeArr.Length; i++) //{ // if (codeArr[i].Type >= 0x90 && codeArr[i].Type <= 0x95) // { // // 期权数据 // TDFOptionCode code = new TDFOptionCode(); // var ret = GetOptionCodeInfo(codeArr[i].WindCode, ref code); // PrintHelper.PrintObject(code); // swWriter.WriteLine(codeArr[i].WindCode + "\t" + codeArr[i].Code + "\t" + codeArr[i].CNName + "\t" + codeArr[i].Type); // } // else // { // //PrintHelper.PrintObject(codeArr[i]); // swWriter.WriteLine(codeArr[i].WindCode + "\t" + codeArr[i].Code + "\t" + codeArr[i].CNName + "\t" + codeArr[i].Type); // } //} //swWriter.Close(); } else if (msg.MsgID == TDFMSGID.MSG_SYS_QUOTATIONDATE_CHANGE) { //行情日期变更。 TDFQuotationDateChange quotationChange = msg.Data as TDFQuotationDateChange; Console.WriteLine("接收到行情日期变更通知消息,market:{0}, old date:{1}, new date:{2}", quotationChange.Market, quotationChange.OldDate, quotationChange.NewDate); } else if (msg.MsgID == TDFMSGID.MSG_SYS_MARKET_CLOSE) { //闭市消息 TDFMarketClose marketClose = msg.Data as TDFMarketClose; Console.WriteLine("接收到闭市消息, 交易所:{0}, 时间:{1}, 信息:{2}", marketClose.Market, marketClose.Time, marketClose.Info); } else if (msg.MsgID == TDFMSGID.MSG_SYS_HEART_BEAT) { //心跳消息 Console.WriteLine("接收到心跳消息!"); } }
//重载 OnRecvSysMsg 方法,接收系统消息通知 // 请注意: // 1. 不要在这个函数里做耗时操作 // 2. 只在这个函数里做数据获取工作 -- 将数据复制到其它数据缓存区,由其它线程做业务逻辑处理 public override void OnRecvSysMsg(TDFMSG msg) { //throw new NotImplementedException(); if (msg.MsgID == TDFMSGID.MSG_SYS_CONNECT_RESULT) { //连接结果 TDFConnectResult connectResult = msg.Data as TDFConnectResult; string strPrefix = connectResult.ConnResult ? "连接成功" : "连接失败"; logA.LogEvent("系统服务器连接情况 :" + strPrefix); } else if (msg.MsgID == TDFMSGID.MSG_SYS_LOGIN_RESULT) { //登陆结果 TDFLoginResult loginResult = msg.Data as TDFLoginResult; if (loginResult.LoginResult) { logA.LogEvent("系统服务器登陆成功"); for (int i = 0; i < loginResult.Markets.Length; i++) { logA.LogEvent(String.Format("market:{0},dyn-date:{1}", loginResult.Markets[i], loginResult.DynDate[i])); } } else { logA.LogEvent(String.Format("登陆失败! info:{0}", loginResult.Info)); } } else if (msg.MsgID == TDFMSGID.MSG_SYS_CODETABLE_RESULT) { //接收代码表结果 TDFCodeResult codeResult = msg.Data as TDFCodeResult; logA.LogEvent(String.Format("获取到代码表, info:{0},市场个数:{1}", codeResult.Info, codeResult.Markets.Length)); //代码表是什么鸟玩意?? TDFCode[] codeArrSZ; GetCodeTable("SZ", out codeArrSZ); TDFCode[] codeArrSH; GetCodeTable("SH", out codeArrSH); //for (int i = 0; i < 100 && i < codeArr.Length; i++) //{ // if (codeArr[i].Type >= 0x90 && codeArr[i].Type <= 0x95) // { // // 期权数据 // TDFOptionCode code = new TDFOptionCode(); // var ret = GetOptionCodeInfo(codeArr[i].WindCode, ref code); // PrintHelper.PrintObject(code); // } // else // { // PrintHelper.PrintObject(codeArr[i]); // } //} } else if (msg.MsgID == TDFMSGID.MSG_SYS_QUOTATIONDATE_CHANGE) { //行情日期变更。 TDFQuotationDateChange quotationChange = msg.Data as TDFQuotationDateChange; logA.LogEvent(String.Format("接收到行情日期变更通知消息,market:{0}, old date:{1}, new date:{2}", quotationChange.Market, quotationChange.OldDate, quotationChange.NewDate)); } else if (msg.MsgID == TDFMSGID.MSG_SYS_MARKET_CLOSE) { //闭市消息 TDFMarketClose marketClose = msg.Data as TDFMarketClose; logA.LogEvent(String.Format("接收到闭市消息, 交易所:{0}, 时间:{1}, 信息:{2}", marketClose.Market, marketClose.Time, marketClose.Info)); } else if (msg.MsgID == TDFMSGID.MSG_SYS_HEART_BEAT) { //心跳消息 } }