Exemple #1
0
func init() {
	tradingdays.DownloadCSV(true)
	log.Println("Init DownloadCSV.")
	csvcachetime.Set()
	flag.StringVar(&httpport, "http", ":59123", "HTTP service address (e.g., ':59123')")
	flag.Int64Var(&defaultcachetime, "csvcachetime", 21600, "CSV cache time.")
}
Exemple #2
0
// TradeOpen is "./open" page.
func TradeOpen(w http.ResponseWriter, req *http.Request) {
	var jsonStr []byte

	if data, err := strconv.ParseInt(req.FormValue("q"), 10, 64); err != nil {
		jsonStr, _ = json.Marshal(&errorJSON{Error: "Wrong date format"})
	} else {
		if csvcachetime.InCache(defaultcachetime) != true {
			tradingdays.DownloadCSV(true)
			csvcachetime.Set()
			log.Println("DownloadCSV.")
		}

		date := time.Unix(data, 0)
		jsonStr, _ = json.Marshal(&tradeJSON{
			Date: date.UTC(),
			Open: tradingdays.IsOpen(date.Year(), date.Month(), date.Day())})
	}
	w.Header().Set("Content-Type", "application/json")
	w.Write(jsonStr)
	Log(req)
}
Exemple #3
0
func init() {
	runtime.GOMAXPROCS(*ncpu)
	tradingdays.DownloadCSV(true)
}