UNPKG

@atomic-utils/time

Version:
224 lines (223 loc) 8.15 kB
export type CsoEvent = 'dlcExpiry' | 'dlcAttestation' | 'rolloverOpen' | 'newEntryOpen' | 'newEntryClosed' | 'tradingOpen' | 'halfMonthEntryClosed' | 'tradingOpenHalfMonth'; export type CsoPeriod = 'weekly' | 'monthly' | 'bimonthly'; export type CsoLength = 'full-month' | 'half-month' | 'one-and-a-half-months' | 'two-months'; export type CsoEventIdType = 'period' | 'split' | 'unsplit'; export declare const DLC_EXPIRY_LEN = 7; export declare const DLC_ATTESTATION_LEN = 1; export declare const ROLLOVER_OPEN_LEN = 24; export declare const NEW_ENTRY_OPEN_LEN = 36; export declare const NEW_ENTRY_CLOSED_LEN = 8; export declare const HALF_MONTH_ENTRY_CLOSED_LEN = 6; export declare const TRADING_OPEN_HALF_MONTH_LEN = 334; export declare const STR_DATE_REGEX: RegExp; /** * getLastFridayInMonth * * Pass in year and month and return Date object with * last friday of the month * * @param {number} y Year in full format (i.e. 2022) * @param {number} m Month NOT 0-indexed (i.e. 1 => January) * @returns {Date} last friday of month */ export declare const getLastFridayInMonth: (y: number, m: number) => Date; /** * getCurrentCycleMaturityDate * * @param {Date} t_ current time * @returns {Date} last friday in current cycle */ export declare const getCurrentCycleMaturityDate: (t_: Date) => Date; /** * getNextCycleMaturityDate * * @param {Date} t_ current time * @returns {Date} last friday in next cycle */ export declare const getNextCycleMaturityDate: (t_: Date) => Date; /** * getPreviousCycleMaturityDate * * @param {Date} t_ current time * @returns {Date} last friday in previous cycle */ export declare const getPreviousCycleMaturityDate: (t_: Date) => Date; export declare const getCsoEventDates: (t_: Date) => CsoEventDates; /** * getCsoEvent * * @param {Date} t_ current time * @returns {CsoEvent} which cso event the date provided is within */ export declare const getCsoEvent: (t_: Date) => CsoEvent; /** * getCsoStartAndEndDate * * Pass in current time and get start and end date of event that user can enter into * immediately * * @param t_ current time * @returns {StartEndDates} start and end dates of the CSO event */ export declare const getCsoStartAndEndDate: (t_: Date, forceExtendedPeriod?: boolean) => StartEndDates; /** * getUpcomingFriday * * From the current time, get the upcoming Friday. * If the current time is Friday and is after 8am UTC, then return the next week's Friday * * @param {Date} t_ current time * @returns */ export declare const getUpcomingFriday: (t_: Date) => Date; /** * getPreviousFriday * * From the current time, get the previous Friday. * If the current time is Friday and is before 8am UTC, then return the previous week's Friday * * @param {Date} t_ current time * @returns */ export declare const getPreviousFriday: (t_: Date) => Date; /** * getCsoEventId * * Pass in Date and return event ID of announcement that user can enter into immediately * * @param {Date} t_ current time * @param {string} provider company or trader providing strategy * @param {string} strategyId unique identifier for strategy * @param {CsoPeriod} period i.e. monthly * @returns {string} event ID string i.e. atomic-call_spread_v1-monthly-27JUN22-29JUL22 */ export declare const getCsoEventId: (t_: Date, provider: string, strategyId: string, period: CsoPeriod, forceExtendedPeriod?: boolean) => string; /** * getCsoTradeSplitEventId * * This function generates an event ID for a split trade. * * @param {string} provider - The company or trader providing the strategy. * @param {string} strategyId - The unique identifier for the strategy. * @param {number} tradeIndex - The index of the trade. * @returns {string} - The event ID string in the format [provider]-[strategyId]-trade-[tradeIndex]. * i.e. atomic-oyster-trade-84 */ export declare const getCsoTradeSplitEventId: (provider: string, strategyId: string, tradeIndex: number) => string; /** * getCsoTradeUnsplitEventId * * This function generates an event ID for an unsplit trade. * * @param {Date} t_ - The current time. * @param {string} provider - The company or trader providing the strategy. * @param {string} strategyId - The unique identifier for the strategy. * @param {number} numTrades - The number of trades. * @returns {string} - The event ID string in the format [provider]-[strategyId]-[numTrades]-trades-[startDate]. * i.e. atomic-oyster-5-trades-1JAN24 */ export declare const getCsoTradeUnsplitEventId: (t_: Date, provider: string, strategyId: string, numTrades: number) => string; export declare const getManualEventId: (provider: string, source: string, maturity: Date, symbol?: string) => string; /** * getStartAndEndDateFromCsoEventId * * Pass in eventId and return start and end date by checking if date is * equal to tradingOpen, tradingOpenHalfMonth or dlcExpiry, else just * output date inside cso params for eventId * * @param {string} eventId format [provider]-[strategyId]-[period]-[startDate]-[endDate] * @returns {CsoParams} provider, strategyId, period, and start and end dates */ export declare const getParamsFromCsoEventId: (eventId: string) => CsoParams; export declare const getParamsFromCsoTradeSplitEventId: (eventId: string) => CsoSplitParams; export declare const getParamsFromCsoTradeUnsplitEventId: (eventId: string) => CsoUnsplitParams; /** * getParamsFromManualEventId * * Pass in eventId and return provider, source, maturity, and symbol * * @param {string} eventId format [provider]-[source]-[symbol]-[maturity] * @returns {ManualEventParams} provider, source, maturity, and symbol */ export declare const getParamsFromManualEventId: (eventId: string) => ManualEventParams; export declare const getCsoEventIdType: (eventId: string) => CsoEventIdType; export declare const getEventIdType: (eventId: string) => CsoEventIdType | 'manual'; /** * extractCsoEventIdDateFromStr * * Get Date from string date while checking if date matches tradingOpen, * tradingOpenHalfMonth or dlcExpiry * * @param {string} dateStr string date in format [day][month][year] i.e. 21AUG22 * @returns {Date} */ export declare const extractCsoEventIdDateFromStr: (dateStr: string) => Date; /** * findCycleMaturityMonthsInPast * * Enter number of cycles to look in past and get cycle maturity * i.e. passing in numMonths 3 will get the cycle maturity 3 months ago * * @param {Date} t_ current time * @param {number} numMonths number of months to go back * @returns {Date} */ export declare const findCycleMaturityMonthsInPast: (t_: Date, numMonths: number) => Date; /** * findNumCyclesInPastMaturityExists * * Enter previousExpiry and find out how many months ago this expiry was * * @param {Date} t_ current time * @param {Date} previousExpiry previous cycle expiry * @returns {number} */ export declare const findNumCyclesInPastMaturityExists: (t_: Date, previousExpiry_: Date, maxTries?: number) => number; /** * isHalfMonth * * Determine if the current cycle is a half month cycle * @param {string} eventId current time * @returns {boolean} whether the current cycle is a half month */ export declare const isHalfMonth: (eventId: string) => boolean; export declare const getCsoLength: (eventId: string) => CsoLength; export interface StartEndDates { startDate: Date; endDate: Date; } export interface CsoParams { provider: string; strategyId: string; period: string; startDate: Date; endDate: Date; } export interface CsoSplitParams { provider: string; strategyId: string; tradeIndex: number; } export interface CsoUnsplitParams { provider: string; strategyId: string; numTrades: number; startDate: Date; } export interface ManualEventParams { provider: string; source: string; symbol: string; maturity: Date; } export interface CsoEventDates { previousDlcExpiry: Date; dlcAttestation: Date; rolloverOpen: Date; newEntryOpen: Date; newEntryClosed: Date; tradingOpen: Date; halfMonthEntryClosed: Date; tradingOpenHalfMonth: Date; upcomingDlcExpiry: Date; }