Ejemplo n.º 1
0
        Dictionary <DateTime, CCandleData> getCandleDataFromSqlite(string symbol, string period)
        {
            Dictionary <DateTime, CCandleData> re = new Dictionary <DateTime, CCandleData>();

            string sql       = string.Format("select Data from PriceData where Symbol='{0}' and Period='{1}'", symbol, period);
            string priceData = CSqliteDBHelp.getValue(sql).ToString();

            re = JsonConvert.DeserializeObject <CCandleDataWrap>(priceData).mPrice;
            return(re);
        }
Ejemplo n.º 2
0
        public void saveSymbol()
        {
            string sql = "select count(*) from Config where Id=2";

            if (int.Parse(CSqliteDBHelp.getValue(sql).ToString()) > 0)
            {
                sql = string.Format("update Config set Data='{0}' where Id=2", JsonConvert.SerializeObject(mSymbolList));
            }
            else
            {
                sql = string.Format("insert into Config (Id,Data) values (2,'{0}')", JsonConvert.SerializeObject(mSymbolList));
            }
            CSqliteDBHelp.executeSql(sql);
        }
Ejemplo n.º 3
0
        public void loadSymbol()
        {
            string sql        = "select Data from Config where Id=2";
            object symbolData = CSqliteDBHelp.getValue(sql);

            treeView1.Nodes.Add("非农商品").Name  = "非农商品";
            treeView1.Nodes.Add("农商品").Name   = "农商品";
            treeView1.Nodes.Add("外汇").Name    = "外汇";
            treeView1.Nodes.Add("指数").Name    = "指数";
            treeView1.Nodes.Add("债券&利率").Name = "债券&利率";
            treeView1.Nodes.Add("加密货币").Name  = "加密货币";

            if (symbolData != null)
            {
                mSymbolList = JsonConvert.DeserializeObject <IEnumerable <CSymbolPro> >(symbolData.ToString()) as List <CSymbolPro>;
            }

            foreach (var v in mSymbolList)
            {
                treeView1.Nodes[v.mSymbolTypeName].Nodes.Add(v.mSymbolName);
            }
            treeView1.ExpandAll();
        }
Ejemplo n.º 4
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();
        }