コード例 #1
0
        /// <summary>
        /// 从csv文件中读取交易日信息。
        /// </summary>
        /// <param name="CSVName"></param>
        private void GetDataFromCSV(string CSVName)
        {
            DataTable tradeDaysData = CsvApplication.OpenCSV(CSVName);

            foreach (DataRow r in tradeDaysData.Rows)
            {
                tradeDaysOfDataBase.Add(Convert.ToInt32(r["tradedays"]));
            }
        }
コード例 #2
0
        public StoreData(List <optionDataFormat> myData, int start = 0, int end = 0)
        {
            if (start == 0)
            {
                start = 0;
                end   = myData.Count() - 1;
            }
            if (start != 0 && start < myData.Count() && end == 0)
            {
                end = myData.Count() - 1;
            }
            DataTable dt = new DataTable();

            dt.Columns.Add("代码", Type.GetType("System.String"));
            dt.Columns.Add("日期", Type.GetType("System.String"));
            dt.Columns.Add("时间", Type.GetType("System.Double"));
            dt.Columns.Add("成交价", Type.GetType("System.Double"));
            dt.Columns.Add("Ask1", Type.GetType("System.Double"));
            dt.Columns.Add("Ask2", Type.GetType("System.Double"));
            dt.Columns.Add("Ask3", Type.GetType("System.Double"));
            dt.Columns.Add("Ask4", Type.GetType("System.Double"));
            dt.Columns.Add("Ask5", Type.GetType("System.Double"));
            dt.Columns.Add("Askv1", Type.GetType("System.Double"));
            dt.Columns.Add("Askv2", Type.GetType("System.Double"));
            dt.Columns.Add("Askv3", Type.GetType("System.Double"));
            dt.Columns.Add("Askv4", Type.GetType("System.Double"));
            dt.Columns.Add("Askv5", Type.GetType("System.Double"));
            dt.Columns.Add("bid1", Type.GetType("System.Double"));
            dt.Columns.Add("bid2", Type.GetType("System.Double"));
            dt.Columns.Add("bid3", Type.GetType("System.Double"));
            dt.Columns.Add("bid4", Type.GetType("System.Double"));
            dt.Columns.Add("bid5", Type.GetType("System.Double"));
            dt.Columns.Add("bidv1", Type.GetType("System.Double"));
            dt.Columns.Add("bidv2", Type.GetType("System.Double"));
            dt.Columns.Add("bidv3", Type.GetType("System.Double"));
            dt.Columns.Add("bidv4", Type.GetType("System.Double"));
            dt.Columns.Add("bidv5", Type.GetType("System.Double"));
            dt.Columns.Add("high", Type.GetType("System.Double"));
            dt.Columns.Add("low", Type.GetType("System.Double"));
            dt.Columns.Add("成交量", Type.GetType("System.Double"));
            dt.Columns.Add("成交额", Type.GetType("System.Double"));
            dt.Columns.Add("持仓量", Type.GetType("System.Double"));
            dt.Columns.Add("成交笔数", Type.GetType("System.Double"));
            dt.Columns.Add("状态", Type.GetType("System.String"));
            string str = DateTime.Now.ToString("yyyyMMdd");

            lock (myData)
            {
                for (int i = start; i <= end; i++)
                {
                    optionDataFormat data = myData[i];
                    dt.Rows.Add(new object[] { data.code, str, data.time, data.last, data.ask[0], data.ask[1], data.ask[2], data.ask[3], data.ask[4], data.askv[0], data.askv[1], data.askv[2], data.askv[3], data.askv[4], data.bid[0], data.bid[1], data.bid[2], data.bid[3], data.bid[4], data.bidv[0], data.bidv[1], data.bidv[2], data.bidv[3], data.bidv[4], data.high, data.low, data.volume, data.turnover, data.openInterest, data.count, data.status });
                }
            }
            CsvApplication.SaveCSV(dt, "optiondata_" + str + ".csv", "append");
        }
コード例 #3
0
        /// <summary>
        /// 将交易日信息存入CSV文件。
        /// </summary>
        private void SaveTradeDaysDataByCSV(string CSVName)
        {
            DataTable tradeDaysData = new DataTable();

            tradeDaysData.Columns.Add("tradedays", typeof(int));
            foreach (int date in tradeDaysOfDataBase)
            {
                DataRow r = tradeDaysData.NewRow();
                r["tradedays"] = date;
                tradeDaysData.Rows.Add(r);
            }
            CsvApplication.SaveCSV(tradeDaysData, CSVName);
        }
