Exemplo n.º 1
0
        public ITradePair GetTickersWithCandlesticks(ITradePair tp)
        {
            var candlesticks_4H   = GetCandleSticks(tp, 0, 0, CandlestickInterval.Hours_4).ToList();
            var candlesticksDaily = GetCandleSticks(tp, 0, 0, CandlestickInterval.Daily).ToList();

            var count = candlesticks_4H.Count() > candlesticksDaily.Count() ? candlesticks_4H.Count() : candlesticksDaily.Count();

            for (var i = 0; i < count; i++)
            {
                if (i < candlesticks_4H.Count())
                {
                    tp.CandleSticks_4h.Add(candlesticks_4H.ElementAt(i));
                    tp.CandleSticks_4h.Last().CCI   = tp.CandleSticks_4h.GetCCI(3, 10);
                    tp.CandleSticks_4h.Last().SMA20 = tp.CandleSticks_4h.GetMovingAvarage(20);
                }

                if (i < candlesticksDaily.Count())
                {
                    tp.CandleSticks_Daily.Add(candlesticksDaily.ElementAt(i));
                    tp.CandleSticks_Daily.Last().CCI   = tp.CandleSticks_Daily.Last().CCI = tp.CandleSticks_Daily.GetCCI(3, 10);
                    tp.CandleSticks_Daily.Last().SMA20 = tp.CandleSticks_Daily.GetMovingAvarage(20);
                }
            }

            return(tp);
        }
Exemplo n.º 2
0
        public IEnumerable <ICandleStick> GetCandleSticks(ITradePair tp, long start, long end, CandlestickInterval interval)
        {
            BlockApiCall();
            var url      = "public?command=returnChartData&currencyPair=" + tp.Id + "&start=1405699200&end=9999999999&period=" + (int)interval;
            var response = _restClient.Get <List <PoloniexCandleStick> >(url);

            _sw.Restart();
            return(response);
        }
Exemplo n.º 3
0
        public ITradePair GetTickersWithCandlesticks(ITradePair poltickers)
        {
            var ticker = new TradePair()
            {
                Id       = poltickers.Id,
                Exchange = CryptoExchange.Poloniex,
            };

            var candlesticks_4H   = GetCandleSticks(poltickers, 0, 0, CandlestickInterval.Hours_4).ToList();
            var candlesticksDaily = GetCandleSticks(poltickers, 0, 0, CandlestickInterval.Daily).ToList();

            var count = candlesticks_4H.Count() > candlesticksDaily.Count() ? candlesticks_4H.Count() : candlesticksDaily.Count();

            for (var j = 0; j < count; j++)
            {
                if (j < candlesticks_4H.Count())
                {
                    ticker.CandleSticks_4h.Add(new CandleStick()
                    {
                        CandleInterval = CandlestickInterval.Hours_4,
                        Close          = candlesticks_4H.ElementAt(j).Close,
                        High           = candlesticks_4H.ElementAt(j).High,
                        Low            = candlesticks_4H.ElementAt(j).Low,
                        Open           = candlesticks_4H.ElementAt(j).Open,
                        Volume         = candlesticks_4H.ElementAt(j).Volume,
                        Date           = candlesticks_4H.ElementAt(j).Date
                    });
                    ticker.CandleSticks_4h.Last().CCI   = ticker.CandleSticks_4h.GetCCI(3, 10);
                    ticker.CandleSticks_4h.Last().SMA20 = ticker.CandleSticks_4h.GetMovingAvarage(20);
                }

                if (j < candlesticksDaily.Count())
                {
                    ticker.CandleSticks_Daily.Add(new CandleStick()
                    {
                        CandleInterval = CandlestickInterval.Daily,
                        Close          = candlesticksDaily.ElementAt(j).Close,
                        High           = candlesticksDaily.ElementAt(j).High,
                        Low            = candlesticksDaily.ElementAt(j).Low,
                        Open           = candlesticksDaily.ElementAt(j).Open,
                        Volume         = candlesticksDaily.ElementAt(j).Volume,
                        Date           = candlesticksDaily.ElementAt(j).Date
                    });
                    ticker.CandleSticks_Daily.Last().CCI   = ticker.CandleSticks_Daily.GetCCI(3, 10);
                    ticker.CandleSticks_Daily.Last().SMA20 = ticker.CandleSticks_Daily.GetMovingAvarage(20);
                }
            }
            ticker.GetCCICrossToPositive();
            ticker.SetLastHighest();
            ticker.LastUpdated = DateTime.Now;

            return(ticker);
        }
