public MarketData(TDFFutureData data) { ActionDay = data.ActionDay; AskPrice = data.AskPrice; AskVol = data.AskVol; BidPrice = data.BidPrice; BidVol = data.BidVol; Code = data.Code; High = data.High; HighLimited = data.HighLimited; Low = data.Low; LowLimited = data.LowLimited; Match = data.Match; PreClose = data.PreClose; WindCode = data.WindCode; Time = data.Time; Status = data.Status; IOPV = 1; }
//获取模拟期货行情 public static TDFFutureData GetSimFutureData() { Random seed = new Random(); double wave = seed.NextDouble(); //涨幅/跌幅 if (seed.Next(0, 1) == 0) { wave *= -1; } TDFFutureData data = new TDFFutureData() { AskPrice = new uint[5] { _futurePrice - 1, _futurePrice - 2, _futurePrice, _futurePrice + 1, _futurePrice + 2 }, AskVol = new uint[5] { 100, 100, 100, 100, 100 }, BidPrice = new uint[5] { _futurePrice - 1, _futurePrice - 2, _futurePrice, _futurePrice + 1, _futurePrice + 2 }, BidVol = new uint[5] { 100, 100, 100, 100, 100 }, Code = _futureCode, High = _futurePrice + 1, HighLimited = Convert.ToUInt32(_futurePrice * 1.1), Low = _futurePrice - 1, LowLimited = Convert.ToUInt32(_futurePrice * 0.9), Match = _futurePrice, Time = Convert.ToInt32(DateTime.Now.ToString("HHmmss")) * 1000, WindCode = "60000.SH" }; return(data); }
//获取模拟期货行情 public static TDFFutureData GetSimFutureData() { Random seed = new Random(); double wave = seed.NextDouble(); //涨幅/跌幅 if (seed.Next(0, 1) == 0) { wave *= -1; } TDFFutureData data = new TDFFutureData() { AskPrice = new uint[5] { _futurePrice - 1, _futurePrice - 2, _futurePrice, _futurePrice + 1, _futurePrice + 2 }, AskVol = new uint[5] { 100, 100, 100, 100, 100 }, BidPrice = new uint[5] { _futurePrice - 1, _futurePrice - 2, _futurePrice, _futurePrice + 1, _futurePrice + 2 }, BidVol = new uint[5] { 100, 100, 100, 100, 100 }, Code = _futureCode, High = _futurePrice + 1, HighLimited = Convert.ToUInt32(_futurePrice * 1.1), Low = _futurePrice - 1, LowLimited = Convert.ToUInt32(_futurePrice * 0.9), Match = _futurePrice, Time = Convert.ToInt32(DateTime.Now.ToString("HHmmss")) * 1000, WindCode = "60000.SH" }; return data; }
public MarketData(TDFFutureData data) { ActionDay = data.ActionDay; AskPrice = data.AskPrice; AskVol = data.AskVol; BidPrice = data.BidPrice; BidVol = data.BidVol; Code = data.Code; High = data.High; HighLimited = data.HighLimited; Low = data.Low; LowLimited = data.LowLimited; Match = data.Match; PreClose = data.PreClose; WindCode = data.WindCode; Time = data.Time; Status = data.Status; IOPV = 1; }
//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; } } }