Beispiel #1
0
        static void Main()
        {
            CHelp.loadConfig();

            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            Application.Run(new Form1());
        }
Beispiel #2
0
        public double toUSD(double v, DateTime d)
        {
            string cry = getSettleCurrency();

            if (cry == "USD")
            {
                return(v);
            }
            else
            {
                return(v * CHelp.toUSD(cry, d));
            }
        }
Beispiel #3
0
        public double toCuy(double dollar, DateTime d)
        {
            string cry = getSettleCurrency();

            if (cry == "USD")
            {
                return(dollar);
            }
            else
            {
                return(dollar / CHelp.toUSD(cry, d));
            }
        }
Beispiel #4
0
 public CCandleData(OHLC ol, string dateStr)
 {
     mPrice      = ol;
     mCandleTime = CHelp.str2Date(dateStr).Date;
 }
Beispiel #5
0
        private void button1_historyDownload_Click(object sender, EventArgs e)
        {
            if (MessageBox.Show("将会下载该时间段所有品种的历史价格数据,需要较多时间,确定继续吗?", "", MessageBoxButtons.YesNo) == DialogResult.No)
            {
                return;
            }

            DateTime startTime = dateTimePicker1_start.Value;
            DateTime endTime   = dateTimePicker2_end.Value;

            if (endTime < startTime)
            {
                MessageBox.Show("结束日期必须大于等于开始日期");
                return;
            }

            button1_historyDownload.Enabled = false;

            List <CSymbolPro> selSymbols = getSelSymbol();

            string pricePeriod = comboBox1_PricePeriod.SelectedItem.ToString().Trim();

            progressBar1_historyData.Maximum = selSymbols.Count;
            progressBar1_historyData.Value   = 0;

            Thread thread = new Thread(new ThreadStart(() =>
            {
                foreach (var j in selSymbols)
                {
                    startTime = dateTimePicker1_start.Value;
                    endTime   = dateTimePicker2_end.Value;

                    Dictionary <DateTime, CCandleData> priceData = new Dictionary <DateTime, CCandleData>();
                    DateTime nowTime = new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day, 0, 0, 0);
                    if (endTime > nowTime.AddDays(-30))
                    {
                        endTime = nowTime.AddDays(-30);
                    }
                    int days = (endTime - startTime).Days;
                    if (days > 4000)
                    {
                        DateTime middleTime;
                        do
                        {
                            middleTime = startTime.AddDays(3000);
                            if (middleTime > endTime)
                            {
                                middleTime = endTime;
                            }

                            Dictionary <DateTime, CCandleData> priceToAdd = CHelp.getCandleHistoryData(j.mSymbolName, startTime, middleTime, pricePeriod);
                            foreach (var v in priceToAdd)
                            {
                                if (!priceData.ContainsKey(v.Key))
                                {
                                    priceData[v.Key] = v.Value;
                                }
                            }
                            startTime = middleTime.AddDays(1);
                        }while (middleTime < endTime);
                    }
                    else
                    {
                        priceData = CHelp.getCandleHistoryData(j.mSymbolName, startTime, endTime, pricePeriod);
                    }

                    if (priceData.Count > 0)
                    {
                        string sql = string.Format("select count(*) from PriceData where Symbol='{0}' and Period='{1}'", j.mSymbolName, pricePeriod);
                        if (int.Parse(CSqliteDBHelp.getValue(sql).ToString()) == 0)
                        {
                            sql = string.Format("insert into PriceData (Symbol,Period,Data) values ('{0}','{1}','{2}')", j.mSymbolName, pricePeriod, JsonConvert.SerializeObject(new CCandleDataWrap(priceData)));
                        }
                        else
                        {
                            sql = string.Format("update PriceData set Data='{0}' where Symbol='{1}' and Period='{2}'", JsonConvert.SerializeObject(new CCandleDataWrap(priceData)), j.mSymbolName, pricePeriod);
                        }
                        CSqliteDBHelp.executeSql(sql);
                    }
                    Invoke(new Action(() =>
                    {
                        progressBar1_historyData.Value++;
                    }));
                }
                Invoke(new Action(() =>
                {
                    button1_historyDownload.Enabled = true;
                }));
            }));

            thread.IsBackground = true;
            thread.Start();
        }