예제 #1
0
 private StockScreeningViewModel BuildStockScreeningModel(StockPrice x, string lastTrendBar)
 {
     return(new StockScreeningViewModel()
     {
         Date = x.Date,
         StockID = x.StockID,
         Open = x.Open,
         Close = x.Close,
         High = x.High,
         Low = x.Low,
         Support = x.Support,
         Resistance = x.Resistance,
         CloseToSupport = (x.Close - x.Support) / x.Support * 100,
         CloseToResistance = (x.Close - x.Resistance) / x.Resistance * 100,
         GSLineDirection = x.GSLineDirection,
         Trend = Screening.DetermineTrend(x),
         NormalRange = Screening.DetermineNormalRange(x),
         BigWave = Screening.DetermineBigWave(x),
         RiskProfile = Screening.DetermineRiskProfile(x),
         TradingPlan = Screening.DetermineTradingPlan(x),
         BuyLimit = Screening.DetermineBuyLimit(x),
         LastTrendBar = lastTrendBar
     });
 }
        // GET: StockWatchLists
        public async Task <IViewComponentResult> InvokeAsync(ApplicationUser currentUser, int?page, string filter, string sort, string nowsort)
        {
            _userID = currentUser;
            //var watchList = await _context.StockWatchList.Where(s => s.ApplicationUserId == _userID.Id).Include(s => s.Stock).ThenInclude(p=>p.Prices).ToListAsync();

            var watchList = await _context.GSProAdminWatchList.Include(s => s.Stock).ThenInclude(p => p.Prices).ToListAsync();

            var model = watchList.Select(x =>

            {
                var lastPrice    = x.Stock.Prices.OrderBy(m => m.Date).LastOrDefault();
                var lastTrendBar = "";
                GetAverageVolume(lastPrice, 50, out lastTrendBar);
                return(new GSProWatchListViewModel()
                {
                    StockID = x.StockID,
                    Open = lastPrice == null ? 0 : lastPrice.Open,
                    Close = lastPrice == null ? 0 : lastPrice.Close,
                    High = lastPrice == null ? 0 : lastPrice.High,
                    Low = lastPrice == null ? 0 : lastPrice.Low,
                    Volume = lastPrice == null ? 0 : lastPrice.Volume,
                    TradingPlan = Screening.DetermineTradingPlan(lastPrice),
                    Trend = Screening.DetermineTrend(lastPrice),
                    RiskProfile = Screening.DetermineRiskProfile(lastPrice),
                    BigWave = Screening.DetermineBigWave(lastPrice),
                    Support = lastPrice.Support,
                    Resistance = lastPrice.Resistance,
                    CloseToSupport = (lastPrice.Close - lastPrice.Support) / lastPrice.Support * 100,
                    CloseToResistance = (lastPrice.Close - lastPrice.Resistance) / lastPrice.Resistance * 100,
                    GSLineDirection = lastPrice.GSLineDirection,
                    NormalRange = Screening.DetermineNormalRange(lastPrice),
                    BuyLimit = Screening.DetermineBuyLimit(lastPrice),
                    LastTrendBar = lastTrendBar,
                    Target1 = x.Target1 == null ? 0: x.Target1,
                    Target2 = x.Target2 == null ? 0: x.Target2
                });
            }
                                         ).ToList();

            //var watchList = _context.StockWatchList.Where(s => s.ApplicationUserId == currentUser.Id).Include(s => s.Stock);


            if (string.IsNullOrEmpty(sort))
            {
                sort = "StockID";
            }

            var current_sort_field = sort.Replace("_DESC", "");

            if (!string.IsNullOrEmpty(nowsort))
            {
                if (nowsort == current_sort_field)
                {
                    if (sort.Contains("_DESC"))
                    {
                        sort = sort.Replace("_DESC", "");
                    }
                    else
                    {
                        sort = sort + "_DESC";
                    }
                }
                else
                {
                    sort = nowsort;
                }
            }


            Paging <GSProWatchListViewModel> pagingModel = new Paging <GSProWatchListViewModel>();

            pagingModel.data = (IQueryable <GSProWatchListViewModel>)model.AsQueryable();
            pagingModel.attribute.recordPerPage = 25;
            pagingModel.attribute.recordsTotal  = watchList.Count();
            pagingModel.attribute.totalPage     = Convert.ToInt32(Math.Ceiling((decimal)pagingModel.attribute.recordsTotal / pagingModel.attribute.recordPerPage));
            pagingModel.attribute.url           = @"/GSProWatchList/Index";
            pagingModel.attribute.divName       = "watchList";
            pagingModel.attribute.sorting       = sort;
            pagingModel.attribute.filter        = filter;
            pagingModel.OrderBy(sort);

            if (page == null)
            {
                page = 1;
            }


            pagingModel.DoPaging((int)page);

            //var stockWatchList = new StockWatchListViewModel()
            //{
            //    CurrentUser = currentUser,
            //    ModifiedStockId = "",
            //    WatchList = pagingModel
            //};
            return(View(pagingModel));


            //return View(model);
        }