Ejemplo n.º 1
0
        public List<dateData> LoadHistory_DB(Quote q)
        {
            List<dateData> dataList = new List<dateData>();
            string tblNm = GetTableNameHistory_DB(q);
            if (!TableExist(tblNm))
                return dataList;

            SqliteConnection conn = null;
            string sql = "";

            try {
                conn = new SqliteConnection(souce);
                conn.Open();
                SqliteCommand cmd = conn.CreateCommand();
                sql = "select date, volume, open, high, low, close from " + tblNm + " order by date desc;";
                cmd.CommandText = sql;
                SqliteDataReader rdr = cmd.ExecuteReader();

                while (rdr.Read()) {
                    dateData dd = new dateData();
                    dd._date = rdr.GetInt64(0);
                    dd._indic._volume = rdr.GetInt64(1);
                    dd._price._open = rdr.GetDouble(2);
                    dd._price._high = rdr.GetDouble(3);
                    dd._price._low = rdr.GetDouble(4);
                    dd._price._close = rdr.GetDouble(5);
                    dataList.Add(dd);
                }
            } catch (Exception e) {
                Output.LogException(" sql (" + sql + ") error : " + e.Message);
            }
            if (conn != null)
                conn.Close();
            return dataList;
        }
Ejemplo n.º 2
0
        protected override List<dateData> DoGetHistory(string  code4src, date date_from, date date_to)
        {
            Login_UsrPwd();
            ConnectTable();
            List<dateData> list = new List<dateData>();

            try {
                SetCell(code4src, date_from, date_to);
                ListFeed listFeed = GetList();

                foreach (ListEntry row in listFeed.Entries) {
                    string time = row.Elements [0].Value;
                    string open = row.Elements [1].Value;
                    string close = row.Elements [2].Value;
                    string high = row.Elements [3].Value;
                    string low = row.Elements [4].Value;
                    string vol = row.Elements [5].Value;

                    Output.Log(code4src + "|" + time + "|" + open + "|" + close + "|" + high + "|" + low + "|" + vol);

                    try {
                        dateData dd = new dateData();
                        string[] date_time = time.Split(" ".ToCharArray());
                        dd._date = Util.GetUnixTimeStamp(date_time [0]);
                        dd._indic._volume = long.Parse(vol);
                        dd._price._open = double.Parse(open);
                        dd._price._high = double.Parse(high);
                        dd._price._low = double.Parse(low);
                        dd._price._close = double.Parse(close);
                        list.Add(dd);
                    } catch (Exception e) {
                        string desc = code4src + " data from web format incorrect : " + e.Message;
                        Output.Log(desc);
                        Output.LogException(desc);
                    }
                }

                Output.Log("YAHOO get history " + code4src + " from : " + date_from + " to : " + date_to);
            } catch (Exception e) {
                Output.LogException("get From Google failed : " + code4src + " " + date_from + " - " + date_to + " msg : " + e.Message);
            }

            return list;
        }
Ejemplo n.º 3
0
        protected override List<dateData> DoGetHistory(string  code4src, date date_from, date date_to)
        {
            string description = code4src + " from : " + date_from + " to : " + date_to;

            List<dateData> list = new List<dateData>();
            //long dateFrom = Util.GetUnixTimeStamp(date_from);
            string URI = "";

            try {

                if (date_from.year == 0 || date_to.year == 0) {
                    //Output.Log("update quote " + code4src + " (desn't have all datas data)");
                    URI = @"http://ichart.finance.yahoo.com/table.csv?s=" + code4src;
                } else {
                    //Output.Log("update quote " + code4src + " (desn't have data " + date_from + " to " + date_to + ")");
                    URI = @"http://ichart.finance.yahoo.com/table.csv?s=" + code4src
                        + "&a=" + (date_from.month - 1)
                        + "&b=" + date_from.day
                        + "&c=" + date_from.year
                        + "&d=" + (date_to.month - 1)
                        + "&e=" + date_to.day
                        + "&f=" + date_to.year;
                }

                //File.WriteAllText("code" + code4src + ".txt", content);
                string content = WebUtil.Static.FetchWebPage(URI);

                string[] lines = content.Split("\n".ToCharArray());
                if(lines.Length <= 2){
                    Output.Log(description + " NO data, ignore content : \"" + content + "\"");
                    return list;
                }

                //titles:
                lines[0] = "";

                foreach (string line in lines) {
                    if(line.Length == 0) continue;
                    string[] values = line.Split(",".ToCharArray());
                    if (values.Length >= 5) {
                        dateData dt = new dateData();
                        dt._date = Util.GetUnixTimeStamp(values [0]);
                        dt._price._open = double.Parse(values [1]);
                        dt._price._high = double.Parse(values [2]);
                        dt._price._low = double.Parse(values [3]);
                        dt._price._close = double.Parse(values [4]);
                        dt._indic._volume = long.Parse(values [5]);
                        list.Add(dt);
                    }else{
                        Output.Log("format error, column less than 5 : \"" + line+ "\"");
                    }
                }

                Output.Log("YAHOO get history " + description);

            } catch (Exception e) {
                Output.LogException("Get history Error. code : " + description + "(msg : " + e.Message);
            }

            return list;
        }