コード例 #1
0
        public async Task <decimal> GetCurrentRate(string baseCurrency, string currency)
        {
            return(await Cache.GetOrCreate(baseCurrency + currency, async entry =>
            {
                var client = new CryptoCompareClient();
                Exception ex = null;

                // Try 3 times, or return 0
                for (var i = 0; i < 3; i++)
                {
                    try
                    {
                        var x = await client.Prices.SingleAsync(currency, new[] { baseCurrency }, true);
                        var res = x.First().Value;
                        return res;
                    }
                    catch (Exception e)
                    {
                        Logger.Warn(e);
                        ex = e;
                        await Task.Delay(5000);
                    }
                }

                Logger.Error(ex, "Failted to get Historic Market data");
                return 0;
            }));
        }
コード例 #2
0
        /// <summary>
        /// Enables the API.
        /// </summary>
        public void Enable()
        {
            this.client = new CryptoCompareClient();

            if (this.assetUpdateWorker.IsAlive)
            {
                throw new Exception("Already running!");
            }

            this.assetUpdateWorker = new Thread(this.AssetUpdateWorker);
            this.assetUpdateWorker.Start();
        }
コード例 #3
0
        public void ExecutePostConnectionTask()
        {
            AzusaContext context = AzusaContext.GetInstance();

            if (!context.DatabaseDriver.CanUpdateExchangeRates)
            {
                return;
            }

            DateTime lastUpdate = context.DatabaseDriver.GetLatestCryptoExchangeRateUpdateDate();

            if (lastUpdate.Date >= DateTime.Today)
            {
                return;
            }

            string apiKey = context.ReadIniKey("cryptocompare", "apikey", null);

            if (string.IsNullOrEmpty(apiKey))
            {
                return;
            }

            context.Splash.SetLabel("Frage Krypto-Umrechungskurse ab...");

            CryptoCompareClient cryptoCompareClient = CryptoCompareClient.Instance;

            cryptoCompareClient.SetApiKey(apiKey);
            Task <PriceSingleResponse> task = cryptoCompareClient.Prices.SingleSymbolPriceAsync("EUR", new [] { "BTC", "LTC", "DOGE", "XCH", "ETH" });

            task.Wait();
            PriceSingleResponse euro = task.Result;

            if (euro.Count == 0)
            {
                return;
            }

            CryptoExchangeRates result = new CryptoExchangeRates();

            result.btc  = Convert.ToDouble(euro["BTC"]);
            result.ltc  = Convert.ToDouble(euro["LTC"]);
            result.doge = Convert.ToDouble(euro["DOGE"]);
            result.xch  = Convert.ToDouble(euro["XCH"]);
            result.eth  = Convert.ToDouble(euro["ETH"]);
            context.DatabaseDriver.InsertCryptoExchangeRate(result);
        }
コード例 #4
0
 public HistoricaldataTests()
 {
     _cryptoCompareClient = new CryptoCompareClient(new HttpClientHandler(), "ab56a1fcd21d7faaefdb8a01e5efb0b14242f3af589f32cfcf942b0aec5a7731");
 }
