public ResizeableArray <TradeInfoItem> DownloadTradeHistory(TickerInputInfo info, DateTime time)
        {
            CachedTradeHistory savedData = new CachedTradeHistory()
            {
                Exchange = info.Exchange, TickerName = info.TickerName, StartDate = info.StartDate, EndDate = info.EndDate, BaseCurrency = info.Ticker.BaseCurrency, MarketCurrency = info.Ticker.MarketCurrency
            };
            CachedTradeHistory cachedData = CachedTradeHistory.FromFile(CachedTradeHistory.Directory + "\\" + ((ISupportSerialization)savedData).FileName);

            info.CheckUpdateTime();
            if (cachedData != null)
            {
                if (info.StartDate != DateTime.MinValue && info.StartDate == cachedData.Items[0].Time.Date && info.EndDate.AddDays(-1) <= cachedData.Items.Last().Time.Date)
                {
                    return(cachedData.Items);
                }
            }

            DateTime start             = info.StartDate.Date;
            int      intervalInSeconds = info.KlineIntervalMin * 60;
            DateTime origin            = start;
            DateTime end = info.EndDate.Date;
            ResizeableArray <TradeInfoItem>         res     = new ResizeableArray <TradeInfoItem>();
            List <ResizeableArray <TradeInfoItem> > tmpList = new List <ResizeableArray <TradeInfoItem> >();

            DownloadProgress = 0.0;
            DownloadText     = "Donwloading Trade History Data for " + info.Exchange + ":" + info.TickerName;

            while (end > start)
            {
                ResizeableArray <TradeInfoItem> data = info.Ticker.Exchange.GetTrades(info.Ticker, start, end);
                if (data == null || data.Count == 0)
                {
                    break;
                }
                tmpList.Add(data);
                DownloadProgress = 100 - (100 * (data.Last().Time - origin).TotalMinutes / (DateTime.UtcNow - origin).TotalMinutes);
                var args = RaiseDownloadProgressChanged();
                if (args.Cancel)
                {
                    return(null);
                }
                Thread.Sleep(300);
                end = data.Last().Time.AddMilliseconds(-1);
            }
            for (int i = tmpList.Count - 1; i >= 0; i--)
            {
                res.AddRangeReversed(tmpList[i]);
            }
            cachedData       = savedData;
            cachedData.Items = res;
            cachedData.Save();
            for (int i = 0; i < res.Count - 1; i++)
            {
                if (res[i].Time > res[i + 1].Time)
                {
                    throw new Exception("TradeHistory Timing Error!");
                }
            }
            return(res);
        }
        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 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);
        }
        private void beNavigate_EditValueChanged(object sender, EventArgs e)
        {
            if (NavigatableArray == null)
            {
                return;
            }
            try {
                int index = Convert.ToInt32(this.beNavigate.EditValue);
                if (index < 0)
                {
                    index = 0;
                }
                if (index >= NavigatableArray.Count)
                {
                    index = NavigatableArray.Count - 1;
                }
                NavigatableIndex = index;
            }
            catch (Exception) {
                return;
            }
            ResizeableArray <TextAnnotation> annotations = NavigatableInfo.DataSource as ResizeableArray <TextAnnotation>;

            if (annotations != null)
            {
                TextAnnotation ann  = annotations[NavigatableIndex];
                DateTime       time = (DateTime)((PaneAnchorPoint)ann.AnchorPoint).AxisXCoordinate.AxisValue;
                NavigateTo(time);
                SelectedAnnotation = ann;
            }
            else
            {
                NavigateTo(NavigatableArray.GetItem(NavigatableIndex));
            }
        }
Ejemplo n.º 5
0
        public void ShouldIncreseCapacityOnInsertWhenMaxCapacityIsReached()
        {
            var array = new ResizeableArray <int>();

            Assert.AreEqual(16, array.Capacity);

            for (int i = 0; i < 15; i++)
            {
                array.Add(i);
            }

            Assert.AreEqual(16, array.Capacity);
            array.Insert(200, 4);
            Assert.AreEqual(32, array.Capacity);

            for (int i = 0; i < 16; i++)
            {
                if (i < 4)
                {
                    Assert.AreEqual(i, array.ElementAt(i));
                }

                if (i == 4)
                {
                    Assert.AreEqual(200, array.ElementAt(i));
                }

                if (i > 4)
                {
                    Assert.AreEqual(i - 1, array.ElementAt(i));
                }
            }
        }
