Beispiel #1
0
        public int GetRoots()
        {
            SqlClientBuilder sbMain = DBConn.GetConn();

            Hashtable htParms = new Hashtable();

            htParms.Add("@smallset", intSmallSet);
            DataTable dtCoinsForRoots = sbMain.GetData("get_coinlist_for_roots", htParms, false);

            if (sbMain.ErrNum > 0)
            {
                intErr = sbMain.ErrNum;
                strErr = sbMain.ErrMes;
                return(intErr);
            }

            CoinRoot cRoot = null;

            foreach (DataRow dr in dtCoinsForRoots.Rows)
            {
                cRoot = GetCoinGithubRoot(dr[0].ToString(), dr[1].ToString(), dr[2].ToString());
                lstCoinRoots.Add(cRoot);
                Thread.Sleep(200);
            }

            return(intErr);
        }
Beispiel #2
0
        public int LoadRoots()
        {
            intErr = 0; strErr = "";

            SqlClientBuilder sbMain = DBConn.GetConn();

            Hashtable htPartms = new Hashtable();
            Hashtable htParms  = new Hashtable();

            htParms.Add("@table", "devroot");
            htParms.Add("@filepath", AppDomain.CurrentDomain.BaseDirectory + "rootslist.txt");
            htParms.Add("@fieldbreak", DL);
            htParms.Add("@rowbreak", "\n");
            htParms.Add("@truncate", intTruncate);
            sbMain.SetData("load_table", htParms, true);
            if (sbMain.ErrNum > 0)
            {
                intErr = sbMain.ErrNum;
                strErr = sbMain.ErrMes;
                sbMain.ConnClose();
            }

            sbMain.ConnClose();
            return(intErr);
        }
Beispiel #3
0
 public DbOper()
 {
     ConnMain = DBConn.GetConn();
     if (DBConn.ErrNum > 0)
     {
         intErr = DBConn.ErrNum;
         strErr = DBConn.ErrMes;
     }
 }
Beispiel #4
0
        //public static string ConnUsed = "capcoin";

        public static SqlClientBuilder GetConn()
        {
            if (sqMain == null)
            {
                string conn = ConfigurationManager.AppSettings[ConnUsed];
                sqMain = new SqlClientBuilder(ConfigurationManager.AppSettings[conn], true);
                if (sqMain.ErrNum > 0)
                {
                    intErr = sqMain.ErrNum; strErr = sqMain.ErrMes;
                }
            }

            return(sqMain);
        }
