Esempio n. 1
0
        private void btnAnalyze_Click(object sender, EventArgs e)
        {
            //vars
            HitBTC_API api  = new HitBTC_API();
            methods    meth = new methods();

            //kry coins
            List <HitBTC_TradingPairs_Template> coins = api.getTradingPairs();

            //kry base currencies
            var basecurrencies = coins.Select(a => a.quoteCurrency).Distinct();

            //first get BTC price
            meth.Pull_Coin_History_NO_DB("BTC", "ZAR", true);

            //kry alle btc
            List <HitBTC_TradingPairs_Template> btc_curr = coins.Where(b => b.quoteCurrency == "BTC").ToList();

            //kry die history vir elkeen
            foreach (HitBTC_TradingPairs_Template coin in btc_curr)
            {
                //pull
                meth.Pull_Coin_History_NO_DB(coin.baseCurrency, "USD", true);
            }
        }
Esempio n. 2
0
        public List <CryptoCompare_Coin_History_Template.Datum> Pull_Coin_History_Structure(string coin_symbol, string currency)
        {
            //variables
            methods meth = new methods();
            List <CryptoCompare_Coin_History_Template.Datum> data_obj = new List <CryptoCompare_Coin_History_Template.Datum>();
            bool              run         = true;
            DateTime          dt_earliest = DateTime.Now;
            CryptoCompare_API crypt_api   = new CryptoCompare_API();


            while (run)
            {
                //get history
                CryptoCompare_Coin_History_Template.RootObject hist = new CryptoCompare_Coin_History_Template.RootObject();
                hist = crypt_api.GetCoinHistory(coin_symbol, currency, 2000, dt_earliest.ToString("yyyy-MM-dd"));

                //convert die datums
                DateTime date_early = meth.UnixTimeStampToDateTime(double.Parse(hist.TimeFrom.ToString()));
                DateTime date_last  = meth.UnixTimeStampToDateTime(double.Parse(hist.TimeTo.ToString()));

                //kyk if daar nog data is
                if (date_early == dt_earliest)
                {
                    break;
                }


                //set date
                for (int i = 0; i < hist.Data.Count; i++)
                {
                    //set date
                    hist.Data[i].s_date = meth.UnixTimeStampToDateTime(double.Parse(hist.Data[i].time.ToString()));

                    //add na die main list
                    data_obj.Add(hist.Data[i]);
                }

                //get the earliest date
                hist.Data.OrderBy(a => a.s_date);

                //moet weer run
                dt_earliest = hist.Data[0].s_date;

                //order die main list
                data_obj.OrderBy(a => a.s_date);

                //check if need to run again
                if (hist.Data.Count < 2000)
                {
                    break;
                }
            }
            return(data_obj);
        }
        public CryptoCompare_Coin_History_Template.RootObject GetCoinHistory(string coin_lookup, string currency, int limit, string from_date)
        {
            //variables
            methods meth     = new methods();
            string  hour_url = "https://min-api.cryptocompare.com/data/histohour?fsym=" + coin_lookup + "&tsym=" + currency + "&limit=" + limit.ToString();
            string  day_url  = "https://min-api.cryptocompare.com/data/histoday?fsym=" + coin_lookup + "&tsym=" + currency + "&limit=" + limit.ToString();
            string  call_url = "";

            //check for dates
            if (string.IsNullOrWhiteSpace(from_date))
            {
                //no offset
                call_url = day_url;
            }
            else
            {
                //kry date
                DateTime dt_from = DateTime.Parse(from_date);

                //convert date
                double dt_unix = meth.DateTime_To_Unix(dt_from);
                call_url = day_url + "&toTs=" + dt_unix;
            }

            //get the json
            http   http_class = new http();
            string json       = http_class.jsonGet(day_url);

            //parse
            CryptoCompare_Coin_History_Template.RootObject coin_data;
            try
            {
                coin_data = JsonConvert.DeserializeObject <CryptoCompare_Coin_History_Template.RootObject>(json);
            }
            catch (Exception)
            {
                coin_data = new CryptoCompare_Coin_History_Template.RootObject();
                return(coin_data);
            }


            //return parse data
            return(coin_data);
        }
Esempio n. 4
0
        public void Pull_Coin_History_NO_DB(string coin_symbol, string currency, bool csv_save)
        {
            //variables
            methods meth = new methods();
            List <CryptoCompare_Coin_History_Template.Datum> data_obj = new List <CryptoCompare_Coin_History_Template.Datum>();
            bool              run         = true;
            DateTime          dt_earliest = DateTime.Now;
            CryptoCompare_API crypt_api   = new CryptoCompare_API();

            //get btc

            //get btc price
            List <CryptoCompare_Coin_History_Template.Datum> btc_price = Pull_Coin_History_Structure("BTC", "ZAR");

            while (run)
            {
                //get history
                CryptoCompare_Coin_History_Template.RootObject hist = new CryptoCompare_Coin_History_Template.RootObject();
                hist = crypt_api.GetCoinHistory(coin_symbol, currency, 2000, dt_earliest.ToString("yyyy-MM-dd"));

                //null check
                if (hist.Data == null)
                {
                    return;
                }

                //check null
                if (hist.Data.Count == 0)
                {
                    return;
                }

                //convert die datums
                DateTime date_early = meth.UnixTimeStampToDateTime(double.Parse(hist.TimeFrom.ToString()));
                DateTime date_last  = meth.UnixTimeStampToDateTime(double.Parse(hist.TimeTo.ToString()));

                //kyk if daar nog data is
                if (date_early == dt_earliest)
                {
                    break;
                }


                //set date
                for (int i = 0; i < hist.Data.Count; i++)
                {
                    //set date
                    hist.Data[i].s_date = meth.UnixTimeStampToDateTime(double.Parse(hist.Data[i].time.ToString()));

                    //add na die main list
                    data_obj.Add(hist.Data[i]);
                }

                //get the earliest date
                hist.Data.OrderBy(a => a.s_date);

                //moet weer run
                dt_earliest = hist.Data[0].s_date;

                //order die main list
                data_obj.OrderBy(a => a.s_date);

                //check if need to run again
                if (hist.Data.Count < 2000)
                {
                    break;
                }
            }

            //process history
            string csv        = "";
            string csv_header = "";

            if (coin_symbol == "BTC")
            {
                csv_header = "close,high,date,low,open,volume_from,volume_to,symbol";
            }
            else
            {
                csv_header = "close,high,date,low,open,volume_from,volume_to,symbol,btc_price";
            }

            //string csv_header = "close,high,date,low,open,volume_from,volume_to,symbol";
            //string csv_header = "close,high,date,low,open,volume_from,volume_to,symbol,btc_price";

            //add the header
            csv += csv_header + Environment.NewLine;

            //loop
            foreach (CryptoCompare_Coin_History_Template.Datum item in data_obj)
            {
                //get btc price
                var btc_p = btc_price.Where(a => a.s_date == item.s_date).FirstOrDefault();

                //unix convert
                DateTime dates = meth.UnixTimeStampToDateTime(item.time);


                //build csv line
                string csv_line = item.close + "," + item.high + "," + dates.ToString("yyyy-MM-dd") + "," + item.low + "," + item.open
                                  + "," + item.volumefrom + "," + item.volumeto + "," + coin_symbol + "," + btc_p.high;
                csv += csv_line + Environment.NewLine;
            }

            //save file
            if (csv_save)
            {
                System.IO.File.WriteAllText(@"C:\crypto_data\" + coin_symbol + ".csv", csv);
            }
        }