Esempio n. 1
0
        public static void UpdateHistoryItem(Ticker item)
        {
            TickerHistoryItem last = item.History.Count == 0 ? null : item.History.Last();

            if (item.History.Count > 36000)
            {
                item.History.RemoveFirst();
            }
            if (last != null)
            {
                if (last.Ask == item.LowestAsk && last.Bid == item.HighestBid && last.Current == item.Last)
                {
                    return;
                }
                //item.Change = ((item.Last - last.Current) / last.Current) * 100;
                if (last.Bid != item.HighestBid)
                {
                    item.BidChange = (item.HighestBid - last.Bid) * 100;
                }
                if (last.Ask != item.LowestAsk)
                {
                    item.AskChange = item.LowestAsk - last.Ask;
                }
                bool error = Math.Abs(item.BidChange) > 100 || Math.Abs(item.AskChange) > 100 || Math.Abs(item.Change) > 100;
                if (error)
                {
                    Debug.WriteLine("error");
                }
            }
            item.History.AddLast(new TickerHistoryItem()
            {
                Time = item.Time, Ask = item.LowestAsk, Bid = item.HighestBid, Current = item.Last
            });
            item.RaiseHistoryChanged();
        }
Esempio n. 2
0
        public void UpdateHistoryItem()
        {
            TickerHistoryItem last = History.Count == 0 ? null : History.Last();

            if (last != null)
            {
                if (last.Ask == LowestAsk && last.Bid == HighestBid && last.Current == Last)
                {
                    return;
                }
                //Change = ((Last - last.Current) / last.Current) * 100;
                if (last.Bid != HighestBid)
                {
                    BidChange = (HighestBid - last.Bid) * 100;
                }
                if (last.Ask != LowestAsk)
                {
                    AskChange = (LowestAsk - last.Ask) * 100;
                }
            }
            History.AddLast(new TickerHistoryItem()
            {
                Time = Time, Ask = LowestAsk, Bid = HighestBid, Current = Last
            });
            RaiseHistoryChanged();
        }
        public static void AddCandleStickData(IList <CandleStickData> list, TickerHistoryItem item, long rangeInSeconds)
        {
            if (list == null)
            {
                return;
            }
            CandleStickData candleItem   = null;
            long            maxTickCount = rangeInSeconds * TimeSpan.TicksPerSecond;

            if (list.Count == 0 || (item.Time.Ticks - list[list.Count - 1].Time.Ticks) > maxTickCount)
            {
                candleItem      = new CandleStickData();
                candleItem.Open = candleItem.Close = candleItem.High = candleItem.Low = item.Current;
                candleItem.Time = item.Time;
                list.Add(candleItem);
                return;
            }
            candleItem       = list[list.Count - 1];
            candleItem.Close = item.Current;
            candleItem.Low   = Math.Min(candleItem.Low, item.Current);
            candleItem.High  = Math.Max(candleItem.High, item.Current);
            return;
        }
        public static BindingList <CandleStickData> CreateCandleStickData(IList <TickerHistoryItem> list, long rangeInSeconds)
        {
            BindingList <CandleStickData> res = new BindingList <CandleStickData>();
            CandleStickData candleItem        = null;
            long            maxTickCount      = rangeInSeconds * TimeSpan.TicksPerSecond;

            for (int i = 0; i < list.Count; i++)
            {
                TickerHistoryItem item = list[i];
                if (candleItem == null || (item.Time.Ticks - candleItem.Time.Ticks > maxTickCount))
                {
                    candleItem      = new CandleStickData();
                    candleItem.Time = item.Time;
                    candleItem.Open = item.Current;
                    candleItem.Low  = candleItem.High = candleItem.Close = item.Current;
                    res.Add(candleItem);
                    continue;
                }
                candleItem.Close = item.Current;
                candleItem.Low   = Math.Min(candleItem.Low, item.Current);
                candleItem.High  = Math.Max(candleItem.High, item.Current);
            }
            return(res);
        }