예제 #1
0
        void do_work(string exchange)
        {
            web_request wreq = new web_request();

            wreq.handler_ = this;
            int run_days = 0;

            while (dtpFrom.Value.Date <= dtpEnd.Value.Date)
            {
                int y = dtpFrom.Value.Date.Year;
                int m = dtpFrom.Value.Date.Month;
                int d = dtpFrom.Value.Day;
                dtpFrom.Value = dtpFrom.Value.Date.AddDays(1);

                DateTime do_date = new DateTime(y, m, d);
                if (do_date.DayOfWeek == DayOfWeek.Saturday || do_date.DayOfWeek == DayOfWeek.Sunday)
                {
                    continue;
                }
                wreq.lst_request_date_.Add(do_date);
                run_days++;
            }
            pbarExc.Minimum = 0;
            pbarExc.Maximum = run_days;
            pbarExc.Value   = 0;

            txtStatus.Text = "Run...";
            ThreadStart start = null;

            if (exchange == "dce")
            {
                start = new ThreadStart(wreq.download_dce);
            }
            else if (exchange == "czce")
            {
                start = new ThreadStart(wreq.download_czce);
            }
            else if (exchange == "shfe")
            {
                start = new ThreadStart(wreq.download_shfe);
            }
            else if (exchange == "cffex")
            {
                start = new ThreadStart(wreq.download_cffex);
            }
            Thread t = new Thread(start);

            t.Start();
        }
예제 #2
0
        public int run()
        {
            web_request wreq = new web_request();
            string      json = wreq.download_json("dhjr.kiiik.com", "https://dhjr.kiiik.com/html/table.html?from=singlemessage&isappinstalled=1",
                                                  "https://dhjr.kiiik.com/public/getBmsCurrexchcommrateInfo.do");

            if (json.Length > 0)
            {
                dhqh_commition commis = JObject.Parse(json).ToObject <dhqh_commition>();
                List <string>  list   = new List <string>();
                foreach (commition comm in commis.bmsCurrexchcommrateInfo)
                {
                    string line = comm.instrumentid + ",";
                    if (Double.Parse(comm.openratiobyvolume) > 0.1)
                    {
                        line += comm.openratiobyvolume + ",";
                    }
                    else
                    {
                        line += comm.openratiobymoney + ",";
                    }
                    if (Double.Parse(comm.closeratiobyvolume) > 0.1)
                    {
                        line += comm.closeratiobyvolume + ",";
                    }
                    else
                    {
                        line += comm.closeratiobymoney + ",";
                    }
                    if (Double.Parse(comm.closetodayratiobyvolume) > 0.1)
                    {
                        line += comm.closetodayratiobyvolume + ",";
                    }
                    else
                    {
                        line += comm.closetodayratiobymoney + ",";
                    }
                    list.Add(line);
                }
                string file_name = "./all_symbol_commission.csv";
                using (StreamWriter sw = new StreamWriter(file_name))
                {
                    sw.WriteLine("品种,开仓,平仓,平今仓");
                    foreach (string line in list)
                    {
                        sw.WriteLine(line);
                    }
                }
                // 备份
                if (File.Exists(file_name))
                {
                    string folder = "./commission";
                    if (!Directory.Exists(folder))
                    {
                        Directory.CreateDirectory(folder);
                    }

                    string new_name = folder + "/" + DateTime.Now.ToString("yyyyMMdd") + ".csv";
                    File.Copy(file_name, new_name);
                }
            }

            return(0);
        }