@gainsnetwork/sdk 1.6.8-rc1 → 1.6.10

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.
@@ -24,8 +24,9 @@ const buildForexWeeklySchedule = (currentDate = new Date(), opts) => {
24
24
  const lowLiq = emptyWeekly();
25
25
  const openHour = isInDST ? 16 : 17; // Monday open
26
26
  const closeHour = isInDST ? 16 : 17; // Friday close
27
- // Open windows (ET): Mon 16/17:00 -> 24:00, Tue-Thu 0-24, Fri 0 -> 16/17:00
28
- add(open, types_1.WeekDay.Monday, { start: { hour: openHour, minute: 0 }, end: { hour: 24, minute: 0 } });
27
+ // Open windows (ET): Sun 16/17:00 -> 24:00, Mon-Thu 0-24, Fri 0 -> 16/17:00
28
+ add(open, types_1.WeekDay.Sunday, { start: { hour: openHour, minute: 0 }, end: { hour: 24, minute: 0 } });
29
+ add(open, types_1.WeekDay.Monday, { start: { hour: 0, minute: 0 }, end: { hour: 24, minute: 0 } });
29
30
  add(open, types_1.WeekDay.Tuesday, { start: { hour: 0, minute: 0 }, end: { hour: 24, minute: 0 } });
30
31
  add(open, types_1.WeekDay.Wednesday, { start: { hour: 0, minute: 0 }, end: { hour: 24, minute: 0 } });
31
32
  add(open, types_1.WeekDay.Thursday, { start: { hour: 0, minute: 0 }, end: { hour: 24, minute: 0 } });
@@ -37,13 +38,14 @@ const buildForexWeeklySchedule = (currentDate = new Date(), opts) => {
37
38
  const llStartMinute = 45;
38
39
  const llEndHour = isInDST ? (useExtended ? 21 : 19) : (useExtended ? 22 : 20);
39
40
  const llEndMinute = 0;
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
+ for (const d of [types_1.WeekDay.Sunday, types_1.WeekDay.Monday, types_1.WeekDay.Tuesday, types_1.WeekDay.Wednesday, types_1.WeekDay.Thursday, types_1.WeekDay.Friday]) {
41
42
  add(lowLiq, d, { start: { hour: llStartHour, minute: llStartMinute }, end: { hour: llEndHour, minute: llEndMinute } });
42
43
  }
44
+ const holidays = (0, holidays_1.getHolidaysInCurrentWeek)('forex', currentDate);
43
45
  const summary = isInDST
44
- ? 'Monday 4:00 pm - Friday 4:00 pm ET (Closed weekends & holidays)'
45
- : 'Monday 5:00 pm - Friday 5:00 pm ET (Closed weekends & holidays)';
46
- return { open, lowLiq, summary };
46
+ ? 'Sunday 4:00 pm - Friday 4:00 pm ET (Closed weekends & holidays)'
47
+ : 'Sunday 5:00 pm - Friday 5:00 pm ET (Closed weekends & holidays)';
48
+ return { open, lowLiq, holidays, summary };
47
49
  };
48
50
  exports.buildForexWeeklySchedule = buildForexWeeklySchedule;
49
51
  const buildStocksWeeklySchedule = (currentDate = new Date()) => {
@@ -52,7 +54,7 @@ const buildStocksWeeklySchedule = (currentDate = new Date()) => {
52
54
  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
55
  add(open, d, { start: { hour: 9, minute: 30 }, end: { hour: 16, minute: 0 } });
54
56
  }
55
- const holidays = (0, holidays_1.getStocksHolidaysInWeek)(currentDate);
57
+ const holidays = (0, holidays_1.getHolidaysInCurrentWeek)('stocks', currentDate);
56
58
  const summary = 'Monday - Friday: 9:30 am - 4:00 pm ET (Closed weekends & holidays)';
57
59
  return { open, lowLiq, holidays, summary };
58
60
  };
@@ -62,17 +64,18 @@ exports.buildIndicesWeeklySchedule = buildIndicesWeeklySchedule;
62
64
  const buildCommoditiesWeeklySchedule = (currentDate = new Date()) => {
63
65
  const open = emptyWeekly();
64
66
  const lowLiq = emptyWeekly();
65
- // Sunday: 19:30 -> 24:00
66
- add(open, types_1.WeekDay.Sunday, { start: { hour: 19, minute: 30 }, end: { hour: 24, minute: 0 } });
67
- // Mon-Thu: 0:00 -> 16:30 and 18:30 -> 24:00 (break represented by the gap)
67
+ // Sunday: 18:00 -> 24:00
68
+ add(open, types_1.WeekDay.Sunday, { start: { hour: 18, minute: 0 }, end: { hour: 24, minute: 0 } });
69
+ // Mon-Thu: 0:00 -> 17:00 and 18:00 -> 24:00 (break represented by the gap)
68
70
  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: 16, minute: 30 } });
