コード例 #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.RemoveAt(0);
            }
            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.Add(new TickerHistoryItem()
            {
                Time = item.Time, Ask = item.LowestAsk, Bid = item.HighestBid, Current = item.Last
            });
            item.RaiseHistoryItemAdded();
        }
コード例 #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.Add(new TickerHistoryItem()
            {
                Time = Time, Ask = LowestAsk, Bid = HighestBid, Current = Last
            });
            RaiseHistoryChanged();
        }
コード例 #3
0
 public static void UpdateHistoryForTradeItem(TradeHistoryItem item, ITicker ticker)
 {
     for (int i = ticker.History.Count - 1; i >= 0; i--)
     {
         TickerHistoryItem h = ticker.History[i];
         if (h.Time.Ticks <= item.Time.Ticks)
         {
             item.Bid     = h.Bid;
             item.Ask     = h.Ask;
             item.Current = h.Current;
             break;
         }
     }
 }
コード例 #4
0
        public static void AddCandleStickData(List <CandleStickData> list, TickerHistoryItem item, long rangeInSeconds)
        {
            Console.WriteLine("Update candle stick data " + item.Time.ToLongTimeString());
            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);
                Console.WriteLine("Add candlestick data Time = " + candleItem.Time);
                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;
        }
コード例 #5
0
        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;
        }
コード例 #6
0
        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);
        }