Intelligence, Advanced Charting & Trading Platform
test: define market calendar gap semantics
davoodmehraban89 committed
Oct 5, 2026 at 16:55 UTC
3c89d46a91e005a179437db9a43c0a2e4f193667
1 file changed
+52
packages/market-domain/test/market-calendar.test.mjs
new
+52
@@ -0,0 +1,52 @@
1
+import test from 'node:test';
2
+import assert from 'node:assert/strict';
3
+import { marketExpectedOpen, classifyGap } from '../src/market-calendar.mjs';
4
+
5
+const crypto = {
6
+ timezone: 'UTC',
7
+ mode: '24x7',
8
+};
9
+
10
+const weekdayMarket = {
11
+ timezone: 'UTC',
12
+ mode: 'weekly',
13
+ sessions: {
14
+ 1: [['09:00','17:00']],
15
+ 2: [['09:00','17:00']],
16
+ 3: [['09:00','17:00']],
17
+ 4: [['09:00','17:00']],
18
+ 5: [['09:00','17:00']],
19
+ },
20
+ holidays: ['2026-10-06'],
21
+};
22
+
23
+test('24x7 calendar is always expected open', () => {
24
+ assert.equal(marketExpectedOpen(new Date('2026-10-04T03:00:00Z'), crypto), true);
25
+});
26
+
27
+test('weekly calendar observes session windows', () => {
28
+ assert.equal(marketExpectedOpen(new Date('2026-10-05T10:00:00Z'), weekdayMarket), true);
29
+ assert.equal(marketExpectedOpen(new Date('2026-10-05T18:00:00Z'), weekdayMarket), false);
30
+});
31
+
32
+test('weekly calendar observes explicit holidays', () => {
33
+ assert.equal(marketExpectedOpen(new Date('2026-10-06T10:00:00Z'), weekdayMarket), false);
34
+});
35
+
36
+test('gap during closed market is not classified as outage', () => {
37
+ assert.equal(classifyGap({
38
+ from: new Date('2026-10-05T17:30:00Z'),
39
+ to: new Date('2026-10-06T08:30:00Z'),
40
+ calendar: weekdayMarket,
41
+ probeMinutes: 30,
42
+ }), 'EXPECTED_CLOSED');
43
+});
44
+
45
+test('gap during expected-open session is classified as missing data', () => {
46
+ assert.equal(classifyGap({
47
+ from: new Date('2026-10-05T10:00:00Z'),
48
+ to: new Date('2026-10-05T10:30:00Z'),
49
+ calendar: weekdayMarket,
50
+ probeMinutes: 5,
51
+ }), 'MISSING_DATA');
52
+});