Ejemplo n.º 1
0
        private List <ChartItem> FromSimpleStock(SimpleShare s)
        {
            List <ChartItem> ctList = null;

            if (s.Dates != null)
            {
                ctList = new List <ChartItem>(s.Dates.Count);

                double preClose = calChangeByStart ? s.Closes[0] : 0;
                for (int i = 0; i < s.Dates.Count; i++)
                {
                    ctList.Add(new ChartItem()
                    {
                        Date        = s.Dates[i],
                        Value       = s.Closes[i],
                        ValueChange = i != 0 ? (s.Closes[i] - preClose) / preClose : 0
                    });

                    if (!calChangeByStart)
                    {
                        preClose = s.Closes[i];
                    }
                }
            }

            return(ctList);
        }
Ejemplo n.º 2
0
        private SimpleShare FromStock(Stock stock)
        {
            SimpleShare share = new SimpleShare()
            {
                StockId = stock.id,
                Dates   = stock.Items.Select(cd => cd.DateTime).ToList(),
                Closes  = stock.Items.Select(cd => (double)cd.close).ToList()
            };

            return(share);
        }
Ejemplo n.º 3
0
        public JsonResult GetShareData(Market market, string id, DateTime?start, DateTime?end, DataType type, string context)
        {
            var stock = LoadStock(market, id, start, end);

            SimpleShare share = null;

            if (stock != null)
            {
                switch (type)
                {
                case DataType.Simple:
                    share = FromStock(stock);
                    break;

                case DataType.SimpleVolumn:
                    share = FromStock2(stock);
                    break;

                case DataType.Complete:
                    share = FromStock3(stock);
                    break;
                }
            }

            if (share != null)
            {
                return(Json(share, JsonRequestBehavior.AllowGet));
            }
            else
            {
                return(Json(new Error()
                {
                    Code = ErrorCode.InternalError,
                    Message = "Cannot get share"
                }, JsonRequestBehavior.AllowGet));
            }
        }