70
- add(open, d, { start: { hour: 18, minute: 30 }, end: { hour: 24, minute: 0 } });
71
+ add(open, d, { start: { hour: 0, minute: 0 }, end: { hour: 17, minute: 0 } });
72
+ add(open, d, { start: { hour: 18, minute: 0 }, end: { hour: 24, minute: 0 } });
71
73
  }
72
- // Friday: 0:00 -> 16:30
73
- add(open, types_1.WeekDay.Friday, { start: { hour: 0, minute: 0 }, end: { hour: 16, minute: 30 } });
74
+ // Friday: 0:00 -> 17:00
75
+ add(open, types_1.WeekDay.Friday, { start: { hour: 0, minute: 0 }, end: { hour: 17, minute: 0 } });
74
76
  // Saturday: closed (no windows)
75
- const summary = 'Sunday 7:30 pm - Friday 4:30 pm ET (Daily break: 4:30 pm - 6:30 pm ET)';
76
- return { open, lowLiq, summary };
77
+ const holidays = (0, holidays_1.getHolidaysInCurrentWeek)('commodities', currentDate);
78
+ const summary = `Sunday 6:00 pm - Friday 5:00 pm ET (Daily break: 5:00 pm - 6:00 pm ET)`;
79
+ return { open, lowLiq, holidays, summary };
77
80
  };
78
81
  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
- export declare function getStocksHolidaysInWeek(currentDate: Date): Holiday[];
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.getStocksHolidaysInWeek = void 0;
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
- // Holiday definitions per year (ET calendar). For full-day closure, openWindows: []
7
- const stocksFullDay = (month, day, name) => ({ month, day, name, openWindows: [] });
8
- const addWindows = (startH, startM, endH, endM) => ({ start: { hour: startH, minute: startM }, end: { hour: endH, minute: endM } });
9
- const HOLIDAYS_2025 = [
10
- stocksFullDay(5, 26, "Memorial Day"),
11
- stocksFullDay(6, 19, "Juneteenth"),
12
- stocksFullDay(7, 4, "Independence Day"),
13
- stocksFullDay(9, 1, "Labor Day"),
14
- stocksFullDay(11, 27, "Thanksgiving Day"),
15
- stocksFullDay(12, 25, "Christmas Day"),
16
- { month: 7, day: 3, name: "Day Before Independence Day", openWindows: [addWindows(9, 30, 13, 0)] },
17
- { month: 11, day: 28, name: "Black Friday", openWindows: [addWindows(9, 30, 13, 0)] },
18
- { month: 12, day: 24, name: "Christmas Eve", openWindows: [addWindows(9, 30, 13, 0)] },
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
- const HOLIDAYS_2026 = [
21
- stocksFullDay(1, 1, "New Year's Day"),
22
- stocksFullDay(1, 19, "Martin Luther King Jr. Day"),
23
- stocksFullDay(2, 16, "Presidents' Day"),
24
- stocksFullDay(4, 3, "Good Friday"),
25
- ];
26
- function getStocksHolidaysForYear(year) {
27
- if (year === 2025)
28
- return HOLIDAYS_2025;
29
- if (year === 2026)
30
- return HOLIDAYS_2026;
31
- return [];
32
- }
33
- function getStocksHolidaysInWeek(currentDate) {
34
- const dt = luxon_1.DateTime.fromJSDate(currentDate).setZone(ET);
35
- const weekStart = dt.startOf("week"); // Sunday 00:00 ET
36
- const weekEnd = weekStart.plus({ days: 7 }); // exclusive end
37
- const year = dt.year;
38
- const list = getStocksHolidaysForYear(year);
39
- return list.filter(h => {
40
- const d = luxon_1.DateTime.fromObject({ year, month: h.month, day: h.day }, { zone: ET });
41
- return d >= weekStart && d < weekEnd;
42
- });
43
- }
44
- exports.getStocksHolidaysInWeek = getStocksHolidaysInWeek;
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, 12, 15),
32
+ ],
33
+ commodities: [
34
+ partial(2025, 12, 24, "Christmas Eve", 0, 0, 12, 45),
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) {
@@ -28,6 +28,7 @@ export declare enum WeekDay {
28
28
  export type WeekDayKey = keyof WeeklySchedule;
29
29
  export declare const weekDayToKey: (d: WeekDay) => WeekDayKey;
30
30
  export type Holiday = {
31
+ year: number;
31
32
  month: number;
32
33
  day: number;
33
34
  name: string;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gainsnetwork/sdk",
3
- "version": "1.6.8-rc1",
3
+ "version": "1.6.10",
4
4
  "description": "Gains Network SDK",
5
5
  "main": "./lib/index.js",
6
6
  "files": [