Beispiel #1
0
 /// <summary>
 /// 按钮点击事件
 /// </summary>
 /// <param name="sender">调用者</param>
 /// <param name="mp">坐标</param>
 /// <param name="button">按钮</param>
 /// <param name="click">点击次数</param>
 /// <param name="delta">滚轮滚动值</param>
 private void clickButton(object sender, FCTouchInfo touchInfo)
 {
     if (touchInfo.m_firstTouch && touchInfo.m_clicks == 1)
     {
         FCView control = sender as FCView;
         String name    = control.Name;
         if (name == "btnCancel")
         {
             close();
         }
         else if (name == "btnOK")
         {
             FCTextBox            txtName          = getTextBox("txtName");
             FCTextBox            txtScript        = getTextBox("txtScript");
             List <IndicatorData> indicatorDatas   = m_mainFrame.m_indicators;
             IndicatorData        newIndicatorData = null;
             //判断是否重复
             int indicatorDatasSize = indicatorDatas.Count;
             for (int i = 0; i < indicatorDatasSize; i++)
             {
                 IndicatorData indicatorData = indicatorDatas[i];
                 if (indicatorData.m_name == txtName.Text)
                 {
                     if (m_isEdit)
                     {
                         newIndicatorData = indicatorData;
                     }
                     else
                     {
                         MessageBox.Show("该指标名称已经存在!", "提示");
                         return;
                     }
                 }
             }
             //添加指标
             if (!m_isEdit)
             {
                 newIndicatorData = new IndicatorData();
                 indicatorDatas.Add(newIndicatorData);
             }
             newIndicatorData.m_name   = txtName.Text;
             newIndicatorData.m_script = txtScript.Text;
             String path    = Application.StartupPath + "\\indicators.txt";
             String content = JsonConvert.SerializeObject(indicatorDatas);
             FCFile.write(path, content);
             if (!m_isEdit)
             {
                 m_mainFrame.addIndicator(newIndicatorData);
             }
             close();
             Native.update();
             Native.invalidate();
         }
         else if (name == "lblDelete")
         {
             m_mainFrame.removeIndicator(m_indicatorData);
             close();
         }
     }
 }
Beispiel #2
0
        /// <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();
        }
Beispiel #3
0
        /// <summary>
        /// 登录
        /// </summary>
        /// <param name="sender">调用者</param>
        /// <param name="e">参数</param>
        private void btnLogin_Click(object sender, EventArgs e)
        {
            //收集信息
            String mdServer   = txtMDServer.Text.Trim();
            String tdServer   = txtTDServer.Text.Trim();
            String brokerID   = txtBrokerID.Text.Trim();
            String investorID = txtInvestorID.Text.Trim();
            String password   = txtPassword.Text.Trim();

            if (mdServer.Length == 0)
            {
                MessageBox.Show("请输入行情服务器的地址!");
                return;
            }
            if (tdServer.Length == 0)
            {
                MessageBox.Show("请输入交易服务器的地址!");
                return;
            }
            if (brokerID.Length == 0)
            {
                MessageBox.Show("请输入机构ID!");
                return;
            }
            if (investorID.Length == 0)
            {
                MessageBox.Show("请输入投资者账号!");
                return;
            }
            if (password.Length == 0)
            {
                MessageBox.Show("请输入密码!");
                return;
            }
            String content  = String.Format("{0}\r\n{1}\r\n{2}\r\n{3}\r\n{4}", mdServer, tdServer, brokerID, investorID, password);
            String filePath = Application.StartupPath + "\\LoginInfo.txt";

            FCFile.write(filePath, content);
            //发起登录
            m_mainForm.Xml.loginCTP(mdServer, tdServer, brokerID, investorID, password);
            this.DialogResult = DialogResult.OK;
            Close();
        }
Beispiel #4
0
        /// <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();
        }