Ejemplo n.º 6
0
        public void ShouldThorwExceptionOnPopWhenIndexOutOfBounds()
        {
            var array = new ResizeableArray <int>();

            Assert.AreEqual(0, array.Length);
            Assert.Throws <ValidationException>(() => array.RemoveAt(1));
        }
Ejemplo n.º 7
0
        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]);
                }
            });
        }
Ejemplo n.º 8
0
        public void ShouldDecreaseCapacityOnPop()
        {
            var array = new ResizeableArray <int>();

            Assert.AreEqual(16, array.Capacity);

            for (int i = 0; i < 16; i++)
            {
                array.Add(i);
            }

            Assert.AreEqual(32, array.Capacity);
            Assert.AreEqual(16, array.Length);

            for (int i = 0; i < 8; i++)
            {
                array.Pop();
            }

            Assert.AreEqual(16, array.Capacity);
            Assert.AreEqual(8, array.Length);

            for (int i = 0; i < 6; i++)
            {
                array.Pop();
            }

            Assert.AreEqual(2, array.Length);
            Assert.AreEqual(16, array.Capacity);
        }
Ejemplo n.º 9
0
        public void ShouldDecreaseCapacityOnRemove()
        {
            var array = new ResizeableArray <int>();

            Assert.AreEqual(16, array.Capacity);

            for (int i = 0; i < 16; i++)
            {
                array.Add(i);
            }

            Assert.AreEqual(32, array.Capacity);
            Assert.AreEqual(16, array.Length);

            for (int i = 0; i < 8; i++)
            {
                var elem = array.ElementAt(0);
                array.Remove(elem);
            }

            Assert.AreEqual(16, array.Capacity);
            Assert.AreEqual(8, array.Length);

            for (int i = 0; i < 6; i++)
            {
                var elem = array.ElementAt(0);
                array.Remove(elem);
            }

            Assert.AreEqual(2, array.Length);
            Assert.AreEqual(16, array.Capacity);
        }
Ejemplo n.º 10
0
        public void ShouldThorwExceptionOnPopWhenArrayIsEmpty()
        {
            var array = new ResizeableArray <int>();

            Assert.AreEqual(0, array.Length);
            Assert.Throws <ValidationException>(() => array.Pop());
        }
Ejemplo n.º 11
0
        public void ShouldReturnTrueOnIsEmptyWhenLenghtIs0()
        {
            var array = new ResizeableArray <int>();

            Assert.AreEqual(0, array.Length);
            Assert.True(array.IsEmpty);
        }
        void UpdateChartSeries(ResizeableArray <CandleStickData> data)
        {
            this.chartControl1.Series["Current"].DataSource = new RealTimeSource()
            {
                DataSource = data
            };
            this.chartControl1.Series["Volume"].DataSource = new RealTimeSource()
            {
                DataSource = data
            };
            this.chartControl1.Series["BuySellVolume"].DataSource = new RealTimeSource()
            {
                DataSource = data
            };

            if (ShouldUpdateVisualRange)
            {
                ShouldUpdateVisualRange = false;

                BeginInvoke(new MethodInvoker(() => {
                    UpdateCandleStickVisualRange();
                    UpdateMarketDepthVisualRange();
                    UpdateWallsVisualRange();
                }));
            }
        }
        void UpdateEvents(System.Collections.Specialized.NotifyCollectionChangedEventArgs e)
        {
            Series s = this.chartControl1.Series["Events"];

            s.Points.BeginUpdate();
            this.chartControl1.Annotations.BeginUpdate();
            s.Points.Clear();
            this.chartControl1.Annotations.Clear();
            try {
                ResizeableArray <CandleStickData> cd = Ticker.CandleStickData;
                DateTime endTime   = cd.Count == 0 ? DateTime.MinValue : cd.Last().Time;
                DateTime startTime = cd.Count == 0 ? DateTime.MaxValue : cd.First().Time;
                for (int i = 0; i < Ticker.Events.Count; i++)
                {
                    TickerEvent ev = Ticker.Events[i];
                    if (ev.Time <= endTime && ev.Time >= startTime)
                    {
                        SeriesPoint sp = CreateEventPoint(Ticker.Events[i]);
                        s.Points.Add(sp);
                        CreateAnnotation(sp);
                    }
                }
            }
            finally {
                s.Points.EndUpdate();
                this.chartControl1.Annotations.EndUpdate();
            }
        }
