Exemplo n.º 1
0
 /// <summary>
 /// 核心存储函数。根据市场信息等存储商品期货数据。
 /// </summary>
 public void StoreData()
 {
     foreach (var bond in bondList)
     {
         string tableName     = "MarketData_" + bond.code + "_" + bond.market + "E";
         int    maxRecordDate = 0;
         foreach (int today in myTradeDays.myTradeDays)
         {
             if (today > bond.endDate)
             //如果在期货交割之后,不再进行记录
             {
                 break;
             }
             int    yesterday     = TradeDays.GetPreviousTradeDay(today);
             string todayDataBase = "TradeMarket" + (today / 100).ToString();
             //string todayConnectString = "server=(local);database=" + todayDataBase + ";Integrated Security=true;";
             //string todayConnectString = "server=192.168.38.217;database=" + todayDataBase + ";uid =sa;pwd=maoheng0;";
             string todayConnectString = "server=145.146.30.152;database=" + todayDataBase + ";uid =spqhhqld;pwd=spqhhqld;";
             if (SqlApplication.CheckDataBaseExist(todayDataBase, orignalConnectString) == false)
             {
                 maxRecordDate = 0;
             }
             else if (yesterday / 100 != today / 100 || today == startDate || maxRecordDate == 0)
             {
                 if (SqlApplication.CheckExist(todayDataBase, tableName, todayConnectString) == true)
                 {
                     maxRecordDate = MaxRecordDate(tableName, todayConnectString);
                 }
             }
             if (maxRecordDate < today)
             //若没有记录数据,需要重新记录
             //若数据存在,存储数据,否则需要跳过
             {
                 TDBReqFuture  reqFuture = new TDBReqFuture(bond.contractName, today, today);
                 TDBFutureAB[] futureABArr;
                 TDBErrNo      nErrInner = tdbSource.GetFutureAB(reqFuture, out futureABArr);
                 if (futureABArr.Length == 0)
                 {
                     continue;
                 }
                 //string yesterdayDataBase = "TradeMarket" + (yesterday / 100).ToString();
                 //string yesterdayConnectString = "server=(local);database=" + yesterdayDataBase + ";Integrated Security=true;";
                 //string yesterdayConnectString = "server=192.168.38.217;database=" + yesterdayDataBase + ";uid =sa;pwd=maoheng0;";Security=true;";
                 if (SqlApplication.CheckDataBaseExist(todayDataBase, orignalConnectString) == false)
                 //检测当日对应的数据库是否存在
                 {
                     CreateDataBase(todayDataBase, orignalConnectString);
                 }
                 if (SqlApplication.CheckExist(todayDataBase, tableName, orignalConnectString) == false)
                 {
                     CreateTable(tableName, todayConnectString);
                 }
                 //if (yesterdayDataBase != todayDataBase)
                 ////如果前一交易日所在月份和当日不同,检测上一个月的数据库是否存在
                 //{
                 //    if (SqlApplication.CheckDataBaseExist(yesterdayDataBase, orignalConnectString) == false)
                 //    {
                 //        CreateDataBase(yesterdayDataBase, orignalConnectString);
                 //    }
                 //    if (SqlApplication.CheckExist(yesterdayDataBase, tableName, orignalConnectString) == false)
                 //    {
                 //        CreateTable(tableName, yesterdayConnectString);
                 //    }
                 //}
                 //判断数据是否已经存储,若数据存在,默认已经记录,仅记录数据条数,写入日志文档,靠人工来校对
                 // int alreadyRecord = CountRecordNumber(tableName, todayConnectString, today);
                 bondShot[] dataList;
                 dataList = ModifyData(futureABArr, bond.contractName, today);
                 StoreDataDaily(tableName, todayConnectString, dataList);
                 Console.WriteLine("Date:{0}, table:{1}, MaxRecordDate:{2}, Wind:{3}", today, tableName, maxRecordDate, futureABArr.Length);
                 string log = "Date:" + today.ToString() + ", table:" + tableName + ", MaxRecordDate:" + maxRecordDate.ToString() + ", Wind:" + futureABArr.Length.ToString();
                 MyApplication.TxtWrite(logName, log);
                 maxRecordDate = today;
             }
             else
             {
                 Console.WriteLine("Date:{0}, table:{1}, MaxRecordDate:{2}", today, tableName, maxRecordDate);
                 string log = "Date:" + today.ToString() + ", table:" + tableName + ", MaxRecordDate:" + maxRecordDate.ToString();
                 MyApplication.TxtWrite(logName, log);
             }
         }
     }
 }