コード例 #5
0
ファイル: Program.cs プロジェクト: systematiclabs/ml_monorepo
        static void FollowTrend()
        {
            bool    privotalpoint = false;
            bool    inversalpivot = false;
            decimal HighInCycle   = 0;
            decimal LowInCycle    = 9999;
            double  lastweight    = 0;
            bool    pivoted       = false;

            var client = new CryptoCompareClient();
            //var eth = client.Coins.SnapshotFullAsync(7605).Result;
            var           btc          = client.History.HourAsync("BTC", "EUR", 1440, new string[] { "Kraken" }, new DateTimeOffset(DateTime.Now)).Result;
            var           History      = new Stack <Tuple <double, DateTime, Tendance, int> >();
            List <double> InitialValue = new List <double>();
            List <double> CompletValue = new List <double>();
            bool          hasbough     = false;
            List <Tuple <double, Tendance> >       MovingLogic = new List <Tuple <double, Tendance> >();
            List <Tuple <double, Tendance, bool> > Historical  = new List <Tuple <double, Tendance, bool> >();

            bool trenddown = false;
            bool trendup   = false;

            foreach (var pair in btc.Data)
            {
                //Get Stats

                InitialValue.Add(double.Parse(pair.Open.ToString()));
                CompletValue.Add(double.Parse(pair.Close.ToString()));


                // Identify Moving Logic

                var FixedIndex = btc.Data.ToList().IndexOf(pair);

                if (FixedIndex > 0)
                {
                    var CurrentPairMinussOne     = btc.Data[FixedIndex - 1];
                    var CurrentPriceMoveUP       = pair.Close > CurrentPairMinussOne.Close;
                    var VolumeVariationMoveLower = pair.VolumeTo > CurrentPairMinussOne.VolumeTo;

                    if (CurrentPriceMoveUP)
                    {
                        MovingLogic.Add(new Tuple <double, Tendance>((double)pair.Open, Tendance.Up));
                        //Console.WriteLine("Price - Move From {0} to {1}", pair.Close, CurrentPairMinussOne.Close);
                    }

                    else
                    {
                        MovingLogic.Add(new Tuple <double, Tendance>((double)pair.Open, Tendance.Down));
                    }
                }



                //High and Low :)
                if (FixedIndex > 30)
                {
                    IList <decimal> FindPeaksHigh(IList <decimal> values, int rangeOfPeaks)
                    {
                        List <decimal> peaks = new List <decimal>();

                        int checksOnEachSide = rangeOfPeaks / 2;

                        for (int i = 0; i < values.Count; i++)
                        {
                            decimal val = values[i];
                            IEnumerable <decimal> range = values;
                            if (i > checksOnEachSide)
                            {
                                range = range.Skip(i - checksOnEachSide);
                            }
                            range = range.Take(rangeOfPeaks);
                            if (val == range.Max())
                            {
                                peaks.Add(val);
                            }
                        }
                        return(peaks);
                    }

                    IList <decimal> FindPeaksLow(IList <decimal> values, int rangeOfPeaks)
                    {
                        List <decimal> peaks = new List <decimal>();

                        int checksOnEachSide = rangeOfPeaks / 2;

                        for (int i = 0; i < values.Count; i++)
                        {
                            decimal val = values[i];
                            IEnumerable <decimal> range = values;
                            if (i < checksOnEachSide)
                            {
                                range = range.Skip(i - checksOnEachSide);
                            }
                            range = range.Take(rangeOfPeaks);
                            if (val == range.Min())
                            {
                                peaks.Add(val);
                            }
                        }
                        return(peaks);
                    }

                    var    lowestpeak = FindPeaksLow(btc.Data.ToList().GetRange(FixedIndex - 10, 10).Select(y => y.Close).ToList(), 10);
                    var    highpeak   = FindPeaksHigh(btc.Data.ToList().GetRange(FixedIndex - 10, 10).Select(y => y.Close).ToList(), 10);
                    double median     = MyListExtensions.Mean(btc.Data.ToList().GetRange(FixedIndex - 10, 10).Select(y => (double)y.Close).ToList());
                    int    xx         = Convert.ToInt32(InitialValue.ToList().Mean());

                    double current = double.Parse(pair.Open.ToString()) / InitialValue.ToList().Max() * 100;
                    bool   range80 = current >= 80;
                    bool   range60 = current >= 60;
                    bool   range40 = current >= 40;
                    bool   range20 = current >= 20;


                    double CurrentComparedtomedian = InitialValue.ToList().Mean() / double.Parse(pair.Open.ToString()) * 100;
                    double weight = (double)InitialValue.ToList().Mean() / double.Parse(InitialValue.ToList().Max().ToString());


                    double maxval = double.Parse(InitialValue.ToList().Max().ToString());
                    double lowval = double.Parse(InitialValue.ToList().Min().ToString());


                    double weightmovinglow = (double)InitialValue.ToList().Mean() / double.Parse(InitialValue.ToList().Min().ToString());



                    double realmedianweight = (double)InitialValue.ToList().Mean() / (maxval - lowval);


                    var weightforcegoingdown = weight < lastweight;


                    Console.WriteLine("High Range weight :" + weight);
                    Console.WriteLine("low Range weight :" + weightmovinglow);
                    Console.WriteLine("mid Range weight :" + realmedianweight);

                    //double median = InitialValue.ToList().Mean();
                    double result = Math.Abs(double.Parse(pair.Open.ToString()) - median);
                    double PercentOfVariationFromMedian = double.Parse(pair.Open.ToString()) / median;
                    double MissingPointBetweenMedian    = xx - double.Parse(pair.Open.ToString());



                    double resuslt              = PercentOfVariationFromMedian / 2;
                    bool   orientationforce     = resuslt < weight / 2;
                    double implementedvariation = MissingPointBetweenMedian / median * 100;
                    var    stddev   = GetStandardDeviation(btc.Data.ToList().GetRange(FixedIndex - 10, 10).Select(y => (double)y.Close).ToList());
                    var    lowsma9  = MovingAverage(9, btc.Data.ToList().GetRange(FixedIndex - 10, 10).Select(y => (double)y.Close).ToArray());
                    var    lowsma15 = MovingAverage(15, btc.Data.ToList().GetRange(FixedIndex - 16, 16).Select(y => (double)y.Close).ToArray());
                    var    lowsma25 = MovingAverage(25, btc.Data.ToList().GetRange(FixedIndex - 26, 26).Select(y => (double)y.Close).ToArray());

                    var CandleType = (pair.Low + pair.Close + pair.High) / 3;

                    Console.WriteLine("###############################################");
                    Console.WriteLine("Current Cycle Low : {0}", lowestpeak[0]);
                    Console.WriteLine("Candle bellow the lowest : {0}", pair.Close < lowestpeak[0]);
                    Console.WriteLine("STDev :) : {0}", stddev);
                    Console.WriteLine("cycle sma 9 : {0}", lowsma9.Last());
                    Console.WriteLine("cycle sma 15 : {0}", lowsma15.Last());
                    Console.WriteLine("cycle sma 25 : {0}", lowsma25.Last());
                    Console.WriteLine("Bellow HCL Derivation : {0}", CandleType > pair.Close);
                    Console.WriteLine("Bellow 0 line inside cycle : {0}", (double)pair.Close < median);
                    Console.WriteLine("Percent of variation from 0 line : {0}", PercentOfVariationFromMedian);
                    Console.WriteLine("Points missing points to 0 line : {0}", MissingPointBetweenMedian);
                    Console.WriteLine("Deviation weight : {0}", weight);
                    Console.WriteLine("Trend force reducting : {0}", weightforcegoingdown);
                    Console.WriteLine("Deviation position uper or equal 20 : {0}", range20);
                    Console.WriteLine("Deviation position uper or equal 40 : {0}", range40);
                    Console.WriteLine("Deviation position uper or equal 60 : {0}", range60);
                    Console.WriteLine("Deviation position uper or equal 80 : {0}", range80);
                    Console.WriteLine("Current Price : {0}", pair.Close);
                    Console.WriteLine("Current Cycle High : {0}", highpeak[0]);
                    Console.WriteLine("###############################################");

                    Console.ReadKey();
                    //foreach (var oldc in btc.Data.ToList().GetRange(FixedIndex - 10,10))
                    //{
                    //    if(oldc.Close < LowInCycle)
                    //    {
                    //        LowInCycle = oldc.Close;
                    //        Console.WriteLine("Lowest in cycle = {0}", LowInCycle);

                    //    }
                    //    if (oldc.Close > HighInCycle)
                    //    {
                    //        Console.WriteLine("Highest in cycle = {0}", HighInCycle);
                    //        HighInCycle = oldc.Close;
                    //    }
                    //}

                    lastweight = weight;
                }
            }
        }