Ejemplo n.º 14
0
 void UpdateCandleStickData(ResizeableArray <CandleStickData> data)
 {
     for (int i = 0; i < Ticker.CandleStickData.Count; i++)
     {
         data.Add(Ticker.CandleStickData[i]);
     }
     Ticker.CandleStickData = data;
 }
Ejemplo n.º 15
0
        public void ShouldNotThrowExceptionOnInsertWhenIndexIsZero()
        {
            var array = new ResizeableArray <int>();

            array.Insert(1, 0);

            Assert.AreEqual(1, array.Length);
            Assert.AreEqual(1, array.ElementAt(0));
        }
Ejemplo n.º 16
0
        public void ShouldNotThrowExceptionOnPrependWhenArrayIsEmpty()
        {
            var array = new ResizeableArray <int>();

            array.Prepend(1);

            Assert.AreEqual(1, array.Length);
            Assert.AreEqual(1, array.ElementAt(0));
        }
Ejemplo n.º 17
0
        public void ShouldThrowExceptionOnElementAtWhenIndexOutOfBounds()
        {
            var array = new ResizeableArray <int>();

            Assert.Throws <ValidationException>(() => array.ElementAt(10));
            Assert.Throws <ValidationException>(() => array.ElementAt(0));
            array.Add(10);
            array.Add(11);
            Assert.Throws <ValidationException>(() => array.ElementAt(2));
        }
Ejemplo n.º 18
0
        public void ShouldReturnFlaseOnIsEmptyWhenLenghtIsGreaterThan0()
        {
            var array = new ResizeableArray <int>();

            array.Add(10);
            array.Add(9);

            Assert.AreEqual(2, array.Length);
            Assert.False(array.IsEmpty);
        }
Ejemplo n.º 19
0
        public ResizeableArray <TradeInfoItem> GetTradeHistory()
        {
            ResizeableArray <TradeInfoItem> res = new ResizeableArray <TradeInfoItem>(TradeHistory.Count);

            foreach (var item in TradeHistory)
            {
                res.Add(item);
            }
            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);
 }
Ejemplo n.º 21
0
        public void ShouldThrowExceptionOnSetWhenIndexOutOfBounds()
        {
            var array = new ResizeableArray <int>();

            array.Add(1);
            array.Add(2);
            array.Add(3);

            Assert.AreEqual(3, array.Length);
            Assert.Throws <ValidationException>(() => array.Set(6, 15));
        }
        private ResizeableArray <CandleStickData> CreateCandleSticks()
        {
            Ticker ticker = PoloniexExchange.Default.Tickers.FirstOrDefault(t => t.BaseCurrency == BaseCurrency && t.MarketCurrency == MarketCurrency);

            if (ticker == null)
            {
                throw new Exception("Ticker not found");
            }
            candleSticks = ticker.GetCandleStickData(5, Time, 5 * 50 * 60);
            return(candleSticks);
        }
        private ResizeableArray <CandleStickData> DownloadCandleSticks()
        {
            Ticker ticker = PoloniexExchange.Default.Tickers.FirstOrDefault(t => t.BaseCurrency == BaseCurrency && t.MarketCurrency == MarketCurrency);

            if (ticker == null)
            {
                throw new Exception("Ticker not found");
            }
            candleSticks = ticker.GetCandleStickData(5, GetCandleSticksStartTime(), (int)GetCandlesticksRange());
            return(candleSticks);
        }
Ejemplo n.º 24
0
        public void ShouldReturnCorrectElementOnElementAtWhenArrayIsNotEmpty()
        {
            var array = new ResizeableArray <int>();

            array.Add(10);
            array.Add(0);

            Assert.AreEqual(10, array.ElementAt(0));
            Assert.AreEqual(0, array.ElementAt(1));
            Assert.AreEqual(2, array.Length);
        }
