deferring creating market open times.
This commit is contained in:
parent
b9f2a35a5d
commit
1584e50483
5 changed files with 36 additions and 38 deletions
14
date.go
14
date.go
|
@ -50,25 +50,23 @@ var (
|
||||||
_eastern *time.Location
|
_eastern *time.Location
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
|
||||||
// NYSEOpen is when the NYSE opens.
|
// NYSEOpen is when the NYSE opens.
|
||||||
NYSEOpen = Date.Time(9, 30, 0, 0, Date.Eastern())
|
func NYSEOpen() time.Time { return Date.Time(9, 30, 0, 0, Date.Eastern()) }
|
||||||
|
|
||||||
// NYSEClose is when the NYSE closes.
|
// NYSEClose is when the NYSE closes.
|
||||||
NYSEClose = Date.Time(16, 0, 0, 0, Date.Eastern())
|
func NYSEClose() time.Time { return Date.Time(16, 0, 0, 0, Date.Eastern()) }
|
||||||
|
|
||||||
// NASDAQOpen is when NASDAQ opens.
|
// NASDAQOpen is when NASDAQ opens.
|
||||||
NASDAQOpen = Date.Time(9, 30, 0, 0, Date.Eastern())
|
func NASDAQOpen() time.Time { return Date.Time(9, 30, 0, 0, Date.Eastern()) }
|
||||||
|
|
||||||
// NASDAQClose is when NASDAQ closes.
|
// NASDAQClose is when NASDAQ closes.
|
||||||
NASDAQClose = Date.Time(16, 0, 0, 0, Date.Eastern())
|
func NASDAQClose() time.Time { return Date.Time(16, 0, 0, 0, Date.Eastern()) }
|
||||||
|
|
||||||
// NYSEArcaOpen is when NYSEARCA opens.
|
// NYSEArcaOpen is when NYSEARCA opens.
|
||||||
NYSEArcaOpen = Date.Time(4, 0, 0, 0, Date.Eastern())
|
func NYSEArcaOpen() time.Time { return Date.Time(4, 0, 0, 0, Date.Eastern()) }
|
||||||
|
|
||||||
// NYSEArcaClose is when NYSEARCA closes.
|
// NYSEArcaClose is when NYSEARCA closes.
|
||||||
NYSEArcaClose = Date.Time(20, 0, 0, 0, Date.Eastern())
|
func NYSEArcaClose() time.Time { return Date.Time(20, 0, 0, 0, Date.Eastern()) }
|
||||||
)
|
|
||||||
|
|
||||||
// HolidayProvider is a function that returns if a given time falls on a holiday.
|
// HolidayProvider is a function that returns if a given time falls on a holiday.
|
||||||
type HolidayProvider func(time.Time) bool
|
type HolidayProvider func(time.Time) bool
|
||||||
|
|
24
date_test.go
24
date_test.go
|
@ -97,10 +97,10 @@ func TestNextMarketOpen(t *testing.T) {
|
||||||
|
|
||||||
weekend := time.Date(2016, 07, 23, 9, 31, 0, 0, Date.Eastern())
|
weekend := time.Date(2016, 07, 23, 9, 31, 0, 0, Date.Eastern())
|
||||||
|
|
||||||
assert.True(todayOpen.Equal(Date.NextMarketOpen(beforeOpen, NYSEOpen, Date.IsNYSEHoliday)))
|
assert.True(todayOpen.Equal(Date.NextMarketOpen(beforeOpen, NYSEOpen(), Date.IsNYSEHoliday)))
|
||||||
assert.True(tomorrowOpen.Equal(Date.NextMarketOpen(afterOpen, NYSEOpen, Date.IsNYSEHoliday)))
|
assert.True(tomorrowOpen.Equal(Date.NextMarketOpen(afterOpen, NYSEOpen(), Date.IsNYSEHoliday)))
|
||||||
assert.True(mondayOpen.Equal(Date.NextMarketOpen(afterFriday, NYSEOpen, Date.IsNYSEHoliday)))
|
assert.True(mondayOpen.Equal(Date.NextMarketOpen(afterFriday, NYSEOpen(), Date.IsNYSEHoliday)))
|
||||||
assert.True(mondayOpen.Equal(Date.NextMarketOpen(weekend, NYSEOpen, Date.IsNYSEHoliday)))
|
assert.True(mondayOpen.Equal(Date.NextMarketOpen(weekend, NYSEOpen(), Date.IsNYSEHoliday)))
|
||||||
|
|
||||||
assert.Equal(Date.Eastern(), todayOpen.Location())
|
assert.Equal(Date.Eastern(), todayOpen.Location())
|
||||||
assert.Equal(Date.Eastern(), tomorrowOpen.Location())
|
assert.Equal(Date.Eastern(), tomorrowOpen.Location())
|
||||||
|
@ -109,7 +109,7 @@ func TestNextMarketOpen(t *testing.T) {
|
||||||
testRegression := time.Date(2016, 07, 18, 16, 0, 0, 0, Date.Eastern())
|
testRegression := time.Date(2016, 07, 18, 16, 0, 0, 0, Date.Eastern())
|
||||||
shouldbe := time.Date(2016, 07, 19, 9, 30, 0, 0, Date.Eastern())
|
shouldbe := time.Date(2016, 07, 19, 9, 30, 0, 0, Date.Eastern())
|
||||||
|
|
||||||
assert.True(shouldbe.Equal(Date.NextMarketOpen(testRegression, NYSEOpen, Date.IsNYSEHoliday)))
|
assert.True(shouldbe.Equal(Date.NextMarketOpen(testRegression, NYSEOpen(), Date.IsNYSEHoliday)))
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestNextMarketClose(t *testing.T) {
|
func TestNextMarketClose(t *testing.T) {
|
||||||
|
@ -126,10 +126,10 @@ func TestNextMarketClose(t *testing.T) {
|
||||||
|
|
||||||
weekend := time.Date(2016, 07, 23, 9, 31, 0, 0, Date.Eastern())
|
weekend := time.Date(2016, 07, 23, 9, 31, 0, 0, Date.Eastern())
|
||||||
|
|
||||||
assert.True(todayClose.Equal(Date.NextMarketClose(beforeClose, NYSEClose, Date.IsNYSEHoliday)))
|
assert.True(todayClose.Equal(Date.NextMarketClose(beforeClose, NYSEClose(), Date.IsNYSEHoliday)))
|
||||||
assert.True(tomorrowClose.Equal(Date.NextMarketClose(afterClose, NYSEClose, Date.IsNYSEHoliday)))
|
assert.True(tomorrowClose.Equal(Date.NextMarketClose(afterClose, NYSEClose(), Date.IsNYSEHoliday)))
|
||||||
assert.True(mondayClose.Equal(Date.NextMarketClose(afterFriday, NYSEClose, Date.IsNYSEHoliday)))
|
assert.True(mondayClose.Equal(Date.NextMarketClose(afterFriday, NYSEClose(), Date.IsNYSEHoliday)))
|
||||||
assert.True(mondayClose.Equal(Date.NextMarketClose(weekend, NYSEClose, Date.IsNYSEHoliday)))
|
assert.True(mondayClose.Equal(Date.NextMarketClose(weekend, NYSEClose(), Date.IsNYSEHoliday)))
|
||||||
|
|
||||||
assert.Equal(Date.Eastern(), todayClose.Location())
|
assert.Equal(Date.Eastern(), todayClose.Location())
|
||||||
assert.Equal(Date.Eastern(), tomorrowClose.Location())
|
assert.Equal(Date.Eastern(), tomorrowClose.Location())
|
||||||
|
@ -144,7 +144,7 @@ func TestCalculateMarketSecondsBetween(t *testing.T) {
|
||||||
|
|
||||||
shouldbe := 5 * 6.5 * 60 * 60
|
shouldbe := 5 * 6.5 * 60 * 60
|
||||||
|
|
||||||
assert.Equal(shouldbe, Date.CalculateMarketSecondsBetween(start, end, NYSEOpen, NYSEClose, Date.IsNYSEHoliday))
|
assert.Equal(shouldbe, Date.CalculateMarketSecondsBetween(start, end, NYSEOpen(), NYSEClose(), Date.IsNYSEHoliday))
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestCalculateMarketSecondsBetween1D(t *testing.T) {
|
func TestCalculateMarketSecondsBetween1D(t *testing.T) {
|
||||||
|
@ -155,7 +155,7 @@ func TestCalculateMarketSecondsBetween1D(t *testing.T) {
|
||||||
|
|
||||||
shouldbe := 6 * 60 * 60
|
shouldbe := 6 * 60 * 60
|
||||||
|
|
||||||
assert.Equal(shouldbe, Date.CalculateMarketSecondsBetween(start, end, NYSEOpen, NYSEClose, Date.IsNYSEHoliday))
|
assert.Equal(shouldbe, Date.CalculateMarketSecondsBetween(start, end, NYSEOpen(), NYSEClose(), Date.IsNYSEHoliday))
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestCalculateMarketSecondsBetweenLTM(t *testing.T) {
|
func TestCalculateMarketSecondsBetweenLTM(t *testing.T) {
|
||||||
|
@ -165,7 +165,7 @@ func TestCalculateMarketSecondsBetweenLTM(t *testing.T) {
|
||||||
end := time.Date(2016, 07, 01, 9, 30, 0, 0, Date.Eastern())
|
end := time.Date(2016, 07, 01, 9, 30, 0, 0, Date.Eastern())
|
||||||
|
|
||||||
shouldbe := 253 * 6.5 * 60 * 60 //253 full market days since this date last year.
|
shouldbe := 253 * 6.5 * 60 * 60 //253 full market days since this date last year.
|
||||||
assert.Equal(shouldbe, Date.CalculateMarketSecondsBetween(start, end, NYSEOpen, NYSEClose, Date.IsNYSEHoliday))
|
assert.Equal(shouldbe, Date.CalculateMarketSecondsBetween(start, end, NYSEOpen(), NYSEClose(), Date.IsNYSEHoliday))
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestDateNextHour(t *testing.T) {
|
func TestDateNextHour(t *testing.T) {
|
||||||
|
|
|
@ -96,7 +96,7 @@ func (mhr MarketHoursRange) GetHolidayProvider() HolidayProvider {
|
||||||
// GetMarketOpen returns the market open time.
|
// GetMarketOpen returns the market open time.
|
||||||
func (mhr MarketHoursRange) GetMarketOpen() time.Time {
|
func (mhr MarketHoursRange) GetMarketOpen() time.Time {
|
||||||
if mhr.MarketOpen.IsZero() {
|
if mhr.MarketOpen.IsZero() {
|
||||||
return NYSEOpen
|
return NYSEOpen()
|
||||||
}
|
}
|
||||||
return mhr.MarketOpen
|
return mhr.MarketOpen
|
||||||
}
|
}
|
||||||
|
@ -104,7 +104,7 @@ func (mhr MarketHoursRange) GetMarketOpen() time.Time {
|
||||||
// GetMarketClose returns the market close time.
|
// GetMarketClose returns the market close time.
|
||||||
func (mhr MarketHoursRange) GetMarketClose() time.Time {
|
func (mhr MarketHoursRange) GetMarketClose() time.Time {
|
||||||
if mhr.MarketClose.IsZero() {
|
if mhr.MarketClose.IsZero() {
|
||||||
return NYSEClose
|
return NYSEClose()
|
||||||
}
|
}
|
||||||
return mhr.MarketClose
|
return mhr.MarketClose
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,8 +13,8 @@ func TestMarketHoursRangeGetDelta(t *testing.T) {
|
||||||
r := &MarketHoursRange{
|
r := &MarketHoursRange{
|
||||||
Min: time.Date(2016, 07, 19, 9, 30, 0, 0, Date.Eastern()),
|
Min: time.Date(2016, 07, 19, 9, 30, 0, 0, Date.Eastern()),
|
||||||
Max: time.Date(2016, 07, 22, 16, 00, 0, 0, Date.Eastern()),
|
Max: time.Date(2016, 07, 22, 16, 00, 0, 0, Date.Eastern()),
|
||||||
MarketOpen: NYSEOpen,
|
MarketOpen: NYSEOpen(),
|
||||||
MarketClose: NYSEClose,
|
MarketClose: NYSEClose(),
|
||||||
HolidayProvider: Date.IsNYSEHoliday,
|
HolidayProvider: Date.IsNYSEHoliday,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -27,8 +27,8 @@ func TestMarketHoursRangeTranslate(t *testing.T) {
|
||||||
r := &MarketHoursRange{
|
r := &MarketHoursRange{
|
||||||
Min: time.Date(2016, 07, 18, 9, 30, 0, 0, Date.Eastern()),
|
Min: time.Date(2016, 07, 18, 9, 30, 0, 0, Date.Eastern()),
|
||||||
Max: time.Date(2016, 07, 22, 16, 00, 0, 0, Date.Eastern()),
|
Max: time.Date(2016, 07, 22, 16, 00, 0, 0, Date.Eastern()),
|
||||||
MarketOpen: NYSEOpen,
|
MarketOpen: NYSEOpen(),
|
||||||
MarketClose: NYSEClose,
|
MarketClose: NYSEClose(),
|
||||||
HolidayProvider: Date.IsNYSEHoliday,
|
HolidayProvider: Date.IsNYSEHoliday,
|
||||||
Domain: 1000,
|
Domain: 1000,
|
||||||
}
|
}
|
||||||
|
@ -56,10 +56,10 @@ func TestMarketHoursRangeGetTicks(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
ra := &MarketHoursRange{
|
ra := &MarketHoursRange{
|
||||||
Min: Date.On(NYSEOpen, Date.Date(2016, 07, 18, Date.Eastern())),
|
Min: Date.On(NYSEOpen(), Date.Date(2016, 07, 18, Date.Eastern())),
|
||||||
Max: Date.On(NYSEClose, Date.Date(2016, 07, 22, Date.Eastern())),
|
Max: Date.On(NYSEClose(), Date.Date(2016, 07, 22, Date.Eastern())),
|
||||||
MarketOpen: NYSEOpen,
|
MarketOpen: NYSEOpen(),
|
||||||
MarketClose: NYSEClose,
|
MarketClose: NYSEClose(),
|
||||||
HolidayProvider: Date.IsNYSEHoliday,
|
HolidayProvider: Date.IsNYSEHoliday,
|
||||||
Domain: 1024,
|
Domain: 1024,
|
||||||
}
|
}
|
||||||
|
|
|
@ -21,7 +21,7 @@ func TestSequenceMarketHours(t *testing.T) {
|
||||||
assert := assert.New(t)
|
assert := assert.New(t)
|
||||||
|
|
||||||
today := time.Date(2016, 07, 01, 12, 0, 0, 0, Date.Eastern())
|
today := time.Date(2016, 07, 01, 12, 0, 0, 0, Date.Eastern())
|
||||||
mh := Sequence.MarketHours(today, today, NYSEOpen, NYSEClose, Date.IsNYSEHoliday)
|
mh := Sequence.MarketHours(today, today, NYSEOpen(), NYSEClose(), Date.IsNYSEHoliday)
|
||||||
assert.Len(mh, 8)
|
assert.Len(mh, 8)
|
||||||
assert.Equal(Date.Eastern(), mh[0].Location())
|
assert.Equal(Date.Eastern(), mh[0].Location())
|
||||||
}
|
}
|
||||||
|
@ -29,7 +29,7 @@ func TestSequenceMarketHours(t *testing.T) {
|
||||||
func TestSequenceMarketQuarters(t *testing.T) {
|
func TestSequenceMarketQuarters(t *testing.T) {
|
||||||
assert := assert.New(t)
|
assert := assert.New(t)
|
||||||
today := time.Date(2016, 07, 01, 12, 0, 0, 0, Date.Eastern())
|
today := time.Date(2016, 07, 01, 12, 0, 0, 0, Date.Eastern())
|
||||||
mh := Sequence.MarketHourQuarters(today, today, NYSEOpen, NYSEClose, Date.IsNYSEHoliday)
|
mh := Sequence.MarketHourQuarters(today, today, NYSEOpen(), NYSEClose(), Date.IsNYSEHoliday)
|
||||||
assert.Len(mh, 4)
|
assert.Len(mh, 4)
|
||||||
assert.Equal(9, mh[0].Hour())
|
assert.Equal(9, mh[0].Hour())
|
||||||
assert.Equal(30, mh[0].Minute())
|
assert.Equal(30, mh[0].Minute())
|
||||||
|
|
Loading…
Reference in a new issue