public string StockSync() { StringBuilder returnStr = new StringBuilder(); //获取股票Domain服务 var stockservice = new ImportStockService(); var dailypriceservice = new ImportDailyPriceDataService(); //获取股票对象 var stock = stockservice.GetStockBySymbol(m_StockCode); if (stock == null) { //创建股票对象 stock = new Stock { Symbol = m_StockCode, Name = string.Empty }; stockservice.ImportStock(stock); } //获取股票日线最新记录时间 var starttime = dailypriceservice.GetLatestDailyPriceDataImportDateTime(m_StockCode); //创建雅虎财经实例,并获取数据库未记录的历史数据 IEnumerable<DailyPriceDataItem> dayItemList; YahooFinance yahoo = new YahooFinance(stock); yahoo.Suffix = Suffix; if (starttime < new DateTime(1990, 12, 1)) { dayItemList = yahoo.GetDayLineHistory(); } else { dayItemList = yahoo.GetDayLineHistory(starttime.AddDays(1), DateTime.Now); } if (dayItemList == null) { returnStr.Append(string.Format("获取雅虎财经:{0}{1}失败,没有新数据或网络异常!\n", m_StockCode, Suffix)); return returnStr.ToString(); } //插入最新的日线数据 if (dayItemList.Count() > 0) { dailypriceservice.ImportPriceData(dayItemList); returnStr.Append(string.Format("股票:{0}{1}插入{2}条日线数据。\n", m_StockCode, Suffix, dayItemList.Count())); } //如果今天是星期六,则获取股票基础面信息 if (DateTime.Now.DayOfWeek == DayOfWeek.Monday) { Eastmoney eastMoney = new Eastmoney(Suffix, m_StockCode); eastMoney.RefreshStockBase(); } return returnStr.ToString(); }
private string DayLineDataImport(object state) { var importmessage = string.Empty; if (_tokenSource.IsCancellationRequested) { return importmessage; } var symbol = (string)state; var messages = new List<string>(); //var domainservice = CreateDomainService(); //var stockservice = new ImportStockService(domainservice); //var dailypriceservice = new ImportDailyPriceDataService(domainservice); var stockservice = new ImportStockService(); var dailypriceservice = new ImportDailyPriceDataService(); messages.Add(string.Format("\t解析文件:{0}.day", symbol)); var stock = stockservice.GetStockBySymbol(symbol); if (stock == null) { messages.Add("\t\t开始创建股票对象"); stock = new Stock { Symbol = symbol, Name = string.Empty }; stockservice.ImportStock(stock); messages.Add("\t\t完成创建股票对象"); } var starttime = dailypriceservice.GetLatestDailyPriceDataImportDateTime(symbol); messages.Add(string.Format("\t\t获取最新记录的时间:{0}", starttime)); importmessage = string.Format("股票代码:{0};最新记录的时间:{1}", symbol, starttime); messages.Add("\t\t获取待导入数据"); var originaldata = _dataReader.GetDaylineData(symbol, starttime); if (originaldata == null || originaldata.Items.Count == 0) { messages.Add("\t\t无数据需要导入"); LogDayLineInfoBatch(messages); return importmessage; } messages.Add(string.Format("\t\t开始导入日线数据{0}条", originaldata.Items.Count)); dailypriceservice.ImportPriceData(originaldata.Items.Select(item => DataUtil.CopyFrom(item, stock))); messages.Add(string.Format("\t\t完成导入日线数据:{0}", symbol)); LogDayLineInfoBatch(messages); return importmessage; }