Exemplo n.º 2
0
        /// <summary>
        /// 核心存储函数。根据市场信息等存储股票数据。
        /// </summary>
        public void StoreData()
        {
            foreach (var stock in stockList)
            {
                string tableName     = "MarketData_" + stock.code + "_" + stock.market;
                int    maxRecordDate = 0;
                foreach (int today in myTradeDays.myTradeDays)
                {
                    int    yesterday     = TradeDays.GetPreviousTradeDay(today);
                    string todayDataBase = "TradeMarket" + (today / 100).ToString();
                    //string todayConnectString = "server=192.168.38.217;database=" + todayDataBase + ";uid =sa;pwd=maoheng0;";
                    //string todayConnectString = "server=(local);database=" + todayDataBase + ";Integrated Security=true;";
                    string todayConnectString = "server=192.168.38.209;database=" + todayDataBase + ";uid =sa;pwd=280514;";
                    if (SqlApplication.CheckDataBaseExist(todayDataBase, orignalConnectString) == false)
                    {
                        maxRecordDate = 0;
                    }
                    if (yesterday / 100 != today / 100 || today == startDate || maxRecordDate == 0)
                    {
                        if (SqlApplication.CheckDataBaseExist(todayDataBase, orignalConnectString) == true && SqlApplication.CheckExist(todayDataBase, tableName, orignalConnectString) == true && SqlApplication.CheckExist(todayDataBase, tableName, todayConnectString) == true)
                        {
                            maxRecordDate = MaxRecordDate(tableName, todayConnectString);
                        }
                    }
                    if (maxRecordDate < today)
                    //若没有记录数据,需要重新记录
                    //若数据存在,存储数据,否则需要跳过
                    {
                        TDBReq      reqTick = new TDBReq(stock.code + "." + stock.market, today, today);
                        TDBTickAB[] tickArr;
                        TDBErrNo    nErrInner = tdbSource.GetTickAB(reqTick, out tickArr);
                        if (tickArr.Length == 0)
                        {
                            continue;
                        }
                        if (SqlApplication.CheckDataBaseExist(todayDataBase, orignalConnectString) == false)
                        //检测当日对应的数据库是否存在
                        {
                            CreateDataBase(todayDataBase, orignalConnectString);
                        }
                        if (SqlApplication.CheckExist(todayDataBase, tableName, orignalConnectString) == false)
                        {
                            CreateTable(tableName, todayConnectString);
                        }

                        //判断数据是否已经存储,若数据存在,默认已经记录,仅记录数据条数,写入日志文档,靠人工来校对
                        // int alreadyRecord = CountRecordNumber(tableName, todayConnectString, today);
                        stockShot[] dataList = ModifyData(tickArr, stock.code, today);
                        StoreDataDaily(tableName, todayConnectString, dataList);
                        Console.WriteLine("Date:{0}, table:{1}, MaxRecordDate:{2}, Wind:{3}", today, tableName, maxRecordDate, tickArr.Length);
                        string log = "Date:" + today.ToString() + ", table:" + tableName + ", MaxRecordDate:" + maxRecordDate.ToString() + ", Wind:" + tickArr.Length.ToString();
                        MyApplication.TxtWrite(logName, log);
                        maxRecordDate = today;
                    }
                    else
                    {
                        Console.WriteLine("Date:{0}, table:{1}, MaxRecordDate:{2}", today, tableName, maxRecordDate);
                        string log = "Date:" + today.ToString() + ", table:" + tableName + ", MaxRecordDate:" + maxRecordDate.ToString();
                        MyApplication.TxtWrite(logName, log);
                    }
                }
            }
        }