Ejemplo n.º 25
0
        public override ResizeableArray <TradeInfoItem> GetTrades(Ticker ticker, DateTime starTime)
        {
            string address = string.Format("https://api.binance.com/api/v1/depth?symbol={0}&limit={1}",
                                           Uri.EscapeDataString(ticker.CurrencyPair), 1000);
            string text = ((Ticker)ticker).DownloadString(address);

            if (string.IsNullOrEmpty(text))
            {
                return(null);
            }

            JArray trades = JsonConvert.DeserializeObject <JArray>(text);

            if (trades.Count == 0)
            {
                return(null);
            }

            ResizeableArray <TradeInfoItem> list = new ResizeableArray <TradeInfoItem>(1000);
            int index = 0;

            for (int i = 0; i < trades.Count; i++)
            {
                JObject  obj     = (JObject)trades[i];
                DateTime time    = new DateTime(obj.Value <Int64>("time"));
                int      tradeId = obj.Value <int>("id");
                if (time < starTime)
                {
                    break;
                }
                TradeInfoItem item  = new TradeInfoItem(null, ticker);
                bool          isBuy = obj.Value <string>("type").Length == 3;
                item.AmountString = obj.Value <string>("qty");
                item.Time         = time;
                item.Type         = isBuy ? TradeType.Buy : TradeType.Sell;
                item.RateString   = obj.Value <string>("price");
                item.Id           = tradeId;
                double price  = item.Rate;
                double amount = item.Amount;
                item.Total = price * amount;
                list.Add(item);
                index++;
            }
            if (ticker.HasTradeHistorySubscribers)
            {
                ticker.RaiseTradeHistoryChanged(new TradeHistoryChangedEventArgs()
                {
                    NewItems = list
                });
            }
            return(list);
        }
Ejemplo n.º 26
0
        public void ShouldAddElementAtCorrectIndexOnInsert()
        {
            var array = new ResizeableArray <int>();

            array.Add(10);
            array.Add(15);
            array.Add(20);
            array.Insert(25, 1);

            Assert.AreEqual(10, array.ElementAt(0));
            Assert.AreEqual(25, array.ElementAt(1));
            Assert.AreEqual(15, array.ElementAt(2));
            Assert.AreEqual(20, array.ElementAt(3));
        }
Ejemplo n.º 27
0
        public void ShouldAddElementAtTheEndOfArrayOnAdd()
        {
            var array = new ResizeableArray <int>();

            array.Add(12);
            array.Add(16);
            array.Add(122);

            Assert.False(array.IsEmpty);
            Assert.AreEqual(3, array.Length);
            Assert.AreEqual(12, array.ElementAt(0));
            Assert.AreEqual(16, array.ElementAt(1));
            Assert.AreEqual(122, array.ElementAt(2));
        }
Ejemplo n.º 28
0
        public void ShouldSetCorrectAtValueAtGivenIndexOnSet()
        {
            var array = new ResizeableArray <int>();

            array.Add(1);
            array.Add(2);
            array.Add(3);
            array.Set(1, 15);

            Assert.AreEqual(3, array.Length);
            Assert.AreEqual(1, array.ElementAt(0));
            Assert.AreEqual(15, array.ElementAt(1));
            Assert.AreEqual(3, array.ElementAt(2));
        }
Ejemplo n.º 29
0
        public void ShouldReturnMinusOneOnFindWhenElementDoesNotExist()
        {
            var array = new ResizeableArray <int>();

            array.Add(12);
            array.Add(16);
            array.Add(14);
            array.Add(16);
            array.Add(25);

            var index = array.Find(200);

            Assert.AreEqual(-1, index);
        }
Ejemplo n.º 30
0
        public void ShouldReturnFirstIndexOnFindWhenElementExists()
        {
            var array = new ResizeableArray <int>();

            array.Add(12);
            array.Add(16);
            array.Add(14);
            array.Add(16);
            array.Add(25);

            var index = array.Find(16);

            Assert.AreEqual(1, index);
        }
Ejemplo n.º 31
0
 public void Light(bool val)
 {
     if (val == true)
     {
         lightpositions = new ResizeableArray<Vector3>(localVars.chunklength * localVars.chunklength * localVars.chunklength); //Fix this later
         lightcolors = new Color32[localVars.chunklength, localVars.chunklength, localVars.chunklength];
         lightintensity = new float[localVars.chunklength, localVars.chunklength, localVars.chunklength];
         lightrange = new float[localVars.chunklength, localVars.chunklength, localVars.chunklength];
         light = true;
     }
 }