/// <summary> /// 开始策略 /// </summary> public static void start() { //加载代码表//step 1 m_codes = ""; if (m_codedMap.Count == 0) { String content = ""; FCFile.read(DataCenter.getAppPath() + "\\codes.txt", ref content); String[] strs = content.Split(new String[] { "\r\n" }, StringSplitOptions.RemoveEmptyEntries); foreach (String str in strs) { String[] substrs = str.Split(new string[] { "," }, StringSplitOptions.RemoveEmptyEntries); Security security = new Security(); security.m_code = substrs[0]; security.m_name = substrs[1]; m_codedMap[security.m_code] = security; m_codes += security.m_code; m_codes += ","; } loadHistoryDatas(); } Thread thread = new Thread(new ThreadStart(startWork)); thread.Start(); }
/// <summary> /// 创建网格 /// </summary> public PropertyGrid() { BackColor = FCColor.Back; GridLineColor = FCColor.Border; RowStyle.HoveredBackColor = FCDraw.FCCOLORS_HOVEREDROWCOLOR; RowStyle.SelectedBackColor = FCDraw.FCCOLORS_SELECTEDROWCOLOR; RowStyle.SelectedTextColor = FCDraw.FCCOLORS_TEXTCOLOR4; RowStyle.Font = new FCFont("微软雅黑", 12, false, false, false); FCGridRowStyle alternateRowStyle = new FCGridRowStyle(); alternateRowStyle.BackColor = FCDraw.FCCOLORS_ALTERNATEROWCOLOR; alternateRowStyle.HoveredBackColor = FCDraw.FCCOLORS_HOVEREDROWCOLOR; alternateRowStyle.SelectedBackColor = FCDraw.FCCOLORS_SELECTEDROWCOLOR; alternateRowStyle.SelectedTextColor = FCDraw.FCCOLORS_TEXTCOLOR4; alternateRowStyle.Font = new FCFont("微软雅黑", 12, false, false, false); AlternateRowStyle = alternateRowStyle; m_assembly = Assembly.Load("facecat_net"); String content = ""; FCFile.read(DataCenter.GetAppPath() + "\\config\\CN_PROPERTIES.txt", ref content); String[] strs = content.Split(new String[] { "\r\n" }, StringSplitOptions.RemoveEmptyEntries); int strsSize = strs.Length; for (int i = 0; i < strsSize; i++) { String[] subStrs = strs[i].Split(new String[] { "=" }, StringSplitOptions.RemoveEmptyEntries); m_chNames[subStrs[0].ToLower()] = subStrs[1]; } }
/// <summary> /// 开始策略 /// </summary> public static void start() { //加载代码表//step 1 m_codes = ""; if (m_codedMap.Count == 0) { String content = ""; FCFile.read(DataCenter.getAppPath() + "\\codes.txt", ref content); String[] strs = content.Split(new String[] { "\r\n" }, StringSplitOptions.RemoveEmptyEntries); foreach (String str in strs) { String[] substrs = str.Split(new string[] { "," }, StringSplitOptions.RemoveEmptyEntries); Security security = new Security(); security.m_code = substrs[0]; security.m_name = substrs[1]; m_codedMap[security.m_code] = security; m_codes += security.m_code; m_codes += ","; } loadHistoryDatas(); Dictionary <String, List <SecurityData> > datas = new Dictionary <string, List <SecurityData> >(); foreach (String key in m_historyDatas.Keys) { List <SecurityData> hDatas = m_historyDatas[key]; if (hDatas.Count > 100) { if (m_codedMap.ContainsKey(key)) { datas[key] = new List <SecurityData>(); for (int i = hDatas.Count - 1; i >= 0 && i > hDatas.Count - 11; i--) { datas[key].Add(hDatas[i]); } } } } StringBuilder sb = new StringBuilder(); foreach (String key in datas.Keys) { List <SecurityData> hDatas = datas[key]; Security security = m_codedMap[key]; sb.Append(security.m_name + ","); for (int j = 0; j < hDatas.Count; j++) { sb.Append(hDatas[j].m_close); if (j != hDatas.Count - 1) { sb.Append(","); } } sb.Append("\r\n"); } FCFile.write(Application.StartupPath + "\\收盘价排名.txt", sb.ToString()); } Thread thread = new Thread(new ThreadStart(startWork)); thread.Start(); }
/// <summary> /// 获取通达信的历史数据的字符串 /// </summary> /// <param name="code">股票代码</param> /// <param name="path">本地文件路径</param> /// <returns>数据字符串</returns> public static String getTdxHistoryDatasStrByCode(String code, String path) { String fileName = FCStrEx.convertDBCodeToFileName(code); String result = ""; String filePath = path + fileName; if (FCFile.isFileExist(filePath)) { FCFile.read(filePath, ref result); } return(result); }
/// <summary> /// 启动监听 /// </summary> public void start() { m_useScript = FCFile.isFileExist(m_fileName); if (m_useScript) { m_native = new FCNative(); FCFile.read(m_fileName, ref m_script); m_indicator = CFunctionEx.CreateScript(m_script, m_native); Console.WriteLine(m_script); } try { //string host = "127.0.0.1"; //IPAddress ip = IPAddress.Parse(host); if (m_indicator != null) { m_indicator.callFunction("ONHTTPSERVERSTARTING('" + m_fileName + "');"); } IPEndPoint ipe = new IPEndPoint(IPAddress.Any, m_port); m_listener = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); m_listener.Bind(ipe); m_listener.Listen(0); } catch (Exception ex) { if (m_indicator != null) { m_indicator.callFunction("ONHTTPSERVERSTARTFAIL('" + ex.Message + "\r\n" + ex.StackTrace + "');"); } return; } int minThreadNum = 0, portThreadNum = 0, maxThreadNum = 0; ThreadPool.GetMaxThreads(out maxThreadNum, out portThreadNum); ThreadPool.GetMinThreads(out minThreadNum, out portThreadNum); if (m_indicator != null) { m_indicator.callFunction("ONHTTPSERVERSTART(" + FCStr.convertIntToStr(maxThreadNum) + "," + FCStr.convertIntToStr(minThreadNum) + ");"); } while (true) { Socket socket = m_listener.Accept(); ThreadPool.QueueUserWorkItem(new WaitCallback(readData), socket); } m_listener.Close(); }
/// <summary> /// 获取分时数据 /// </summary> public static void getMinuteDatas() { if (m_minuteDatas.Count > 0) { return; } String appPath = DataCenter.getAppPath(); foreach (String code in m_codedMap.Keys) { String fileName = m_newFileDir + FCStrEx.convertDBCodeToFileName(code); if (!FCFile.isFileExist(fileName)) { fileName = m_newFileDir + FCStrEx.convertDBCodeToSinaCode(code).ToUpper() + ".txt"; } if (FCFile.isFileExist(fileName)) { String text = ""; FCFile.read(fileName, ref text); List <SecurityData> datas = new List <SecurityData>(); StockService.getHistoryDatasByMinuteStr(text, datas); if (datas.Count > 0) { int rindex = 0; int dataSize = datas.Count; while (rindex < dataSize) { SecurityData d = datas[rindex]; if (rindex == 0) { d.m_avgPrice = d.m_close; } else { SecurityData ld = datas[rindex - 1]; d.m_avgPrice = (ld.m_avgPrice * rindex + d.m_close) / (rindex + 1); } rindex++; } m_minuteDatas[code] = datas; } } } }
/// <summary> /// 获取证券列表 /// </summary> /// <returns>证券列表</returns> public List <Security> getSecurities() { List <Security> securities = new List <Security>(); String codesStr = ""; FCFile.read(DataCenter.getAppPath() + "\\codes.txt", ref codesStr); String[] strs = codesStr.Split(new String[] { "\r\n" }, StringSplitOptions.RemoveEmptyEntries); int strsSize = strs.Length; for (int i = 0; i < strsSize; i++) { String[] subStrs = strs[i].Split(','); Security security = new Security(); security.m_code = subStrs[0]; security.m_name = subStrs[1]; securities.Add(security); } return(securities); }
/// <summary> /// 加载界面方法 /// </summary> protected override void OnLoad(EventArgs e) { base.OnLoad(e); String filePath = Application.StartupPath + "\\LoginInfo.txt"; if (FCFile.isFileExist(filePath)) { String content = ""; FCFile.read(filePath, ref content); if (content.Length > 0) { String[] strs = content.Split(new String[] { "\r\n" }, StringSplitOptions.RemoveEmptyEntries); txtMDServer.Text = strs[0]; txtTDServer.Text = strs[1]; txtBrokerID.Text = strs[2]; txtInvestorID.Text = strs[3]; txtPassword.Text = strs[4]; } } }
/// <summary> /// 创建项目 /// </summary> /// <param name="dir">目录</param> private void createProject(String projectName, String dir, String identifier) { ArrayList <String> dirs = new ArrayList <String>(); FCFile.getDirectories(dir, dirs); int dirsSize = dirs.Count; for (int i = 0; i < dirsSize; i++) { createProject(projectName, dirs.get(i), identifier); } ArrayList <String> files = new ArrayList <String>(); FCFile.getFiles(dir, files); int filesSize = files.Count; for (int i = 0; i < filesSize; i++) { String file = files.get(i); String content = ""; if (file.Substring(file.LastIndexOf('\\')).IndexOf(identifier) != -1) { FCFile.read(file, ref content); String newFile = file.Replace(identifier, projectName); FCFile.write(newFile, content); FCFile.removeFile(file); file = newFile; } FCFile.read(file, ref content); if (content.IndexOf(identifier) != -1) { content = content.Replace(identifier, projectName); FCFile.write(file, content); } } dirs.Clear(); files.Clear(); }
/// <summary> /// 检查脚本 /// </summary> public void checkScript() { String newScript = ""; FCFile.read(m_fileName, ref newScript); if (m_script != newScript) { Console.WriteLine("检测到脚本被修改..."); m_script = newScript; lock (m_indicators) { while (true) { try { FCScript indicator = m_indicators.Pop(); indicator.delete(); } catch { break; } } } } }