Exemple #1
0
 static App()
 {
     Dist.Setup();
     SyncStrategy();
     InstallAutoSolutionSetting();
     ReadSolutionSetting();
     ReadDateRangeSetting();
     asset_.readAssetFromDB();
 }
Exemple #2
0
 static DB()
 {
     RegConn(Dist.GlobalDBFile(), "$g");
 }
Exemple #3
0
        public bool start()
        {
            if (Utils.GetSysInfo(DB.Global(), "SucRunStartScriptDate", "0") != Utils.NowDate().ToString())
            {
                if (!App.RunScript("start"))
                {
                    return(false);
                }
            }

            readTradeDate();
            Dist.PrepareRuntimePath();
            readStocks();
            if (stockDict_.Count == 0)
            {
                return(false);
            }
            int nFinishCount = 0;
            int nTotalCount  = stockList_.Count + 1;

            App.host_.uiStartProcessBar();
            Dictionary <String, List <AdjFactor> > stockFactorDict = new Dictionary <string, List <AdjFactor> >();
            DataTable dtFactor = DB.Global().Select("Select * From AdjFactor Order by trade_date");

            foreach (DataRow row in dtFactor.Rows)
            {
                String    code      = row["code"].ToString();
                AdjFactor adjFactor = new AdjFactor();
                adjFactor.date_   = Utils.ToType <int>(row["trade_date"]);
                adjFactor.factor_ = Utils.ToType <float>(row["adj_factor"]);
                List <AdjFactor> factors;
                if (stockFactorDict.TryGetValue(code, out factors))
                {
                    factors.Add(adjFactor);
                }
                else
                {
                    factors = new List <AdjFactor>();
                    factors.Add(adjFactor);
                    stockFactorDict[code] = factors;
                }
            }
            AdjFactor dummyFactor = new AdjFactor();

            dummyFactor.date_   = Utils.Date(DateTime.Now.AddYears(2));
            dummyFactor.factor_ = 1;
            foreach (var kv in stockFactorDict)
            {
                float newestFactor = kv.Value[kv.Value.Count - 1].factor_;
                kv.Value[kv.Value.Count - 1].factor_ = 1;
                for (int i = kv.Value.Count - 2; i >= 0; i--)
                {
                    kv.Value[i].factor_ = kv.Value[i].factor_ / newestFactor;
                }
                kv.Value.Add(dummyFactor);
            }

            foreach (Stock sk in stockList_)
            {
                List <AdjFactor> factors = null;
                stockFactorDict.TryGetValue(sk.code_, out factors);
                readDayData(sk, factors);
                readRuntimeData(sk);
                ++nFinishCount;
                App.host_.uiSetProcessBar(String.Format("已完成读入{0}({1}/{2})", sk.code_, nFinishCount, nTotalCount), nFinishCount * 100 / nTotalCount);
            }
            readSZZSData();
            readSZZSRuntimeData();
            int lastTrayDay = Utils.LastTradeDay();
            int iNewestLastTrayDayIndex;

            if (Utils.NowIsTradeDay())
            {
                iNewestLastTrayDayIndex = 1;
            }
            else
            {
                iNewestLastTrayDayIndex = 0;
            }
            bool bSZZSHasFullHistory  = szListData_[iNewestLastTrayDayIndex].date_ == lastTrayDay;
            bool bStockHasFullHistory = false;

            foreach (var sk in stockList_)
            {
                if (sk.dataList_[iNewestLastTrayDayIndex].date_ == lastTrayDay)
                {
                    bStockHasFullHistory = true;
                    break;
                }
            }
            if (bSZZSHasFullHistory && bStockHasFullHistory)
            {
                Utils.SetSysInfo(DB.Global(), "SucRunStartScriptDate", Utils.NowDate().ToString());
            }
            else
            {
                if (Utils.NowIsTradeDay())
                {
                    App.host_.uiMessageBox("The history is not full!", MessageBoxButtons.OK);
                }
            }

            App.host_.uiFinishProcessBar();
            return(true);
        }