guanaco
Version:
A cute and cuddly cryptocurrency quant trading engine in TypeScript.
64 lines (63 loc) • 3.37 kB
TypeScript
import { ScheduledTask } from 'node-cron';
import { DayOfMonth, DayOfWeek, Hour, Interval, Minute, Month, Range, Second } from '../models';
/**
* Function that can be run in the scheduler.
*/
declare type SchedulerFunction = () => void;
/**
* Schedule the task every ___________. i.e. 'every minute'
*/
export declare type ScheduleWildcard = '*';
/**
* Schedule market actions ahead of time.
*/
export declare class Scheduler {
static WILDCARD: ScheduleWildcard;
/**
* Run a function on a second-by-second basis.
* @param callback The function to call.
* @param every The interval, in seconds.
*/
static secondInterval(callback: SchedulerFunction, every: number): ScheduledTask;
/**
* Run a function in a minutely interval.
* @param callback The function to call.
* @param every The interval, in minutes.
*/
static minuteInterval(callback: SchedulerFunction, every: number): ScheduledTask;
/**
* Run a function in an hourly interval.
* @param callback The function to call.
* @param every The interval, in hours.
*/
static hourInterval(callback: SchedulerFunction, every: number): ScheduledTask;
/**
* Run a function on a daily basis.
* @param callback The function to call.
* @param every The interval, in number of days.
*/
static dailyInterval(callback: SchedulerFunction, every: number): ScheduledTask;
/**
* Schedule a function called precisely at a certain time, range, or interval.
* @param callback The function to call.
* @param dayOfWeek The day of the week to call the function. Leave undefined or null for every day of the week.
* @param month The month to call the function. Leave undefined or null for every month of the year.
* @param day The day of the month to call the function. Leave undefined or null for every day of the month.
* @param hour The hour of the day to call the function. Leave undefined or null for every hour of the day.
* @param minute The minute of the hour to call the function. Leave undefined or null for every minute of every hour.
* @param second The second of the minute to call the function. Leave undefined or null for every second of every minute.
*/
static schedule(callback: SchedulerFunction, dayOfWeek?: DayOfWeek | Interval<Range<DayOfWeek> | DayOfWeek | ScheduleWildcard> | Range<DayOfWeek> | ScheduleWildcard | null, month?: Month | Interval<Range<Month> | Month | ScheduleWildcard> | Range<Month> | ScheduleWildcard | null, day?: DayOfMonth | Interval<Range<DayOfMonth> | DayOfMonth | ScheduleWildcard> | Range<DayOfMonth> | ScheduleWildcard | null, hour?: Hour | Interval<Range<Hour> | Hour | ScheduleWildcard> | Range<Hour> | ScheduleWildcard | null, minute?: Minute | Interval<Range<Minute> | Minute | ScheduleWildcard> | Range<Minute> | ScheduleWildcard | null, second?: Second | Interval<Range<Second> | Second | ScheduleWildcard> | Range<Second> | ScheduleWildcard | null): ScheduledTask;
/**
* Validate a CRON expression.
* @param cronExpression The CRON expression to validate.
*/
private static validate;
/**
* Schedule a valid CRON expression.
* @param callback The function to call.
* @param cronExpression The CRON expression to perform.
*/
private static perform;
}
export {};