Ejemplo n.º 1
0
// Crawl 获取公司每天的报价
func (yahoo YahooFinance) Crawl(_market market.Market, company market.Company, date time.Time) (*market.CompanyDailyQuote, error) {

	// 起止时间
	start := time.Date(date.Year(), date.Month(), date.Day(), 0, 0, 0, 0, date.Location())
	end := start.AddDate(0, 0, 1)

	pattern := "https://finance-yql.media.yahoo.com/v7/finance/chart/%s?period2=%d&period1=%d&interval=1m&indicators=quote&includeTimestamps=true&includePrePost=true&events=div%%7Csplit%%7Cearn&corsDomain=finance.yahoo.com"
	url := fmt.Sprintf(pattern, _market.YahooQueryCode(company), end.Unix(), start.Unix())

	// 查询Yahoo财经接口,返回股票分时数据
	str, err := net.DownloadStringRetry(url, yahoo.RetryCount(), yahoo.RetryInterval())
	if err != nil {
		return nil, err
	}

	// 解析Json
	quote := &YahooQuote{}
	err = json.Unmarshal([]byte(str), &quote)
	if err != nil {
		return nil, err
	}

	// 校验
	err = yahoo.valid(quote)
	if err != nil {
		return nil, err
	}

	// 解析
	return yahoo.parse(_market, company, date, quote)
}
Ejemplo n.º 2
0
// objectKey 存储路径
func (s AliyunOSS) objectKey(_market market.Market, date time.Time) string {
	return fmt.Sprintf("%s%s/%s.mdq", s.config.KeyRoot, date.Format("2006/01/02"), strings.ToLower(_market.Name()))
}
Ejemplo n.º 3
0
// savePath 保存到S3的路径
func (s AmazonS3) savePath(_market market.Market, date time.Time) string {
	return fmt.Sprintf("%s%s/%s.mdq", s.config.KeyRoot, date.Format("2006/01/02"), strings.ToLower(_market.Name()))
}