コード例 #4
0
        private void findChance()
        {
            DataTable dt = CsvApplication.OpenCSV("20160706.csv");

            for (int i = 0; i < dt.Rows.Count; i++)
            {
                //模拟实时的行情
                dataFormat data0 = new dataFormat();
                data0.code = (string)dt.Rows[i]["代码"];
                if (data0.code == "代码")
                {
                    continue;
                }
                string[] str  = data0.code.Split('.');
                int      code = str[0][0] == 'I'?0:Convert.ToInt32(str[0]);
                if (OptionInformation.myOptionList.ContainsKey(code) && optionList.ContainsKey(data0.code) == false)
                {
                    optionList.Add(data0.code, OptionInformation.myOptionList[code]);
                }

                data0.date         = Convert.ToInt64(dt.Rows[i]["日期"]);
                data0.time         = Convert.ToInt64(dt.Rows[i]["时间"]);
                data0.ask          = new double[5];
                data0.ask[0]       = Convert.ToDouble(dt.Rows[i]["Ask1"]) / 10000.0;
                data0.ask[1]       = Convert.ToDouble(dt.Rows[i]["Ask2"]) / 10000.0;
                data0.ask[2]       = Convert.ToDouble(dt.Rows[i]["Ask3"]) / 10000.0;
                data0.ask[3]       = Convert.ToDouble(dt.Rows[i]["Ask4"]) / 10000.0;
                data0.ask[4]       = Convert.ToDouble(dt.Rows[i]["Ask5"]) / 10000.0;
                data0.askv         = new double[5];
                data0.askv[0]      = Convert.ToDouble(dt.Rows[i]["Askv1"]) / 10000.0;
                data0.askv[1]      = Convert.ToDouble(dt.Rows[i]["Askv2"]) / 10000.0;
                data0.askv[2]      = Convert.ToDouble(dt.Rows[i]["Askv3"]) / 10000.0;
                data0.askv[3]      = Convert.ToDouble(dt.Rows[i]["Askv4"]) / 10000.0;
                data0.askv[4]      = Convert.ToDouble(dt.Rows[i]["Askv5"]) / 10000.0;
                data0.bid          = new double[5];
                data0.bid[0]       = Convert.ToDouble(dt.Rows[i]["Bid1"]) / 10000.0;
                data0.bid[1]       = Convert.ToDouble(dt.Rows[i]["Bid2"]) / 10000.0;
                data0.bid[2]       = Convert.ToDouble(dt.Rows[i]["Bid3"]) / 10000.0;
                data0.bid[3]       = Convert.ToDouble(dt.Rows[i]["Bid4"]) / 10000.0;
                data0.bid[4]       = Convert.ToDouble(dt.Rows[i]["Bid5"]) / 10000.0;
                data0.bidv         = new double[5];
                data0.bidv[0]      = Convert.ToDouble(dt.Rows[i]["Bidv1"]) / 10000.0;
                data0.bidv[1]      = Convert.ToDouble(dt.Rows[i]["Bidv2"]) / 10000.0;
                data0.bidv[2]      = Convert.ToDouble(dt.Rows[i]["Bidv3"]) / 10000.0;
                data0.bidv[3]      = Convert.ToDouble(dt.Rows[i]["Bidv4"]) / 10000.0;
                data0.bidv[4]      = Convert.ToDouble(dt.Rows[i]["Bidv5"]) / 10000.0;
                data0.high         = Convert.ToDecimal(dt.Rows[i]["high"]) / 10000;
                data0.low          = Convert.ToDecimal(dt.Rows[i]["low"]) / 10000;
                data0.last         = Convert.ToDecimal(dt.Rows[i]["成交价"]) / 10000;
                data0.openInterest = Convert.ToDecimal(dt.Rows[i]["持仓量"]) / 10000;
                data0.status       = (string)dt.Rows[i]["状态"];
                data0.turnover     = Convert.ToDecimal(dt.Rows[i]["成交额"]);
                data0.volume       = Convert.ToDecimal(dt.Rows[i]["成交量"]);
                if (marketInformation.ContainsKey(data0.code))
                {
                    marketInformation[data0.code] = data0;
                }
                else
                {
                    marketInformation.Add(data0.code, data0);
                }
            }
        }