Ejemplo n.º 1
0
        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();
        }
Ejemplo n.º 2
0
        private string DividendDataImport(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 dividenddataservice = new ImportDividendDataService(domainservice);
            var stockservice = new ImportStockService();
            var dividenddataservice = new ImportDividendDataService();

            messages.Add(string.Format("\t处理数据:{0}", 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 = dividenddataservice.GetLatestDividendDataImportDateTime(symbol);
            messages.Add(string.Format("\t\t获取最新记录的时间:{0}", starttime));
            importmessage = string.Format("股票代码:{0};最新记录的时间:{1}", symbol, starttime);

            messages.Add("\t\t获取待导入数据");
            var originaldata = _dataReader.GetDividendData(symbol, starttime);
            if (originaldata == null || originaldata.Items.Count == 0)
            {
                messages.Add("\t\t无数据需要导入");
                LogDividendInfoBatch(messages);
                return importmessage;
            }

            messages.Add(string.Format("\t\t开始导入除权数据{0}条", originaldata.Items.Count));
            dividenddataservice.ImportDividendData(originaldata.Items.Select(item => DataUtil.CopyFrom(item, stock)));
            messages.Add(string.Format("\t\t完成导入除权数据:{0}", symbol));

            LogDividendInfoBatch(messages);
            return importmessage;
        }