Exemple #1
0
        private void Send(string objCode, data.TechCycle cycle)
        {
            string msg = JsonConvert.SerializeObject(new IndexTask
            {
                type  = ObjectType.Object,
                code  = objCode,
                cycle = cycle
            });

            byte[] msgBytes = Encoding.UTF8.GetBytes(msg);
            _socket.Send(msg);
            this.Log().Info("发送:{" + msg + "}");
            string message = _socket.ReceiveString();

            this.Log().Info("接收:" + message);
        }
Exemple #2
0
        /// <summary>
        /// 计算某行业,每周期的指数值
        /// </summary>
        /// <param name="categoryCode"></param>
        /// <param name="cycle"></param>
        private void InitCategoryIndexByCycle(string categoryCode, data.TechCycle cycle)
        {
            //获取某只股票的所有价格列表

            var     stocks    = stockService.GetPriceInfo("0600000", cycle);
            decimal yestclose = 0;
            decimal baseIndex = 100;
            decimal baseValue = 0;

            //计算每个周期的指数值
            for (int i = 0; i < stocks.Count; i++)
            {
                var stock     = stocks[i];
                var priceList = stockService.GetStockPriceByDate(categoryCode, cycle, stock.date);
                if (priceList == null || priceList.Count == 0)
                {
                    continue;
                }
                decimal total = 0, vol = 0, turnover = 0, index = 0;
                foreach (var priceInfo in priceList)
                {
                    total    += priceInfo.price ?? 1 * priceInfo.volume ?? 1;
                    vol      += priceInfo.volume ?? 1;
                    turnover += priceInfo.turnover ?? 1;
                }

                if (baseValue == 0)
                {
                    baseValue = total;
                    index     = 100;
                }
                else
                {
                    index = (total / baseValue) * 100;
                }

                var info = new data.PriceInfo
                {
                    code      = categoryCode,
                    date      = stock.date,
                    price     = Math.Round(index, 2),
                    high      = 0,
                    low       = 0,
                    yestclose = yestclose,
                    volume    = vol,
                    turnover  = turnover,
                    open      = Math.Round(index, 2),
                };

                yestclose = index;

                try
                {
                    //cateService.AddPriceInfo(categoryCode, info, cycle);
                    if (cycle == TechCycle.day)
                    {
                        cateService.AddPriceByDay <data_category_day_latest>(new List <PriceInfo>()
                        {
                            info
                        }, true);
                    }
                    else if (cycle == TechCycle.week)
                    {
                        cateService.AddPriceByWeek <data_category_week_latest>(new List <PriceInfo>()
                        {
                            info
                        }, true);
                    }
                    else if (cycle == TechCycle.month)
                    {
                        cateService.AddPriceByMonth <data_category_month_latest>(new List <PriceInfo>()
                        {
                            info
                        }, true);
                    }

                    this.Log().Info(string.Format("行业指数:周期:{0},日期:{1},类别:{2},数值:{3}", cycle, info.date, categoryCode, info.price));
                }
                catch (Exception ex)
                {
                    //(new System.Collections.Generic.Mscorlib_CollectionDebugView<System.Data.Entity.Validation.DbEntityValidationResult>(((System.Data.Entity.Validation.DbEntityValidationException)(ex)).EntityValidationErrors as System.Collections.Generic.List<System.Data.Entity.Validation.DbEntityValidationResult>)).Items[0].ValidationErrors


                    this.Log().Error(ex.Message);
                }
            }
        }