Scheduled Events

Estimated reading time: 2 min

Scheduled events allow you to trigger code to run at specific times of day. This happens regardless of your data events. The schedule API requires a date and time rule to specify when the event is fired.

Scheduled events need a DateRules and TimeRules pair to set a specific time. When the event is triggered, the action code block is executed.

DateRules Class Example Usage
On(year,month,day) DateRules.On(2013, 10, 7) Trigger an event on a specific date.
EveryDay(symbol) DateRules.EveryDay("ETHUSD") Trigger an event every day a specific symbol is trading.
EveryDay() DateRules.EveryDay() Trigger an event every day.
Every(days) DateRules.Every(DayOfWeek.Monday, DayOfWeek.Friday) Trigger an event on specific days during week.
MonthStart(daysOffset) DateRules.MonthStart() Trigger an event on the first day of each month plus offset (default is zero)
MonthStart(symbol, daysOffset) DateRules.MonthStart("ETHUSD") Trigger an event on the first tradable date of each month plus offset for the specified symbol of each month (default is zero)
MonthEnd(daysOffset) DateRules.MonthEnd() Trigger an event on the last day of each month minus offset (default is zero)
MonthEnd(symbol, daysOffset) DateRules.MonthEnd("ETHUSD") Trigger an event on the last tradable date of each month minus offset for the specified symbol of each month (default is zero)
WeekStart(daysOffset) DateRules.WeekStart() Trigger an event on the first day of each week plus offset (default is zero)
WeekStart(symbol, daysOffset) DateRules.WeekStart("ETHUSD") Trigger an event on the first tradable date of each week plus offset for the specified symbol of each month (default is zero)
WeekEnd(daysOffset) DateRules.WeekEnd() Trigger an event on the last day of each week minus offset (default is zero)
WeekEnd(symbol, daysOffset) DateRules.WeekEnd("ETHUSD") Trigger an event on the last tradable date of each week minus offset for the specified symbol of each month (default is zero)
TimeRules Class Example Usage
At(hour, min) TimeRules.At(13, 10) Trigger an event at a specific time of day (e.g. 13:10).
AfterMarketOpen(symbol, min) TimeRules.AfterMarketOpen("ETHUSD", 10) Trigger an event a few minutes after market open for a specific symbol.
BeforeMarketClose(symbol, min) TimeRules.BeforeMarketClose("ETHUSD", 10) Trigger an event a few minutes before close for a specific symbol.
Every(period) TimeRules.Every(TimeSpan.FromMinutes(10)) Trigger an event every period interval.
// Schedule an event to fire at a specific date/time
Schedule.On(DateRules.On(2013, 10, 7), TimeRules.At(13, 0), () =>
{
    Log("SpecificTime: Fired at : " + Time);
});

// Schedule an event to fire every trading day for a security
// The time rule here tells it to fire 10 minutes after ETHUSD's market open
Schedule.On(DateRules.EveryDay("BTCUSD"), TimeRules.AfterMarketOpen("BTCUSD", 10), () =>
{
    Log("EveryDay.BTCUSD 10 min after open: Fired at: " + Time);
});

// Schedule an event to fire every trading day for a security
// The time rule here tells it to fire 10 minutes before BTCUSD's market close
Schedule.On(DateRules.EveryDay("BTCUSD"), TimeRules.BeforeMarketClose("BTCUSD", 10), () =>
{
    Log("EveryDay.ETHUSD 10 min before close: Fired at: " + Time);
});

// Schedule an event to fire on certain days of the week
Schedule.On(DateRules.Every(DayOfWeek.Monday, DayOfWeek.Friday), TimeRules.At(12, 0), () =>
{
    Log("Mon/Fri at 12pm: Fired at: " + Time);
});
Was this article helpful?
Dislike 0
Views: 4