public static void UpdateVolumes(ResizeableArray <CandleStickData> candles, TradeInfoItem trade, int period) { if (candles.Count == 0) { return; } CandleStickData saved = candles.Last(); if (saved.Time > trade.Time || saved.Time.AddMinutes(period) <= saved.Time) { UpdateCandle(saved, trade); return; } saved = null; for (int ci = 0; ci < candles.Count; ci++) { CandleStickData c = candles[ci]; if (c.Time <= trade.Time & c.Time.AddMinutes(period) > trade.Time) { saved = c; break; } } UpdateCandle(saved, trade); }
public static void UpdateVolumes(ResizeableArray <CandleStickData> candles, List <TradeInfoItem> trades, int period) { CandleStickData saved = null; if (trades == null) { return; } for (int i = 0; i < trades.Count; i++) { var trade = trades[i]; if (saved == null || saved.Time > trade.Time || saved.Time.AddMinutes(period) <= saved.Time) { saved = null; for (int ci = 0; ci < candles.Count; ci++) { CandleStickData c = candles[ci]; if (c.Time <= trade.Time & c.Time.AddMinutes(period) > trade.Time) { saved = c; break; } } } if (saved != null) { UpdateCandle(saved, trade); } } }
public void UpdateLastCandleStick() { if (CandleStickData.Count == 0) { return; } CandleStickData last = CandleStickData.Last(); DateTime newKlineData = last.Time.AddMinutes(CandleStickPeriodMin); DateTime timeToUpdate = last.Time; if (DateTime.UtcNow >= newKlineData) { timeToUpdate = newKlineData; } Task t = Task.Run(() => { ResizeableArray <CandleStickData> res = GetCandleStickData(CandleStickPeriodMin, timeToUpdate, 1000000); if (res == null) { return; } if (res[0].Time.Year == 1970) { return; } for (int i = 0; i < res.Count; i++) { UpdateCandleStickData(res[i]); } }); }
public CandleStickData UpdateCandleStickData(CandleStickData newData) { DateTime dt = newData.Time; int end = Math.Max(0, CandleStickData.Count - 30); for (int i = CandleStickData.Count - 1; i >= end; i--) { CandleStickData data = CandleStickData[i]; if (dt > data.Time) { break; } if (dt == data.Time) { CandleStickData[i] = newData; return(newData); } if (dt < data.Time) { CandleStickData.Insert(i, newData); return(newData); } } CandleStickData.Add(newData); return(newData); }
protected CandleStickData CreateStartCandleStick(CandleStickData data) { CandleStickData res = new Crypto.Core.CandleStickData(); res.Assign(data); res.Open = res.Close = res.High = res.Low = data.Open; return(res); }
public static void InitializeVolumes(ResizeableArray <CandleStickData> candles, List <TradeInfoItem> trades, int period) { for (int i = 0; i < candles.Count; i++) { CandleStickData data = candles[i]; data.BuyVolume = 0; data.SellVolume = 0; } UpdateVolumes(candles, trades, period); }
public void Assign(CandleStickData data) { this.open = data.Open; this.close = data.Close; this.high = data.High; this.low = data.Low; this.Time = data.Time; this.Value = data.Value; this.weightedAverage = data.WeightedAverage; this.volume = data.volume; this.sellVolume = data.sellVolume; this.buyVolume = data.buyVolume; }
public static void UpdateCandle(CandleStickData candle, TradeInfoItem trade) { if (candle == null) { return; } if (trade.Type == TradeType.Buy) { candle.BuyVolume += trade.Amount; } else { candle.SellVolume += trade.Amount; } candle.BuySellVolume = candle.BuyVolume - candle.SellVolume; }
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); }