示例#1
0
        /// <inheritdoc />
        protected override async Task RunExclusive()
        {
            var ts = DateTime.Now;

            if (ts.DayOfWeek == DayOfWeek.Saturday || ts.DayOfWeek == DayOfWeek.Sunday)
            {
                // 周六周日不开市
                return;
            }

            if (ts.TimeOfDay < new TimeSpan(9, 30, 0) ||
                ts.TimeOfDay > new TimeSpan(15, 0, 0))
            {
                // 股市未开市
                return;
            }

            var stocksList = await StockInfoProvider.GetRealtimeStocksList();

            _logger.LogInformation("获取股票实时价格列表完成。共获取到 {0} 条数据。", stocksList.Count);

            // 将新获取的数据加入到 HBase 中
            var hbaseRows = stocksList.Select(item => GetRow(item, ts));
            await HBaseClientFactory.Create().Add(RealtimeDataHBaseTableName, hbaseRows);

            _logger.LogTrace("准备通知预测节点数据更新");

            // 通知预测节点
            await _predictorNotifier.Notify();
        }
示例#2
0
        /// <inheritdoc />
        protected override async Task RunExclusive()
        {
            var ts = DateTime.Now;

            if (ts.TimeOfDay < new TimeSpan(15, 0, 0) ||
                ts.TimeOfDay > new TimeSpan(16, 0, 0))
            {
                // 15:00 - 16:00 以外时间不执行
                return;
            }

            if (ts.DayOfWeek == DayOfWeek.Saturday || ts.DayOfWeek == DayOfWeek.Sunday)
            {
                // 周六周日不执行
                return;
            }

            // 获取所有的股票代码
            var stocksList = await StockInfoProvider.GetRealtimeStocksList();

            _logger.LogInformation("获取所有股票代码完毕。一共获取到 {0} 支股票代码。", stocksList.Count);

            // 爬取所有股票的日统计数据
            var stockInfosList = new List <StockDailyStatisticsInfo>();

            foreach (var stockCode in stocksList.Select(stock => stock.Code))
            {
                var stockStatList = await StockInfoProvider.GetDailyStatisticsInfo(stockCode, ts.Date, ts.Date);

                var stockStat = stockStatList.FirstOrDefault();
                if (stockStat != null)
                {
                    stockInfosList.Add(stockStat);
                }
            }

            // 将爬取到的日统计数据写入 HBase
            var rows = stockInfosList.Select(item => GetRow(item, ts));
            await HBaseClientFactory.Create().Add(DailyDataHBaseTableName, rows);

            _logger.LogTrace("准备通知预测节点数据更新");

            // 通知预测节点
            await _predictorNotifier.Notify();
        }