コード例 #6
0
 public CryptoCompareService()
 {
     _client             = CryptoCompareClient.Instance;
     _exchangeRepository = new ExchangeRepository();
 }
コード例 #7
0
        private static async Task signalAl(string symbol = "QKC")
        {
            /*
             *  //@version=3
             *  //created by Buff DORMEIER
             *  //author: KIVANC @fr3762 on twitter
             *  study("VOLUME WEIGHTED MACD V2", shorttitle="VWMACDV2")
             *  fastperiod = input(12,title="fastperiod",type=integer,minval=1,maxval=500)
             *  slowperiod = input(26,title="slowperiod",type=integer,minval=1,maxval=500)
             *  signalperiod = input(9,title="signalperiod",type=integer,minval=1,maxval=500)
             *  fastMA = ema(volume*close, fastperiod)/ema(volume, fastperiod)
             *  slowMA = ema(volume*close, slowperiod)/ema(volume, slowperiod)
             *  vwmacd = fastMA - slowMA
             *  signal = ema(vwmacd, signalperiod)
             *  //hist= vwmacd - signal
             *  plot(vwmacd, color=blue, linewidth=2)
             *  plot(signal, color=red, linewidth=2)
             *  //plot(hist, color=green, linewidth=4, style=histogram)
             *  plot(0, color=black)
             */

            var client       = new CryptoCompareClient();
            var fastperiod   = 12;
            var slowperiod   = 26;
            var signalperiod = 9;
            var history      = await client.History.HourAsync(symbol, "BTC", 986, "Binance");

            var liste   = history.Data;
            var candles = liste.Where(x => x.Close > 0).ToList();
            var kalan   = candles.Count % 4;

            candles = candles.Skip(kalan).ToList();

            List <CandleData> listem4lu = new List <CandleData>();
            var son = candles.Count / 4;

            for (int i = 0; i < son; i++)
            {
                var        temp       = candles.Skip(i * 4).Take(4);
                CandleData candleData = new CandleData();
                foreach (var item in temp)
                {
                    candleData.Close      += item.Close;
                    candleData.VolumeFrom += item.VolumeFrom;
                }
                listem4lu.Add(candleData);
            }


            var volumesXcloses = listem4lu.Select(x => x.Close * x.VolumeFrom).ToList();
            var closes         = listem4lu.Select(x => x.Close).ToList();
            var volumes        = listem4lu.Select(x => x.VolumeFrom).ToList();

            /*
             *  fastMA = ema(volume*close, fastperiod)/ema(volume, fastperiod)
             *  slowMA = ema(volume*close, slowperiod)/ema(volume, slowperiod)
             *  vwmacd = fastMA - slowMA
             *  signal = ema(vwmacd, signalperiod)
             */
            var fastEma = volumesXcloses.Ema(fastperiod).Zip(volumes.Ema(fastperiod), (x, y) => { return(x / y); }).ToList();
            var slowEma = volumesXcloses.Ema(slowperiod).Zip(volumes.Ema(slowperiod), (x, y) => { return(x / y); }).ToList();
            var vwmacd  = fastEma.Zip(slowEma, (x, y) => { return(x - y); }).ToList();
            var signal  = vwmacd.Ema(signalperiod);

            //signalLast = signal.Last();
            //vwmacdLast = vwmacd.Last();
            if (vwmacd.Last() > signal.Last())
            {
                ekle(symbol);
            }
            else
            {
                cikar(symbol);
            }
        }