public void Send(IMessageSender sender) { this.Log().Info("清空数据"); ClearRecormend(); var groups = new string[] { "tencent", "market" }; foreach (var group in groups) { this.Log().Info("推荐" + group + "股票"); IList <data.stockcategory> cateList = cateService.GetCategoryList(group); IList <data.indexdefinition> indexList = indexService.FindAll().Where(p => p.state == 1).ToList(); foreach (var cate in cateList) { foreach (var index in indexList) { RecoCateStock msg = new RecoCateStock { CateCode = cate.code, CateName = cate.name, IndexCode = index.code, IndexName = index.name }; sender.Send(JsonConvert.SerializeObject(msg)); } } } }
public void Execute(IJobExecutionContext context) { LoggingExtensions.Logging.Log.InitializeWith <LoggingExtensions.log4net.Log4NetLog>(); //获取分类 IList <data.stockcategory> cateList; if (string.IsNullOrEmpty(this.CategoryCode) || this.CategoryCode == "-1") { cateList = cateService.GetCategoryList("tencent"); } else { string[] cates = this.CategoryCode.Split(','); cateList = cateService.GetCategoryList("tencent").Where(p => cates.Contains(p.code)).ToList(); } int total = 0; foreach (var category in cateList) { this.Log().Info(string.Format("行业指数日线开始,行业:{0}", category.name)); //获取分类,某个周期,所有股票的价格 try { InitCategoryIndexByDay(category.code); } catch (Exception ex) { this.Log().Info(string.Format("异常:{0},堆栈:{1}", ex.Message, ex.StackTrace)); } this.Log().Info(string.Format("行业指数周线开始,行业:{0}", category.name)); try { InitCategoryIndexByWeek(category.code); } catch (Exception ex) { this.Log().Info(string.Format("异常:{0},堆栈:{1}", ex.Message, ex.StackTrace)); } this.Log().Info(string.Format("行业指数月线开始,行业:{0}", category.name)); try { InitCategoryIndexByMonth(category.code); } catch (Exception ex) { this.Log().Info(string.Format("异常:{0},堆栈:{1}", ex.Message, ex.StackTrace)); } } }
public void Execute(IJobExecutionContext context) { IList <data.StockCategory> cateList = cateService.GetCategoryList("tencent"); foreach (var category in cateList) { IList <data.Stock> stockList = stockService.GetStockByCategory(category.code); for (int i = 0; i < stockList.Count; i += batchNum) { IList <data.StockInfo> spList = sync.GetPrice(stockList.Skip(i).Take(batchNum).ToList()); IList <data.PriceInfo> spiList = spList.Select(p => new data.PriceInfo { code = p.stock_code, date = p.date, high = p.high, low = p.low, open = p.open, percent = p.percent, price = p.price, updown = p.updown, volume = p.volume, yestclose = p.yestclose }).ToList(); stockService.AddPriceByDay(spiList); stockService.AddPriceByWeek(spiList); stockService.AddPriceByMonth(spiList); } } }
private void ComputeCategoryCount(string group) { IList <data.stockcategory> cateList = null; IList <data.indexdefinition> indexList = indexService.FindAll().Where(p => p.state == 1).ToList(); if (string.IsNullOrEmpty(this.CategoryCode) || this.CategoryCode == "-1") { cateList = cateService.GetCategoryList(group); } else { string[] cates = this.CategoryCode.Split(','); cateList = cateService.GetCategoryList(group).Where(p => cates.Contains(p.code)).ToList();; } using (var entity = new StockManDBEntities()) { cateList.Each(p => { indexList.Each(i => { this.Log().Info("推荐行业:" + p.name + ",技术" + i.name); var count = entity.reco_stock_category_index.Count(s => s.cate_code == p.code && s.index_code == i.code); var code = p.code + "_" + i.code; var rcc = entity.reco_category_count.FirstOrDefault(s => s.code == code); if (rcc == null) { entity.reco_category_count.Add(new data.reco_category_count { code = code, cate_code = p.code, cate_type = group, index_code = i.code, count = count }); } else { rcc.count = count; } }); entity.SaveChanges(); }); } }
public void Execute(IJobExecutionContext context) { LoggingExtensions.Logging.Log.InitializeWith <LoggingExtensions.log4net.Log4NetLog>(); this.Log().Info("开始更新缓存数据"); //大盘 if (this.Category == "3" || this.Category == "-1") { this.Log().Info("开始大盘缓存数据"); var objList = objectService.FindAll(); foreach (var obj in objList) { this.Log().Info("更新:" + obj.name); UpdateCacheData(ObjectType.Object, obj.code); } this.Log().Info("结束大盘缓存数据"); } //个股 if (this.Category == "1" || this.Category == "-1") { this.Log().Info("开始更新个股数据"); //var stockList = stockService.FindAll(); IList <data.stockcategory> cateList1 = cateService.GetCategoryList("tencent").ToList(); int total = 0; foreach (var category in cateList1) { IList <data.stock> stockList = stockService.GetStockByCategory(category.code); foreach (var stock in stockList) { this.Log().Info("更新:" + stock.name); UpdateCacheData(ObjectType.Stock, stock.code); } this.Log().Info("结束更新个股数据"); } } //行业 if (this.Category == "2" || this.Category == "-1") { this.Log().Info("开始更新行业数据"); var cateList = cateService.FindAll(); foreach (var cate in cateList) { this.Log().Info("更新:" + cate.name); UpdateCacheData(ObjectType.Category, cate.code); } this.Log().Info("结束更新行业数据"); } this.Log().Info("更新缓存数据结束!"); }
public void Execute(IJobExecutionContext context) { LoggingExtensions.Logging.Log.InitializeWith <LoggingExtensions.log4net.Log4NetLog>(); log = log4net.LogManager.GetLogger(this.GetType()).Log(); IList <data.stockcategory> cateList = null; if (string.IsNullOrEmpty(this.CategoryCode) || this.CategoryCode == "-1") { cateList = cateService.GetCategoryList("tencent"); } else { string[] cates = this.CategoryCode.Split(','); cateList = cateService.GetCategoryList("tencent").Where(p => cates.Contains(p.code)).ToList(); } foreach (var category in cateList) { IList <data.stock> stockList = stockService.GetStockByCategory(category.code); if (StartDate.ToString("yyyyMMdd") == DateTime.Now.ToString("yyyyMMdd")) { log.Info(string.Format("导入今天日线数据,分类:{1}:从日期{0}", StartDate.ToString("yyyy-MM-dd"), category.name)); ImportTodayPrice(stockList); } else { foreach (var stock in stockList) { log.Info(string.Format("导入日线开始,股票:{1}:从日期{0}", StartDate.ToString("yyyy-MM-dd"), stock.name)); ImportDay(stock, StartDate); log.Info(string.Format("导入周线开始,股票:{1}:从日期{0}", StartDate.ToString("yyyy-MM-dd"), stock.name)); ImportWeek(stock, StartDate); log.Info(string.Format("导入月线开始,股票:{1}:从日期{0}", StartDate.ToString("yyyy-MM-dd"), stock.name)); ImportMonth(stock, StartDate); log.Info(string.Format("导入结束,股票:{1}:从日期{0}", StartDate.ToString("yyyy-MM-dd"), stock.name)); } } } }
public void Execute(IJobExecutionContext context) { this.batch = Guid.NewGuid(); //获取分类 IList <data.stockcategory> cateList = null; if (string.IsNullOrEmpty(this.CategoryCode) || this.CategoryCode == "-1") { cateList = cateService.GetCategoryList("tencent"); } else { string[] cates = this.CategoryCode.Split(','); cateList = cateService.GetCategoryList("tencent").Where(p => cates.Contains(p.code)).ToList(); } int total = 0; foreach (var category in cateList) { this.Log().Info("开始导入行业:" + category.code + "-" + category.name); IList <data.stock> stockList = stockService.GetStockByCategory(category.code); foreach (data.stock stock in stockList) { Thread.Sleep(50); ImportDay(stock); ImportWeek(stock); ImportMonth(stock); } this.Log().Info("结束导入行业:" + category.code + "-" + category.name); } //处理失败的记录 ReImport(); }
/// <summary> /// 获取股票分类(行业) /// </summary> /// <param name="id"></param> /// <returns></returns> public IList <StockCategory> GetCategoryList(string id) { var list = categoryService.GetCategoryList(id); var l = list.Select(p => new StockMan.Facade.Models.StockCategory { code = p.code, group_code = p.group_code, name = p.name, price = 10, yestclose = 13 }); return(l.ToList()); }
public void Send(IMessageSender sender) { this.Log().Info("消息发送开始"); //获取行业列表 IList <data.stockcategory> list = cateService.GetCategoryList("tencent"); foreach (var item in list) { var task1 = new CatePriceUpdate { Code = item.code }; sender.Send(JsonConvert.SerializeObject(task1)); } this.Log().Info("消息发送开始"); }
/// <summary> /// 获取自定义指数(行业) /// </summary> /// <param name="id">分类,2,行业,3大盘,4其他</param> /// <returns></returns> public IList <CustomObject> GetObjectList(string id) { switch (id) { case "2": //行业 return(categoryService.GetCategoryList("tencent").Select(p => new StockMan.Facade.Models.CustomObject { code = p.code, type = id, name = p.name, price = 0, yestclose = 0, sort = 1, }).ToList()); case "4": //关联数据 return(relateService.FindAll().Select(p => new StockMan.Facade.Models.CustomObject { code = p.code, type = id, name = p.name, price = 0, yestclose = 0, sort = 2 }).ToList()); default: var list = objectService.GetObjectList(id); var l = list.Select(p => new StockMan.Facade.Models.CustomObject { code = p.code, type = id, name = p.name, price = p.price, yestclose = p.yestclose, sort = 0 }); return(l.ToList()); } }
public void Execute(IJobExecutionContext context) { //获取分类 IList <data.stockcategory> cateList = cateService.GetCategoryList("tencent"); foreach (var category in cateList) { IList <data.stock> stockList = stockService.GetStockByCategory(category.code); for (int i = 0; i < stockList.Count; i += batchNum) { IList <data.StockInfo> spList = sync.GetPrice(stockList.Skip(i).Take(batchNum).ToList()); foreach (data.StockInfo price in spList) { //stockService.UpdateStockPrice(price.stock_code, price); this.Log().Info("更新价格:" + price.stock_code + "-" + price.name + "-" + price.price); } stockService.UpdateStockPrice(spList); } } //变量分类下的股票 }
private void RecoStateReverseStock(string group, string cycle) { IList <data.stockcategory> cateList = null; IList <data.indexdefinition> indexList = indexService.FindAll().Where(p => p.state == 1).ToList(); if (string.IsNullOrEmpty(this.CategoryCode) || this.CategoryCode == "-1") { cateList = cateService.GetCategoryList(group); } else { string[] cates = this.CategoryCode.Split(','); cateList = cateService.GetCategoryList(group).Where(p => cates.Contains(p.code)).ToList();; } //每个行业,每个技术,最多推荐5只股票。 cateList.Each(p => { this.Log().Info("推荐行业:" + p.name); string sql = string.Format(@"select distinct CONCAT(b.cate_code,'_',a.code,'_',c.index_code,'_','{1}') as code, a.code as object_code,a.name as object_name,a.price,a.yestclose,a.percent,a.pe, a.pb,a.mv,a.fv,b.cate_code as cate_code,d.name as cate_name,c.index_code,i.name as index_name,c.index_code as tag_code,i.name as tag_name, c.day,c.week,c.month,c.last_day,c.last_week,c.last_month,'{1}' as cycle from objectstate c left join stock a on a.code=c.object_code left join stock_category_map b on b.stock_code=a.code left join stockcategory d on b.cate_code=d.code inner join indexdefinition i on c.index_code=i.code where c.{1}='1' and c.last_{1}='-1' and c.month='1' and b.cate_code ='{0}' limit 5", p.code, cycle); using (var entity = new StockManDBEntities()) { var recos = entity.Database.SqlQuery <data.reco_stock_category_state>(sql).ToList(); recos.Each(reco => { this.Log().Info("推荐股票:" + reco.object_code + "_" + reco.object_name); if (entity.reco_stock_category_state.Any(x => x.code == reco.code)) { entity.Entry(reco).State = EntityState.Modified; } else { entity.reco_stock_category_state.Add(reco); } }); entity.SaveChanges(); } }); }
public void Execute(IJobExecutionContext context) { LoggingExtensions.Logging.Log.InitializeWith <LoggingExtensions.log4net.Log4NetLog>(); this.Log().Info("计算开始"); //获取行业列表 IList <data.stockcategory> list; if (string.IsNullOrEmpty(this.CategoryCode) || this.CategoryCode == "-1") { list = cateService.GetCategoryList("tencent"); } else { string[] cates = this.CategoryCode.Split(','); list = cateService.GetCategoryList("tencent").Where(p => cates.Contains(p.code)).ToList(); } //遍历列表,获取行业下的股票,计算指数,更新指数 IList <data.PriceInfo> priceInfoList = new List <data.PriceInfo>(); foreach (var item in list) { //IList<data.stock> stocks = stockService.GetStockByCategory(item.code); DateTime today = new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day); decimal yestclose = GetYestclose(item.code, today); //获取基期的值 int i = -1; bool isOk = false; decimal baseValue = 0; while (!isOk) { var priceList = stockService.GetStockPriceByDate(item.code, data.TechCycle.day, DateTime.Now.AddDays(i--)); if (priceList == null || priceList.Count == 0) { continue; } decimal total = 0, baseIndex = 100; foreach (var priceInfo in priceList) { total += priceInfo.price ?? 1 * priceInfo.volume ?? 1; } baseValue = (total * 100) / yestclose; isOk = true; } //index = (total / baseValue) * 100; var priceList0 = stockService.GetStockPriceByDate(item.code, data.TechCycle.day, today); decimal vol = 0, turnover = 0; decimal total1 = 0; foreach (var priceInfo in priceList0) { total1 += priceInfo.price ?? 1 * priceInfo.volume ?? 1; vol += priceInfo.volume ?? 1; turnover += priceInfo.turnover ?? 1; } decimal index = (total1 / baseValue) * 100; var percent = (index - yestclose) * 100 / yestclose; var info = new data.PriceInfo { code = item.code, date = today, price = Math.Round(index, 2), high = 0, low = 0, yestclose = yestclose, volume = vol, turnover = turnover, percent = percent, open = Math.Round(index, 2), }; priceInfoList.Add(info); this.Log().Info(string.Format("行业:{0},值:{1}", item.code, info.price)); } cateService.UpdateCategoryPrice(priceInfoList); cateService.AddPriceByDay <data.data_category_day_latest>(priceInfoList); cateService.AddPriceByWeek <data.data_category_week_latest>(priceInfoList); cateService.AddPriceByMonth <data.data_category_month_latest>(priceInfoList); this.Log().Info("计算结束"); }
private void Calculate(IndexDefinitionInfo define, TechCycle cycle) { IIndex indexGener = new Dma();// CodeHelper.GetIEvaluator(define.server_algorithm_code); IList <stockcategory> cateList = cateService.GetCategoryList("tencent"); int tatol = 0; foreach (var category in cateList) { IList <stock> stockList = stockService.GetStockByCategory(category.code); foreach (stock stock in stockList) { IList <PriceInfo> list = stockService.GetStockPriceDayInfo(stock); IList <IndexData> listIndexData = GetLastIndexData(stock, define); var result = indexGener.GetState(listIndexData); this.Log().Info(stock.name + "_" + result); using (StockManDBEntities entity = new StockManDBEntities()) { var cate = "1"; var code = cate + "_" + stock.code + "_" + define.code; var objectState = entity.objectstate.FirstOrDefault(p => p.code == code); if (objectState == null) { var temp = new objectstate() { code = code, category_code = cate, object_code = stock.code, index_code = define.code, date = DateTime.Now }; switch (cycle) { case TechCycle.day: temp.day = (int)result; break; case TechCycle.week: temp.week = (int)result; break; default: temp.month = (int)result; break; } entity.objectstate.Add(temp); } else { switch (cycle) { case TechCycle.day: objectState.last_day = objectState.day; objectState.day = (int)result; break; case TechCycle.week: objectState.last_week = objectState.week; objectState.week = (int)result; break; default: objectState.last_month = objectState.month; objectState.month = (int)result; break; } } entity.SaveChanges(); } if (++tatol > 3) { break; } } if (tatol > 3) { break; } } }
private void UpdateCategory() { IList <data.stockcategory> list = cateService.GetCategoryList("tencent"); //遍历列表,获取行业下的股票,计算指数,更新指数 IList <data.PriceInfo> priceInfoList = new List <data.PriceInfo>(); foreach (var item in list) { //IList<data.stock> stocks = stockService.GetStockByCategory(item.code); DateTime today = new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day); decimal yestclose = GetYestclose(item.code, today); //获取基期的值 int i = -1; bool isOk = false; decimal baseValue = 0; while (!isOk) { var priceList = stockService.GetStockPriceByDate(item.code, data.TechCycle.day, DateTime.Now.AddDays(i--)); if (priceList == null || priceList.Count == 0) { continue; } decimal total = 0, baseIndex = 100; foreach (var priceInfo in priceList) { total += priceInfo.price ?? 1 * priceInfo.volume ?? 1; } baseValue = (total * 100) / yestclose; isOk = true; } //index = (total / baseValue) * 100; var priceList0 = GetCurrentCategoryPrice(item.code); decimal vol = 0, turnover = 0; decimal total1 = 0; foreach (var priceInfo in priceList0) { total1 += priceInfo.price ?? 1 * priceInfo.volume ?? 1; vol += priceInfo.volume ?? 1; turnover += priceInfo.turnover ?? 1; } decimal index = (total1 / baseValue) * 100; var info = new data.PriceInfo { code = item.code, date = today, price = Math.Round(index, 2), high = 0, low = 0, yestclose = yestclose, volume = vol, turnover = turnover }; priceInfoList.Add(info); this.Log().Info(string.Format("行业:{0},值:{1}", item.code, info.price)); } foreach (var info in priceInfoList) { this.Log().Info("更新行业:" + string.Format("{0}_{1}", (int)ObjectType.Category, info.code) + ":" + info.code); UpdateRealTimePrice(ObjectType.Category, info); UpdateDayPrice(ObjectType.Category, info); //UpdatePrice(ObjectType.Category, TechCycle.Week, info); //UpdatePrice(ObjectType.Category, TechCycle.Month, info); } //cateService.UpdateCategoryPrice(priceInfoList); //cateService.AddPriceByDay<data.data_category_day_latest>(priceInfoList); //cateService.AddPriceByWeek<data.data_category_week_latest>(priceInfoList); //cateService.AddPriceByMonth<data.data_category_month_latest>(priceInfoList); this.Log().Info("计算结束"); }