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; }
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; }
protected virtual List<dateData> DoGetHistory(string code4src, date date_from, date date_to) { return new List<dateData>(); }
private void SetCell(string code, date date_from, date date_to) { // Fetch the cell feed of the worksheet. CellQuery cellQuery = new CellQuery(worksheet.CellFeedLink); CellFeed cellFeed = service.Query(cellQuery); CellEntry cell1st = (CellEntry)cellFeed.Entries [0]; cell1st.InputValue = "=GoogleFinance(\"" + code + "\", \"ALL\", \"" + date_from.ToString() + "\", \"" + date_to.ToString() + "\", \"DAILY\")"; cell1st.Update(); Output.Log("Get From Google sheet " + cell1st.InputValue); //Console.Write(" cnt : " + cellFeed.Entries.Count); }
public List<dateData> GetHistory(Quote q, date date_from, date date_to) { string code = _src.GetCode(q); Output.Log("update quote " + q.Describe + " (desn't have data " + date_from + " to " + date_to + ")"); return DoGetHistory(code, date_from, date_to); }