Beispiel #5
0
        /// <summary>
        /// 数据落地线程工作
        /// </summary>
        public static void startWork3()
        {
            //复制数据
            loadHistoryDatas();
            //getMinuteDatas();
            //新旧数据合并
            foreach (String oCode in m_historyDatas.Keys)
            {
                if (!m_latestDatas.ContainsKey(oCode) || !m_historyDatas.ContainsKey(oCode))
                {
                    continue;
                }
                SecurityLatestData  securityLatestData = m_latestDatas[oCode];
                List <SecurityData> oldSecurityDatas = m_historyDatas[oCode];
                SecurityData        oldSecurityData = oldSecurityDatas[oldSecurityDatas.Count - 1];
                int myear = 0, mmonth = 0, mday = 0, mhour = 0, mmin = 0, msec = 0, mmsec = 0;
                FCStr.getDateByNum(oldSecurityData.m_date, ref myear, ref mmonth, ref mday, ref mhour, ref mmin, ref msec, ref mmsec);
                int year = 0, month = 0, day = 0, hour = 0, min = 0, sec = 0, msec2 = 0;
                FCStr.getDateByNum(securityLatestData.m_date, ref year, ref month, ref day, ref hour, ref min, ref sec, ref msec2);
                if (year >= myear && month >= mmonth && day >= mday)
                {
                    SecurityData nSecurityData = new SecurityData();
                    nSecurityData.m_amount = securityLatestData.m_amount;
                    nSecurityData.m_close  = securityLatestData.m_close;
                    nSecurityData.m_date   = securityLatestData.m_date;
                    nSecurityData.m_high   = securityLatestData.m_high;
                    nSecurityData.m_low    = securityLatestData.m_low;
                    nSecurityData.m_open   = securityLatestData.m_open;
                    nSecurityData.m_volume = securityLatestData.m_volume;
                    if (day == mday)
                    {
                        m_historyDatas[oCode].RemoveAt(m_historyDatas[oCode].Count - 1);
                    }
                    m_historyDatas[oCode].Add(nSecurityData);
                }
            }
            String outputFileTemplate = DataCenter.getAppPath() + "\\day\\{0}.txt";
            String fileInfo           = "{0} {1} 日线 前复权\r\n";
            String title         = "      日期	    开盘	    最高	    最低	    收盘	    成交量	    成交额\r\n";
            String lineTemp      = "{0},{1},{2},{3},{4},{5},{6}\r\n";
            String timeFormatStr = "yyyy-MM-dd";

            //写入文件
            foreach (String code in m_historyDatas.Keys)
            {
                List <SecurityData> temp3   = m_historyDatas[code];
                StringBuilder       strbuff = new StringBuilder();
                strbuff.Append(String.Format(fileInfo, m_codedMap[code].m_code, m_codedMap[code].m_name));
                strbuff.Append(title);
                foreach (SecurityData sdt in temp3)
                {
                    strbuff.Append(String.Format(lineTemp,                                                   //
                                                 FCStr.convertNumToDate(sdt.m_date).ToString(timeFormatStr), //
                                                 sdt.m_open,                                                 //
                                                 sdt.m_high,                                                 //
                                                 sdt.m_low,                                                  //
                                                 sdt.m_close,                                                //
                                                 sdt.m_volume,                                               //
                                                 sdt.m_amount));
                }
                strbuff.Append("数据来源:通达信\r\n");
                FCFile.write(String.Format(outputFileTemplate, code), strbuff.ToString());
            }
        }
Beispiel #6
0
        /// <summary>
        /// 工作中
        /// </summary>
        /// <param name="dataInfo">信息</param>
        /// <returns>状态</returns>
        public override int onWorking(WorkDataInfo dataInfo)
        {
            Console.WriteLine(dataInfo.m_id.ToString());
            SecurityDataInfo securityDataInfo = dataInfo as SecurityDataInfo;
            String           url = String.Format(m_listUrl, FCStrEx.ConvertDBCodeToSinaCode(securityDataInfo.m_security.m_code));

            Log = String.Format("下载:{0}", securityDataInfo.m_security.m_code);
            String html = DataCenter.getHttpWebRequest(url, "GB2312");

            if (html != null && html.Length > 0)
            {
                NewsInfo newsInfo = new NewsInfo("sinanews");
                newsInfo.m_code = securityDataInfo.m_security.m_code;
                String dir = newsInfo.getDirectory();
                if (!FCFile.isDirectoryExist(dir))
                {
                    FCFile.createDirectory(dir);
                }
                String identifier = "<div class=\"datelist\">";
                int    pos        = html.IndexOf(identifier);
                if (pos != -1)
                {
                    html = html.Substring(pos + identifier.Length);
                    html = html.Substring(0, html.IndexOf("</ul>"));
                    html = html.Replace("<ul>\r\n\t\t\t", "").Replace("&nbsp;", " ");
                    String[] strs     = html.Split(new String[] { "<br>" }, StringSplitOptions.RemoveEmptyEntries);
                    int      strsSize = strs.Length;
                    for (int i = 0; i < strsSize; i++)
                    {
                        try {
                            newsInfo.m_content = "";
                            String   str     = strs[i];
                            String[] subStrs = str.Split(new String[] { "<a target='_blank' href='" }, StringSplitOptions.RemoveEmptyEntries);
                            if (subStrs.Length >= 2)
                            {
                                newsInfo.m_time = subStrs[0].Trim();
                                String[] sunStrs = subStrs[1].Split(new String[] { "'>" }, StringSplitOptions.RemoveEmptyEntries);
                                newsInfo.m_url   = sunStrs[0];
                                newsInfo.m_title = sunStrs[1].Replace("</a>", "");
                                String fileName = newsInfo.getFileName();
                                if (!FCFile.isFileExist(fileName))
                                {
                                    Log = String.Format("下载:{0}", securityDataInfo.m_security.m_code);
                                    String contentHtml = DataCenter.getHttpWebRequest(newsInfo.m_url, "UTF-8");
                                    String sIdentifier = "<!-- 原始正文start -->", eIdentifier = "<!-- 原始正文end -->";
                                    int    sPos = contentHtml.IndexOf(sIdentifier);
                                    if (sPos != -1)
                                    {
                                        String content = contentHtml.Substring(sPos + sIdentifier.Length);
                                        int    ePos    = content.IndexOf(eIdentifier);
                                        newsInfo.m_content = content.Substring(0, ePos);
                                        FCFile.write(fileName, newsInfo.ToString());
                                    }
                                }
                            }
                        }
                        catch (Exception ex) {
                        }
                    }
                }
            }
            return(1);
        }