public async Task <StockVolumnList> GetStockItems(string id) { StockVolumnList result = null; await loadTask; var share = shares.FirstOrDefault(s => s.StockId == id); if (share != null) { result = FromCompleteStock(share); } return(result); }
private StockVolumnList FromCompleteStock(CompleteShare s) { StockVolumnList svList = new StockVolumnList(); if (s.Dates != null) { svList.Prices = new List <StockItem>(s.Dates.Count); svList.Volumns = new List <VolumnItem>(s.Dates.Count); double preClose = calChangeByStart ? s.Closes[0] : 0; for (int i = 0; i < s.Dates.Count; i++) { var sItem = new StockItem() { Date = s.Dates[i], Value = s.Closes[i], ValueChange = i != 0 ? (s.Closes[i] - preClose) / preClose : 0, High = s.Highs[i], Low = s.Lows[i], Open = s.Opens[i] }; svList.Prices.Add(sItem); svList.Volumns.Add(new VolumnItem() { Date = s.Dates[i], Value = s.Volumns[i], Turnover = s.Turnovers[i], IsRaise = s.Closes[i] > s.Opens[i] || (s.Closes[i] == s.Opens[i] && sItem.CloseChange > 0) }); if (!calChangeByStart) { preClose = s.Closes[i]; } } } return(svList); }
private void CandleTrading(string id, ChartItemCollection priceColl, ChartItemCollection volumnColl, IEnumerable<ChartItemCollection> maColls, StockVolumnList svList, int mvStart = 0) { tradingTimer = new DispatcherTimer(); bool isStarted = false; int i = 0; tradingTimer.Interval = tradingPeriod; tradingTimer.Tick += async (s, e) => { var tvList = await Timeloader.GetStockItems(id); if (i == tvList.Prices.Count) { tradingTimer.Stop(); return; } var candle = tvList.Prices[i]; var volumn = tvList.Volumns[i]; if (!isStarted) { priceColl.AddLatestChartItem(candle); volumnColl.AddLatestChartItem(volumn); UpdateMACollections(maColls, svList.Prices, candle, mvStart, isStarted); isStarted = true; } else { var lastestCandle = priceColl.Items.Last() as StockItem; var lastestVolumn = volumnColl.Items.Last() as VolumnItem; candle = MergeChartItem(lastestCandle, candle); volumn = MergeChartItem(lastestVolumn, volumn); volumn.IsRaise = candle.Open <= candle.Close; priceColl.UpdateLatestChartItem(candle); volumnColl.UpdateLatestChartItem(volumn); UpdateMACollections(maColls, svList.Prices, candle, mvStart, isStarted); } price.ForceDraw(false, false); i++; }; tradingTimer.Start(); }
private void CandleTrading(string id, ChartItemCollection priceColl, ChartItemCollection volumnColl, IEnumerable <ChartItemCollection> maColls, StockVolumnList svList, int mvStart = 0) { tradingTimer = new DispatcherTimer(); bool isStarted = false; int i = 0; tradingTimer.Interval = tradingPeriod; tradingTimer.Tick += async(s, e) => { var tvList = await Timeloader.GetStockItems(id); if (i == tvList.Prices.Count) { tradingTimer.Stop(); return; } var candle = tvList.Prices[i]; var volumn = tvList.Volumns[i]; if (!isStarted) { priceColl.AddLatestChartItem(candle); volumnColl.AddLatestChartItem(volumn); UpdateMACollections(maColls, svList.Prices, candle, mvStart, isStarted); isStarted = true; } else { var lastestCandle = priceColl.Items.Last() as StockItem; var lastestVolumn = volumnColl.Items.Last() as VolumnItem; candle = MergeChartItem(lastestCandle, candle); volumn = MergeChartItem(lastestVolumn, volumn); volumn.IsRaise = candle.Open <= candle.Close; priceColl.UpdateLatestChartItem(candle); volumnColl.UpdateLatestChartItem(volumn); UpdateMACollections(maColls, svList.Prices, candle, mvStart, isStarted); } price.ForceDraw(false, false); i++; }; tradingTimer.Start(); }
private StockVolumnList FromCompleteStock(CompleteShare s) { StockVolumnList svList = new StockVolumnList(); if (s.Dates != null) { svList.Prices = new List<StockItem>(s.Dates.Count); svList.Volumns = new List<VolumnItem>(s.Dates.Count); double preClose = calChangeByStart ? s.Closes[0] : 0; for (int i = 0; i < s.Dates.Count; i++) { var sItem = new StockItem() { Date = s.Dates[i], Value = s.Closes[i], ValueChange = i != 0 ? (s.Closes[i] - preClose) / preClose : 0, High = s.Highs[i], Low = s.Lows[i], Open = s.Opens[i] }; svList.Prices.Add(sItem); svList.Volumns.Add(new VolumnItem() { Date = s.Dates[i], Value = s.Volumns[i], Turnover = s.Turnovers[i], IsRaise = s.Closes[i] > s.Opens[i] || (s.Closes[i] == s.Opens[i] && sItem.CloseChange > 0) }); if (!calChangeByStart) preClose = s.Closes[i]; } } return svList; }