@gainsnetwork/sdk 1.6.6 → 1.6.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/markets/schedules/builders.js +13 -11
- package/lib/markets/schedules/checkers.js +1 -1
- package/lib/markets/schedules/holidays.d.ts +3 -1
- package/lib/markets/schedules/holidays.js +58 -39
- package/lib/markets/schedules/index.d.ts +1 -0
- package/lib/markets/schedules/index.js +4 -1
- package/lib/markets/schedules/types.d.ts +1 -0
- package/package.json +1 -1
|
@@ -40,10 +40,11 @@ const buildForexWeeklySchedule = (currentDate = new Date(), opts) => {
|
|
|
40
40
|
for (const d of [types_1.WeekDay.Monday, types_1.WeekDay.Tuesday, types_1.WeekDay.Wednesday, types_1.WeekDay.Thursday, types_1.WeekDay.Friday]) {
|
|
41
41
|
add(lowLiq, d, { start: { hour: llStartHour, minute: llStartMinute }, end: { hour: llEndHour, minute: llEndMinute } });
|
|
42
42
|
}
|
|
43
|
+
const holidays = (0, holidays_1.getHolidaysInCurrentWeek)('forex', currentDate);
|
|
43
44
|
const summary = isInDST
|
|
44
45
|
? 'Monday 4:00 pm - Friday 4:00 pm ET (Closed weekends & holidays)'
|
|
45
46
|
: 'Monday 5:00 pm - Friday 5:00 pm ET (Closed weekends & holidays)';
|
|
46
|
-
return { open, lowLiq, summary };
|
|
47
|
+
return { open, lowLiq, holidays, summary };
|
|
47
48
|
};
|
|
48
49
|
exports.buildForexWeeklySchedule = buildForexWeeklySchedule;
|
|
49
50
|
const buildStocksWeeklySchedule = (currentDate = new Date()) => {
|
|
@@ -52,7 +53,7 @@ const buildStocksWeeklySchedule = (currentDate = new Date()) => {
|
|
|
52
53
|
for (const d of [types_1.WeekDay.Monday, types_1.WeekDay.Tuesday, types_1.WeekDay.Wednesday, types_1.WeekDay.Thursday, types_1.WeekDay.Friday]) {
|
|
53
54
|
add(open, d, { start: { hour: 9, minute: 30 }, end: { hour: 16, minute: 0 } });
|
|
54
55
|
}
|
|
55
|
-
const holidays = (0, holidays_1.
|
|
56
|
+
const holidays = (0, holidays_1.getHolidaysInCurrentWeek)('stocks', currentDate);
|
|
56
57
|
const summary = 'Monday - Friday: 9:30 am - 4:00 pm ET (Closed weekends & holidays)';
|
|
57
58
|
return { open, lowLiq, holidays, summary };
|
|
58
59
|
};
|
|
@@ -62,17 +63,18 @@ exports.buildIndicesWeeklySchedule = buildIndicesWeeklySchedule;
|
|
|
62
63
|
const buildCommoditiesWeeklySchedule = (currentDate = new Date()) => {
|
|
63
64
|
const open = emptyWeekly();
|
|
64
65
|
const lowLiq = emptyWeekly();
|
|
65
|
-
// Sunday:
|
|
66
|
-
add(open, types_1.WeekDay.Sunday, { start: { hour:
|
|
67
|
-
// Mon-Thu: 0:00 ->
|
|
66
|
+
// Sunday: 18:00 -> 24:00
|
|
67
|
+
add(open, types_1.WeekDay.Sunday, { start: { hour: 18, minute: 0 }, end: { hour: 24, minute: 0 } });
|
|
68
|
+
// Mon-Thu: 0:00 -> 17:00 and 18:00 -> 24:00 (break represented by the gap)
|
|
68
69
|
for (const d of [types_1.WeekDay.Monday, types_1.WeekDay.Tuesday, types_1.WeekDay.Wednesday, types_1.WeekDay.Thursday]) {
|
|
69
|
-
add(open, d, { start: { hour: 0, minute: 0 }, end: { hour:
|
|
70
|
-
add(open, d, { start: { hour: 18, minute:
|
|
70
|
+
add(open, d, { start: { hour: 0, minute: 0 }, end: { hour: 17, minute: 0 } });
|
|
71
|
+
add(open, d, { start: { hour: 18, minute: 0 }, end: { hour: 24, minute: 0 } });
|
|
71
72
|
}
|
|
72
|
-
// Friday: 0:00 ->
|
|
73
|
-
add(open, types_1.WeekDay.Friday, { start: { hour: 0, minute: 0 }, end: { hour:
|
|
73
|
+
// Friday: 0:00 -> 17:00
|
|
74
|
+
add(open, types_1.WeekDay.Friday, { start: { hour: 0, minute: 0 }, end: { hour: 17, minute: 0 } });
|
|
74
75
|
// Saturday: closed (no windows)
|
|
75
|
-
const
|
|
76
|
-
|
|
76
|
+
const holidays = (0, holidays_1.getHolidaysInCurrentWeek)('commodities', currentDate);
|
|
77
|
+
const summary = `Sunday 6:00 pm - Friday 5:00 pm ET (Daily break: 5:00 pm - 6:00 pm ET)`;
|
|
78
|
+
return { open, lowLiq, holidays, summary };
|
|
77
79
|
};
|
|
78
80
|
exports.buildCommoditiesWeeklySchedule = buildCommoditiesWeeklySchedule;
|
|
@@ -19,7 +19,7 @@ const isOpenAt = (market, date, opts) => {
|
|
|
19
19
|
const dayKey = weekdayKey(dt.weekday);
|
|
20
20
|
const mm = dt.hour * 60 + dt.minute;
|
|
21
21
|
// Holiday override: if this ET date has a holiday entry, use its openWindows
|
|
22
|
-
const holiday = schedule.holidays?.find(x => x.month === dt.month && x.day === dt.day);
|
|
22
|
+
const holiday = schedule.holidays?.find(x => x.year === dt.year && x.month === dt.month && x.day === dt.day);
|
|
23
23
|
if (holiday) {
|
|
24
24
|
return inInAnyWindow(mm, holiday.openWindows);
|
|
25
25
|
}
|
|
@@ -1,2 +1,4 @@
|
|
|
1
1
|
import { Holiday } from "./types";
|
|
2
|
-
|
|
2
|
+
import { TradFiMarket } from "./index";
|
|
3
|
+
export declare const getHolidays: (market: TradFiMarket, startDate: Date, days: number) => Holiday[];
|
|
4
|
+
export declare const getHolidaysInCurrentWeek: (market: TradFiMarket, currentDate: Date) => Holiday[];
|
|
@@ -1,44 +1,63 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.getHolidaysInCurrentWeek = exports.getHolidays = void 0;
|
|
4
4
|
const luxon_1 = require("luxon");
|
|
5
5
|
const ET = luxon_1.IANAZone.create("America/New_York");
|
|
6
|
-
|
|
7
|
-
const
|
|
8
|
-
|
|
9
|
-
const
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
6
|
+
const full = (year, month, day, name) => ({ year, month, day, name, openWindows: [] });
|
|
7
|
+
const partial = (year, month, day, name, startH, startM, endH, endM) => ({ year, month, day, name, openWindows: [{ start: { hour: startH, minute: startM }, end: { hour: endH, minute: endM } }] });
|
|
8
|
+
// Shared holidays
|
|
9
|
+
const HOLIDAYS = [
|
|
10
|
+
// 2025
|
|
11
|
+
full(2025, 5, 26, "Memorial Day"),
|
|
12
|
+
full(2025, 6, 19, "Juneteenth"),
|
|
13
|
+
partial(2025, 7, 3, "Day Before Independence Day", 9, 30, 13, 0),
|
|
14
|
+
full(2025, 7, 4, "Independence Day"),
|
|
15
|
+
full(2025, 9, 1, "Labor Day"),
|
|
16
|
+
full(2025, 11, 27, "Thanksgiving Day"),
|
|
17
|
+
partial(2025, 11, 28, "Black Friday", 9, 30, 13, 0),
|
|
18
|
+
full(2025, 12, 25, "Christmas Day"),
|
|
19
|
+
// 2026
|
|
20
|
+
full(2026, 1, 1, "New Year's Day"),
|
|
21
|
+
full(2026, 1, 19, "Martin Luther King Jr. Day"),
|
|
22
|
+
full(2026, 2, 16, "Presidents' Day"),
|
|
23
|
+
full(2026, 4, 3, "Good Friday"),
|
|
19
24
|
];
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
const
|
|
37
|
-
const
|
|
38
|
-
const
|
|
39
|
-
return
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
}
|
|
44
|
-
|
|
25
|
+
// Market-specific holiday overrides
|
|
26
|
+
const HOLIDAYS_OVERRIDES = {
|
|
27
|
+
stocks: [
|
|
28
|
+
partial(2025, 12, 24, "Christmas Eve", 9, 30, 13, 0),
|
|
29
|
+
],
|
|
30
|
+
indices: [
|
|
31
|
+
partial(2025, 12, 24, "Christmas Eve", 9, 30, 13, 0),
|
|
32
|
+
],
|
|
33
|
+
commodities: [
|
|
34
|
+
partial(2025, 12, 24, "Christmas Eve", 0, 0, 12, 0),
|
|
35
|
+
],
|
|
36
|
+
forex: [
|
|
37
|
+
partial(2025, 12, 24, "Christmas Eve", 0, 0, 12, 45),
|
|
38
|
+
],
|
|
39
|
+
};
|
|
40
|
+
const getHolidaysForYear = (market, year) => {
|
|
41
|
+
const holidayOverrides = HOLIDAYS_OVERRIDES[market]?.filter(h => h.year === year) || [];
|
|
42
|
+
const overridden = new Set(holidayOverrides.map(h => h.name));
|
|
43
|
+
const filteredHolidays = HOLIDAYS.filter(h => h.year === year && !overridden.has(h.name));
|
|
44
|
+
return [...filteredHolidays, ...holidayOverrides].sort((a, b) => a.month === b.month ? a.day - b.day : a.month - b.month);
|
|
45
|
+
};
|
|
46
|
+
const getHolidays = (market, startDate, days) => {
|
|
47
|
+
const start = luxon_1.DateTime.fromJSDate(startDate).setZone(ET).startOf('day');
|
|
48
|
+
const end = start.plus({ days });
|
|
49
|
+
const years = [];
|
|
50
|
+
for (let year = start.year; year <= end.year; year++) {
|
|
51
|
+
years.push(year);
|
|
52
|
+
}
|
|
53
|
+
return years.flatMap(year => getHolidaysForYear(market, year).filter(h => {
|
|
54
|
+
const d = luxon_1.DateTime.fromObject({ year: h.year, month: h.month, day: h.day }, { zone: ET });
|
|
55
|
+
return d >= start && d < end;
|
|
56
|
+
}));
|
|
57
|
+
};
|
|
58
|
+
exports.getHolidays = getHolidays;
|
|
59
|
+
const getHolidaysInCurrentWeek = (market, currentDate) => {
|
|
60
|
+
const weekStart = luxon_1.DateTime.fromJSDate(currentDate).setZone(ET).startOf("week");
|
|
61
|
+
return (0, exports.getHolidays)(market, weekStart.toJSDate(), 7);
|
|
62
|
+
};
|
|
63
|
+
exports.getHolidaysInCurrentWeek = getHolidaysInCurrentWeek;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
export * from "./types";
|
|
2
2
|
export { buildForexWeeklySchedule, buildStocksWeeklySchedule, buildIndicesWeeklySchedule, buildCommoditiesWeeklySchedule, } from "./builders";
|
|
3
3
|
export { isOpenAt, isLowLiquidityAt } from "./checkers";
|
|
4
|
+
export { getHolidays, getHolidaysInCurrentWeek } from "./holidays";
|
|
4
5
|
import { Schedule } from "./types";
|
|
5
6
|
export type TradFiMarket = "forex" | "stocks" | "indices" | "commodities";
|
|
6
7
|
export declare const getWeeklySchedule: (market: TradFiMarket, currentDate?: Date, opts?: {
|
|
@@ -14,7 +14,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
14
14
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
exports.getWeeklySchedule = exports.isLowLiquidityAt = exports.isOpenAt = exports.buildCommoditiesWeeklySchedule = exports.buildIndicesWeeklySchedule = exports.buildStocksWeeklySchedule = exports.buildForexWeeklySchedule = void 0;
|
|
17
|
+
exports.getWeeklySchedule = exports.getHolidaysInCurrentWeek = exports.getHolidays = exports.isLowLiquidityAt = exports.isOpenAt = exports.buildCommoditiesWeeklySchedule = exports.buildIndicesWeeklySchedule = exports.buildStocksWeeklySchedule = exports.buildForexWeeklySchedule = void 0;
|
|
18
18
|
__exportStar(require("./types"), exports);
|
|
19
19
|
var builders_1 = require("./builders");
|
|
20
20
|
Object.defineProperty(exports, "buildForexWeeklySchedule", { enumerable: true, get: function () { return builders_1.buildForexWeeklySchedule; } });
|
|
@@ -24,6 +24,9 @@ Object.defineProperty(exports, "buildCommoditiesWeeklySchedule", { enumerable: t
|
|
|
24
24
|
var checkers_1 = require("./checkers");
|
|
25
25
|
Object.defineProperty(exports, "isOpenAt", { enumerable: true, get: function () { return checkers_1.isOpenAt; } });
|
|
26
26
|
Object.defineProperty(exports, "isLowLiquidityAt", { enumerable: true, get: function () { return checkers_1.isLowLiquidityAt; } });
|
|
27
|
+
var holidays_1 = require("./holidays");
|
|
28
|
+
Object.defineProperty(exports, "getHolidays", { enumerable: true, get: function () { return holidays_1.getHolidays; } });
|
|
29
|
+
Object.defineProperty(exports, "getHolidaysInCurrentWeek", { enumerable: true, get: function () { return holidays_1.getHolidaysInCurrentWeek; } });
|
|
27
30
|
const builders_2 = require("./builders");
|
|
28
31
|
const getWeeklySchedule = (market, currentDate = new Date(), opts) => {
|
|
29
32
|
switch (market) {
|