public void GetRecentHistoryTest() { //Setup control variables for verification var privateStockHistory = new PrivateObject(new StockData(), new PrivateType(typeof(StockData))); var entireHistory = privateStockHistory.Invoke("GetFullHistory") as MarketSegment; var firstDay = entireHistory[0]; var secondDay = entireHistory[1]; var thirdDay = entireHistory[2]; var lastDay = entireHistory[entireHistory.Count - 1]; //Reset StockData to day 0 StockData.Init(); //Current day zero, recentHistory should rollover. var recentHist = StockData.GetRecentHistory(2); Assert.AreEqual(lastDay, recentHist[0]); Assert.AreEqual(firstDay, recentHist[1]); //Current day 1, still a recentHistory rollover StockData.AdvanceDay(); recentHist = StockData.GetRecentHistory(3); Assert.AreEqual(lastDay, recentHist[0]); Assert.AreEqual(firstDay, recentHist[1]); Assert.AreEqual(secondDay, recentHist[2]); //Current day 2, no more recentHistory rollover StockData.AdvanceDay(); recentHist = StockData.GetRecentHistory(3); Assert.AreEqual(firstDay, recentHist[0]); Assert.AreEqual(secondDay, recentHist[1]); Assert.AreEqual(thirdDay, recentHist[2]); }
static void Main(string[] args) { Log.Debug($"{nameof(Main)} (enter)"); SignatureService.LoadPrivateKey("Team1/StockServer"); StockData.Init(); ConversationManager.Start(ConversationBuilder); ComService.AddUdpClient(Config.DEFAULT_UDP_CLIENT, Config.GetInt(Config.STOCK_SERVER_PORT)); ComService.AddTcpListener(Config.DEFAULT_TCP_CLIENT, Config.GetInt(Config.STOCK_SERVER_TCP_PORT)); Log.Info("Starting simulation."); Task.Run(() => RunSimulation()); Log.Info("Waiting for StockStreamRequestMessages."); Log.Info("Pres any key to close program."); Console.ReadKey(); lock (RunSimLock) { IsSimRunning = false; } Log.Debug($"{nameof(Main)} (exit)"); }
public void LoadDataTest() { StockData.Init(); var marketDay = StockData.GetCurrentDay(); var numDays = StockData.GetSize(); var numCompanies = marketDay.TradedCompanies.Count; for (int i = 0; i < numDays; i++) { Assert.AreEqual("Apple Inc.", marketDay.TradedCompanies[1].Name); Assert.AreEqual("AAPL", marketDay.TradedCompanies[1].Symbol); Assert.AreEqual("Amazon.com Inc", marketDay.TradedCompanies[2].Name); Assert.AreEqual("AMZN", marketDay.TradedCompanies[2].Symbol); Assert.AreEqual(numCompanies, marketDay.TradedCompanies.Count); marketDay = StockData.AdvanceDay(); } }
//同步股票数据 //2018-03-14 Reviewed private void SyncData() { //更新进度 int statusNum = 0; //删除已有股票 StockSQL.DeleteStock(); this.btn_syncData.Enabled = false; foreach (object obj in filelist) { statusNum++; string filename = (string)obj; StockData stock = new StockData(); stock.Init(filename); UtilLog.AddInfo(TAG, "Start to analyse " + stock.code + ";"); StockAttribute attri = new StockAttribute(stock); StockKPI kpi = new StockKPI(stock); if (!stock.IsValid()) { UtilLog.AddInfo(TAG, statusNum + "/" + filelist.Count + " " + stock.code + " skipped"); } else { attri.InitAttribute(); kpi.InitKPI(); StockSQL.InsertStockWithItem(stock); UtilLog.AddInfo(TAG, statusNum + "/" + filelist.Count + " " + stock.code + " initialization finished"); } int status = statusNum * 100 / filelist.Count; if (statusNum % 100 == 0) { GC.Collect(); } prog.SetProgress(status); } StockData.SetStockFull(); StockDapan.InsertStockDaPan(); this.btn_syncData.Enabled = true; }
public void AdvanceDayTest() { StockData.Init(); Assert.AreEqual(StockData.CurrentDayNumber, 0); StockData.AdvanceDay(); Assert.AreEqual(StockData.CurrentDayNumber, 1); StockData.AdvanceDay(); Assert.AreEqual(StockData.CurrentDayNumber, 2); StockData.Init(); Assert.AreEqual(StockData.CurrentDayNumber, 0); //ensure proper rollover for (int i = 0; i < StockData.GetSize() - 1; i++) { StockData.AdvanceDay(); } Assert.AreEqual(StockData.GetSize() - 1, StockData.CurrentDayNumber); StockData.AdvanceDay(); Assert.AreEqual(0, StockData.CurrentDayNumber); }