Exemplo n.º 4
0
        public static void GetCCICrossToPositive(this ITradePair ticker)
        {
            var candles_4h = ticker.CandleSticks_4h.OrderByDescending(x => x.Date).ToList();


            if (candles_4h.FirstOrDefault() != null)
            {
                if (candles_4h.FirstOrDefault().CCI < 0)
                {
                    ticker.CCI_positive_distance_4h = 0;
                }
                else
                {
                    for (int i = 1; i < candles_4h.Count(); i++)
                    {
                        if (candles_4h.ElementAt(i).CCI < 0)
                        {
                            ticker.CCI_positive_distance_4h = i;
                            break;
                        }
                    }
                }
            }


            var candles_Daily = ticker.CandleSticks_Daily.OrderByDescending(x => x.Date).ToList();

            if (candles_Daily.FirstOrDefault() != null)
            {
                if (candles_Daily.FirstOrDefault().CCI < 0)
                {
                    ticker.CCI_positive_distance_4h = 0;
                }
                else
                {
                    for (int i = 1; i < candles_Daily.Count(); i++)
                    {
                        if (candles_Daily.ElementAt(i).CCI < 0)
                        {
                            ticker.CCI_positive_distance_Daily = i;
                            break;
                        }
                    }
                }
            }
        }
Exemplo n.º 5
0
        public IEnumerable <ICandleStick> GetCandleSticks(ITradePair tp, long start, long end, CandlestickInterval interval)
        {
            BlockApiCall();

            var intervalStr = "";

            switch (interval)
            {
            case CandlestickInterval.Hours_4:
                intervalStr = "4h";
                break;

            case CandlestickInterval.Daily:
                intervalStr = "1d";
                break;

            case CandlestickInterval.Minutes_5:
                break;

            case CandlestickInterval.Minutes_15:
                break;

            case CandlestickInterval.Minutes_30:
                break;

            case CandlestickInterval.Hours_2:
                break;

            default:
                throw new ArgumentOutOfRangeException(nameof(interval), interval, null);
            }

            var url = $"v1/klines?symbol={tp.Id}&interval={intervalStr}";

            var response = _restClient.Get <List <BinanceCandleStick> >(url);

            _sw.Restart();
            return(response);
        }
Exemplo n.º 6
0
        public static void SetLastHighest(this ITradePair ticker)
        {
            var candles_4H = ticker.CandleSticks_4h.OrderByDescending(x => x.Date);

            for (int i = 1; i < candles_4H.Count(); i++)
            {
                if (candles_4H.ElementAt(i).High > candles_4H.First().High)
                {
                    ticker.HighestInXAmountOfCandles_4h = i;
                    break;
                }

                if (i + 1 == candles_4H.Count())
                {
                    ticker.HighestInXAmountOfCandles_4h = i;
                }
            }

            var candles_Daily = ticker.CandleSticks_Daily.OrderByDescending(x => x.Date);

            for (int i = 1; i < candles_Daily.Count(); i++)
            {
                if (candles_Daily.ElementAt(i).High > candles_Daily.First().High)
                {
                    ticker.HighestInXAmountOfCandles_Daily = i;
                    break;
                }

                if (i + 1 == candles_4H.Count())
                {
                    ticker.HighestInXAmountOfCandles_Daily = i;
                }
            }

            return;
        }