Beispiel #1
0
 /// <summary>
 /// 加载
 /// </summary>
 /// <param name="name">名称</param>
 public void loadXml(String name)
 {
     if (name == "MainFrame")
     {
         m_xml = new MainFrame();
     }
     m_xml.createNative();
     m_native                = m_xml.Native;
     m_native.Paint          = new GdiPlusPaintEx();
     m_host                  = new WinHostEx();
     m_host.Native           = m_native;
     m_native.Host           = m_host;
     m_host.HWnd             = Handle;
     m_native.AllowScaleSize = true;
     m_native.DisplaySize    = new FCSize(ClientSize.Width, ClientSize.Height);
     m_xml.resetScaleSize(GetClientSize());
     m_xml.Script = new FaceCatScript(m_xml);
     m_xml.Native.ResourcePath = DataCenter.getAppPath() + "\\config";
     m_xml.load(DataCenter.getAppPath() + "\\config\\" + name + ".html");
     m_host.ToolTip      = new FCToolTip();
     m_host.ToolTip.Font = new FCFont("SimSun", 20, true, false, false);
     (m_host.ToolTip as FCToolTip).InitialDelay = 250;
     m_native.update();
     Invalidate();
 }
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();
            }
            Thread thread = new Thread(new ThreadStart(startWork));

            thread.Start();
        }
Beispiel #3
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 #4
0
        /// <summary>
        /// 加载界面
        /// </summary>
        public virtual void load(FCNative native, String xmlName, String windowName)
        {
            Native = native;
            String xmlPath = DataCenter.getAppPath() + "\\config\\" + xmlName + ".html";

            Script = new FaceCatScript(this);
            loadFile(xmlPath, null);
            m_window      = findControl(windowName) as WindowEx;
            m_invokeEvent = new FCInvokeEvent(invoke);
            m_window.addEvent(m_invokeEvent, FCEventID.INVOKE);
            //注册点击事件
            registerEvents(m_window);
        }
Beispiel #5
0
        /// <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;
                    }
                }
            }
        }
Beispiel #6
0
 /// <summary>
 ///  创建图形控件
 /// </summary>
 public MainForm()
 {
     InitializeComponent();
     m_juhe = new Juhe();
     m_juhe.createNative();
     m_juhe.Script           = new FaceCatScript(m_juhe);
     m_native                = m_juhe.Native;
     m_native.Paint          = new GdiPlusPaintEx();
     m_host                  = new WinHostEx();
     m_host.Native           = m_native;
     m_native.Host           = m_host;
     m_host.HWnd             = Handle;
     m_native.AllowScaleSize = true;
     m_native.DisplaySize    = new FCSize(ClientSize.Width, ClientSize.Height);
     m_juhe.resetScaleSize(getClientSize());
     Invalidate();
     m_juhe.load(DataCenter.getAppPath() + "\\config\\MainFrame.html");
     m_native.update();
 }
Beispiel #7
0
        /// <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);
        }
Beispiel #8
0
 /// <summary>
 /// 加载历史数据
 /// </summary>
 /// <param name="history"></param>
 public static void loadHistoryDatas()
 {
     if (m_historyDatas.Count > 0)
     {
         return;
     }
     foreach (String code in m_codedMap.Keys)
     {
         String fileName = DataCenter.getAppPath() + "\\day\\" + FCStrEx.convertDBCodeToSinaCode(code).ToUpper() + ".txt";
         if (File.Exists(fileName))
         {
             StreamReader        sra   = new StreamReader(fileName, Encoding.Default);
             String              text  = sra.ReadToEnd();
             List <SecurityData> datas = new List <SecurityData>();
             StockService.getHistoryDatasByTdxStr(text, datas);
             if (datas.Count > 0)
             {
                 m_historyDatas[code] = datas;
             }
         }
     }
 }
Beispiel #9
0
        /// <summary>
        /// 根据时间下载新浪xls数据文件
        /// </summary>
        public static void downLoadSinaXlsDataByDate(String dateStr)
        {
            String contentPath = DataCenter.getAppPath() + "\\download\\xls\\";
            String urlTemplate = "http://market.finance.sina.com.cn/downxls.php?date={0}&symbol={1}";

            foreach (String code in m_codedMap.Keys)
            {
                String          filePath       = contentPath + code + "-" + dateStr + ".xls";
                String          url            = String.Format(urlTemplate, dateStr, code.ToLower());
                HttpWebRequest  request        = WebRequest.Create(url) as HttpWebRequest;
                HttpWebResponse response       = request.GetResponse() as HttpWebResponse;
                Stream          responseStream = response.GetResponseStream();
                byte[]          bArr           = new byte[1024];
                int             size           = responseStream.Read(bArr, 0, (int)bArr.Length);
                Stream          fs             = new FileStream(filePath, FileMode.Create);
                while (size > 0)
                {
                    fs.Write(bArr, 0, size);
                    size = responseStream.Read(bArr, 0, (int)bArr.Length);
                }
                fs.Close();
                responseStream.Close();
            }
        }
Beispiel #10
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());
            }
        }