Example #1
0
// a quick comparison function for MarkitChartAPIResponses
// currently this just checks that the dates and positions values are the same
func CompareMarkitChartAPIResponses(r *stock.MarkitChartAPIResponse, l *stock.MarkitChartAPIResponse) bool {
	if len(r.Dates) != len(l.Dates) ||
		len(r.Positions) != len(l.Positions) ||
		len(r.Dates) != len(r.Positions) {
		return false
	}

	var rD, lD stock.ISOTime = r.Dates[0], l.Dates[0]
	var rP, lP = r.Positions[0], l.Positions[0]
	for i := 1; rD.Year() == lD.Year() && rD.YearDay() == lD.YearDay() && rP == lP; i++ {
		if i >= len(r.Dates) {
			return true
		}
		rD, lD = r.Dates[i], l.Dates[i]
		rP, lP = r.Positions[i], l.Positions[i]
	}
	return false
}
Example #2
0
func makeISOTimeArray(startDate time.Time, endDate time.Time) []stock.ISOTime {
	var timeArray []stock.ISOTime

	// Make sure startDate and endDate are in 2011/2012, those are the only years
	// that we have holiday information for. If not, return empy.
	if !(startDate.Year() == 2011 || startDate.Year() == 2012) && (endDate.Year() == 2011 || endDate.Year() == 2012) {
		return timeArray
	}

	var day stock.ISOTime = stock.ISOTime{startDate.AddDate(0, 0, -1)}
	for day.Before(endDate) {
		day = stock.ISOTime{day.AddDate(0, 0, 1)}

		// market is not open on Saturday or Sunday
		if day.Weekday() == time.Weekday(0) ||
			day.Weekday() == time.Weekday(6) {
			continue
		}

		// market is not open on certain holidays
		isHoliday := false
		for _, holiday := range Holidays20112012 {
			if day.Year() == holiday.Year() && day.YearDay() == holiday.YearDay() {
				isHoliday = true
				break
			}
		}

		if !isHoliday {
			timeArray = append(timeArray, day)
		}
	}
	return timeArray
}