Documentation ¶
Index ¶
- Constants
- Variables
- func LoadMarketHolidays()
- type MarketHours
- type MarketStatus
- func (ms *MarketStatus) EarlyClose(t time.Time) int
- func (ms *MarketStatus) IsMarketDay(t time.Time) bool
- func (ms *MarketStatus) IsMarketHoliday(t time.Time) bool
- func (ms *MarketStatus) IsMarketOpen(t time.Time) bool
- func (ms *MarketStatus) NextFirstTradingDayOfMonth(t time.Time) time.Time
- func (ms *MarketStatus) NextFirstTradingDayOfWeek(t time.Time) time.Time
- func (ms *MarketStatus) NextLastTradingDayOfMonth(t time.Time) time.Time
- func (ms *MarketStatus) NextLastTradingDayOfWeek(t time.Time) time.Time
- type TradeCron
Constants ¶
const ( AtOpen = "@open" AtClose = "@close" AtWeekBegin = "@weekbegin" AtWeekEnd = "@weekend" AtMonthBegin = "@monthbegin" AtMonthEnd = "@monthend" )
Variables ¶
var ( ErrConflictingModifiers = errors.New("malformed schedule; conflicting modifiers combined") ErrFieldOutOfBounds = errors.New("time field out of range") ErrMalformedTimeSpec = errors.New("time spec malformed") ErrUnknownModifier = errors.New("unknown modifier specified") )
var ( RegularHours = MarketHours{ Open: 930, Close: 1600, } ExtendedHours = MarketHours{ Open: 700, Close: 2000, } )
Functions ¶
func LoadMarketHolidays ¶ added in v0.5.0
func LoadMarketHolidays()
Types ¶
type MarketHours ¶
type MarketStatus ¶
type MarketStatus struct {
// contains filtered or unexported fields
}
func NewMarketStatus ¶
func NewMarketStatus(hours *MarketHours) *MarketStatus
LoadMarketHolidays retrieves market holidays from the database
func (*MarketStatus) EarlyClose ¶
func (ms *MarketStatus) EarlyClose(t time.Time) int
EarlyClose returns close time of an early close market day, e.g. 1300
func (*MarketStatus) IsMarketDay ¶
func (ms *MarketStatus) IsMarketDay(t time.Time) bool
IsMarketOpen returns true if the specified date is a valid trading day (i.e. not a market holiday or weekend)
func (*MarketStatus) IsMarketHoliday ¶
func (ms *MarketStatus) IsMarketHoliday(t time.Time) bool
IsMarketHoliday returns true if the specified date is a market holiday
func (*MarketStatus) IsMarketOpen ¶
func (ms *MarketStatus) IsMarketOpen(t time.Time) bool
IsMarketOpen returns true if the specified time is during market hours (i.e. not a market holiday or weekend)
func (*MarketStatus) NextFirstTradingDayOfMonth ¶
func (ms *MarketStatus) NextFirstTradingDayOfMonth(t time.Time) time.Time
NextFirstTradingDayOfMonth returns the first trading day of the next month
func (*MarketStatus) NextFirstTradingDayOfWeek ¶
func (ms *MarketStatus) NextFirstTradingDayOfWeek(t time.Time) time.Time
NextFirstTradingDayOfWeek returns the first trading day of the week.
func (*MarketStatus) NextLastTradingDayOfMonth ¶
func (ms *MarketStatus) NextLastTradingDayOfMonth(t time.Time) time.Time
NextLastTradingDayOfMonth returns the last trading day of the specified month; where a trading day is defined as a day the market is open
func (*MarketStatus) NextLastTradingDayOfWeek ¶
func (ms *MarketStatus) NextLastTradingDayOfWeek(t time.Time) time.Time
NextLastTradingDayOfWeek returns the next last trading day of week
type TradeCron ¶
type TradeCron struct { Schedule cron.Schedule ScheduleString string TimeSpec string TimeFlag string DateFlag string // contains filtered or unexported fields }
func New ¶
func New(cronSpec string, hours MarketHours) (*TradeCron, error)
TradeCron enables market aware scheduling. It supports schedules via the standard CRON format of: Minutes(Min) Hours(H) DayOfMonth(DoM) Month(M) DayOfWeek(DoW) See: https://en.wikipedia.org/wiki/Cron
'*' wildcards only execute during market open hours
Additional market-aware modifiers are supported:
@open - Run at market open; replaces Minute and Hour field e.g., @open * * * @close - Run at market close; replaces Minute and Hour field @weekbegin - Run on first trading day of week; replaces DayOfMonth field @weekend - Run on last trading day of week; replaces DayOfMonth field @monthbegin - Run at market open or timespec on first trading day of month @monthend - Run at market close or timespec on last trading day of month
Examples:
- every 5 minutes: */5 * * * *
- market open on tuesdays: @open * * 2
- 15 minutes after market open: 15 @open * * *
- market open on first trading day of week: @weekbegin
- market open on last trading day of month: @open @monthend
func (*TradeCron) IsTradeDay ¶
IsTradeDay evaluates the given date against the schedule and returns true if the date falls on a trading day according to the schedule. The time portion of the schedule is ignored when evaluating this function