Beispiel #5
0
        public void LoadData()
        {
            string strDataFile = AppDomain.CurrentDomain.BaseDirectory + "coincapio.dat";
            string strLogFile  = AppDomain.CurrentDomain.BaseDirectory + "coincap.log";
            string DL          = "|";
            //** Get IBM Date
            CommUtil cm        = new CommUtil();
            string   strDt     = cm.GetDateInt();
            string   strTimeHR = DateTime.Now.TimeOfDay.Hours.ToString();
            string   strTimeMN = DateTime.Now.TimeOfDay.Minutes.ToString();

            if (strTimeHR.Equals("0"))
            {
                strTimeHR = "";
            }
            if (Int16.Parse(strTimeMN) < 10)
            {
                strTimeMN = "0" + strTimeMN;
            }
            string strTm = strTimeHR + strTimeMN;

            DateTime dtDateTime = new DateTime(1970, 1, 1, 0, 0, 0, 0, System.DateTimeKind.Utc);
            //DateTime dtDateTime = new DateTime(2017, 5, 6, 0, 0, 0, 0, System.DateTimeKind.Utc);
            DateTime dtDateTimeAdj = dtDateTime.AddSeconds(1500176348).ToLocalTime();
            string   strUpdt       = GetStandardDt(dtDateTime);

            //** Get Json data
            //string input = "https://api.coinmarketcap.com/v1/ticker/";
            //string input = "https://api.coinmarketcap.com/v1/ticker/?limit=2000";
            string    input     = "http://coincap.io/front";
            WebClient client    = new WebClient();
            string    jsonInput = client.DownloadString(input);

            Dictionary <string, string>[] ccurData = JsonConvert.DeserializeObject <Dictionary <string, string>[]>(jsonInput);

            StringBuilder sb      = new StringBuilder();
            string        strLine = "";
            string        strElem = "";

            //int intUTCSec = 0;

            for (int i = 0; i < ccurData.Length; i++)
            {
                strLine = "";
                strLine = strDt + DL + strTm + DL + ccurData[i]["long"] + DL + ccurData[i]["short"] + DL;

                strElem = ccurData[i]["price"];
                if (strElem == null)
                {
                    strElem = "0";
                }
                decimal dec = 0;
                if (!Decimal.TryParse(strElem, out dec))
                {
                    strElem = "0";
                }
                strLine += strElem + DL;

                strElem = ccurData[i]["mktcap"];
                if (strElem == null)
                {
                    strElem = "0";
                }
                else
                {
                    strElem = GetFormattedElem(strElem);
                }
                strLine += strElem + DL;

                strElem = ccurData[i]["supply"];
                if (strElem == null)
                {
                    strElem = "0";
                }
                else
                {
                    strElem = GetFormattedElem(strElem);
                }
                strLine += strElem + DL;

                strElem = ccurData[i]["volume"];
                if (strElem == null)
                {
                    strElem = "0";
                }
                else
                {
                    strElem = GetFormattedElem(strElem);
                }

                strLine += strElem + "\n";

                //strElem = ccurData[i]["total_supply"];
                //if (strElem == null) strElem = "0";
                //else strElem = GetFormattedElem(strElem);
                //strLine += strElem + DL;

                //strElem = ccurData[i]["percent_change_1h"];
                //if (strElem == null) strElem = "0";
                //strLine += strElem + DL;

                //strElem = ccurData[i]["percent_change_24h"];
                //if (strElem == null) strElem = "0";
                //strLine += strElem + DL;

                //strElem = ccurData[i]["percent_change_7d"];
                //if (strElem == null) strElem = "0";
                //strLine += strElem + DL;

                //intUTCSec = Int32.Parse(ccurData[i]["last_updated"]);
                //dtDateTimeAdj = dtDateTime.AddSeconds(intUTCSec).ToLocalTime();
                //strUpdt = GetStandardDt(dtDateTimeAdj);

                //strLine += strUpdt + "\n";
                sb.Append(strLine);
            }

            StreamWriter st = new StreamWriter(strLogFile, true);

            st.WriteLine("***************  COINCAP-IO LOG " + strDt + " at " + strTm + " ***************************");

            try { File.WriteAllText(strDataFile, sb.ToString()); }
            catch (Exception ex)
            {
                st.WriteLine(ex.Message);
                st.Close();
                return;
            }


            SqlClientBuilder sq = new SqlClientBuilder(ConfigurationManager.AppSettings["conn"], false);

            if (sq.ErrNum > 0)
            {
                st.WriteLine(sq.ErrMes);
                return;
            }

            Hashtable htParms = new Hashtable();

            htParms.Add("@table", "coincapio");
            htParms.Add("@filepath", strDataFile);
            htParms.Add("@fieldbreak", DL);
            htParms.Add("@rowbreak", "\n");
            htParms.Add("@truncate", 0);
            sq.SetData("load_table", htParms, false);
            if (sq.ErrNum > 0)
            {
                st.WriteLine(sq.ErrMes);
                st.Close();
                return;
            }

            //** Add the coins that do not exist in info table yet
            sq.SetData("refresh_coincapinfo", true);
            if (sq.ErrNum > 0)
            {
                st.WriteLine(sq.ErrMes);
                st.Close();
                return;
            }

            st.WriteLine("Sucsess - creating file and loading to database with " + ccurData.Length.ToString() + " records");
            st.Close();
        }