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 void QueryCandleRunning() { if (timer != null) { timer.Stop(); } StockItemCollection stockCollection = ViewModel.CreateCollection(ChartItemType.Candle, raisePen, fallPen) as StockItemCollection; stockCollection.MaxItemXDistance = 50; ChartItemCollection volumnCollection = ViewModel.CreateCollection(ChartItemType.Volumn, raisePen, fallPen); volumnCollection.MaxItemXDistance = 50; volumn.SetMainCollection(volumnCollection); price.SetMainCollection(stockCollection); price.YScaleDock = YScaleDock.Right; volumn.YScaleDock = YScaleDock.Right; price.AddConnection(volumn); price.ForceDraw(); bool isStarted = false; var std = ViewModel.LoadDetailDatas(); var tdds = std.Data; if (tdds != null && tdds.Count > 10) { timer = new DispatcherTimer(); timer.Interval = interval; int i = 0; timer.Tick += (s, e) => { if (i == tdds.Count) { timer.Stop(); return; } if (!isStarted) { var candle = ViewModel.FromTradeDetailData(tdds[i], ChartItemType.Candle) as StockItem; var volumn = ViewModel.FromTradeDetailData(tdds[i], ChartItemType.Volumn) as VolumnItem; stockCollection.AddLatestChartItem(candle); volumnCollection.AddLatestChartItem(volumn); isStarted = true; } else { var candle = ViewModel.FromTradeDetailData(tdds[i], ChartItemType.Candle) as StockItem; var volumn = ViewModel.FromTradeDetailData(tdds[i], ChartItemType.Volumn) as VolumnItem; var lastestCandle = stockCollection.Items.Last(); var lastestVolumn = volumnCollection.Items.Last(); candle = ViewModel.MergeChartItem(lastestCandle as StockItem, candle); volumn = ViewModel.MergeChartItem(lastestVolumn as VolumnItem, volumn); Debug.WriteLine(candle.Date.ToString("HH:mm:ss ") + candle + "" + volumn); stockCollection.UpdateLatestChartItem(candle); volumnCollection.UpdateLatestChartItem(volumn); } price.ForceDraw(false, false); i++; }; Thread t = new Thread(new ThreadStart(() => { Thread.Sleep(1000); timer.Start(); })); t.Start(); } }