tradeblocks-mcp 4.2.0 → 4.4.0

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.
Files changed (48) hide show
  1. package/README.md +72 -1
  2. package/dist/{chunk-YRD62LDE.js → chunk-35RVWZGT.js} +4 -1
  3. package/dist/{chunk-4UU7IT2A.js.map → chunk-35RVWZGT.js.map} +1 -1
  4. package/dist/{chunk-62GCLMQA.js → chunk-CZNPQ574.js} +6 -9
  5. package/dist/chunk-CZNPQ574.js.map +1 -0
  6. package/dist/{chunk-4UU7IT2A.js → chunk-ENXBPJ7Y.js} +148 -6
  7. package/dist/chunk-ENXBPJ7Y.js.map +1 -0
  8. package/dist/{daily-logs-store-PXB53WEK.js → daily-logs-store-FZRIGYUX.js} +2 -2
  9. package/dist/{daily-logs-store-65YHFJ5F.js → daily-logs-store-MEZ5S3BR.js} +2 -2
  10. package/dist/market/provenance/index.js +1 -4
  11. package/dist/market/provenance/index.js.map +1 -1
  12. package/dist/{sync-JL7OPLCT.js → sync-P6QUZFSF.js} +3 -3
  13. package/dist/test-exports.js +320 -279
  14. package/dist/test-exports.js.map +1 -1
  15. package/dist/{trades-store-UGZ62A7N.js → trades-store-3TOLBL2W.js} +2 -2
  16. package/dist/{trades-store-MOFJHRC2.js → trades-store-PNLPRYRJ.js} +2 -2
  17. package/package.json +1 -1
  18. package/server/{chunk-J4GWE6JR.js → chunk-5JTQEV7P.js} +307 -255
  19. package/server/chunk-5JTQEV7P.js.map +1 -0
  20. package/server/{chunk-7N6HBOAY.js → chunk-PDSUY2X2.js} +148 -6
  21. package/server/chunk-PDSUY2X2.js.map +1 -0
  22. package/server/{daily-logs-store-YAXASQN4.js → daily-logs-store-LRVO7COL.js} +2 -2
  23. package/server/index.js +1326 -928
  24. package/server/index.js.map +1 -1
  25. package/server/{sync-ZV3QEGMO.js → sync-336543PJ.js} +3 -3
  26. package/server/{trades-store-MF7YYLCH.js → trades-store-MXUZLSF5.js} +2 -2
  27. package/src/db/dataset-schemas.ts +97 -23
  28. package/src/tools/market-data.ts +327 -245
  29. package/src/tools/profile-analysis.ts +18 -4
  30. package/src/tools/reports/fields.ts +16 -11
  31. package/src/tools/reports/helpers.ts +6 -2
  32. package/src/tools/reports/predictive.ts +177 -191
  33. package/src/tools/shared/field-analysis.ts +57 -14
  34. package/src/tools/shared/filter-objective.ts +73 -0
  35. package/src/utils/filter-curve.ts +257 -0
  36. package/src/utils/trade-analysis-fields.ts +19 -4
  37. package/dist/chunk-62GCLMQA.js.map +0 -1
  38. package/dist/chunk-YRD62LDE.js.map +0 -1
  39. package/server/chunk-7N6HBOAY.js.map +0 -1
  40. package/server/chunk-J4GWE6JR.js.map +0 -1
  41. /package/dist/{daily-logs-store-65YHFJ5F.js.map → daily-logs-store-FZRIGYUX.js.map} +0 -0
  42. /package/dist/{daily-logs-store-PXB53WEK.js.map → daily-logs-store-MEZ5S3BR.js.map} +0 -0
  43. /package/dist/{sync-JL7OPLCT.js.map → sync-P6QUZFSF.js.map} +0 -0
  44. /package/dist/{trades-store-MOFJHRC2.js.map → trades-store-3TOLBL2W.js.map} +0 -0
  45. /package/dist/{trades-store-UGZ62A7N.js.map → trades-store-PNLPRYRJ.js.map} +0 -0
  46. /package/server/{daily-logs-store-YAXASQN4.js.map → daily-logs-store-LRVO7COL.js.map} +0 -0
  47. /package/server/{sync-ZV3QEGMO.js.map → sync-336543PJ.js.map} +0 -0
  48. /package/server/{trades-store-MF7YYLCH.js.map → trades-store-MXUZLSF5.js.map} +0 -0
@@ -5327,6 +5327,131 @@ async function getTradesPage(blockId, offset, limit) {
5327
5327
  // ../lib/utils/trade-frequency.ts
5328
5328
  var MS_PER_DAY = 1e3 * 60 * 60 * 24;
5329
5329
 
5330
+ // ../lib/calculations/xnys-session-calendar.ts
5331
+ var XNYS_SESSION_CALENDAR_REVISION = "xnys-full-day-2022-2030-v1";
5332
+ var XNYS_SESSION_CALENDAR_SUPPORTED_FROM = "2022-01-01";
5333
+ var XNYS_SESSION_CALENDAR_SUPPORTED_THROUGH = "2030-12-31";
5334
+ var ISO_DATE_RE = /^\d{4}-\d{2}-\d{2}$/;
5335
+ var MS_PER_DAY2 = 24 * 60 * 60 * 1e3;
5336
+ var SPECIAL_CLOSURES = /* @__PURE__ */ new Set(["2025-01-09"]);
5337
+ function isoDate(date) {
5338
+ return date.toISOString().slice(0, 10);
5339
+ }
5340
+ function utcDate(year, monthIndex, day) {
5341
+ return new Date(Date.UTC(year, monthIndex, day));
5342
+ }
5343
+ function parseSupportedDate(value, label) {
5344
+ if (!ISO_DATE_RE.test(value)) {
5345
+ throw new TypeError(
5346
+ `${label} must be an ISO calendar date (YYYY-MM-DD): ${JSON.stringify(value)}`
5347
+ );
5348
+ }
5349
+ const parsed = /* @__PURE__ */ new Date(`${value}T00:00:00.000Z`);
5350
+ if (!Number.isFinite(parsed.getTime()) || isoDate(parsed) !== value) {
5351
+ throw new TypeError(`${label} is not a real calendar date: ${JSON.stringify(value)}`);
5352
+ }
5353
+ if (value < XNYS_SESSION_CALENDAR_SUPPORTED_FROM || value > XNYS_SESSION_CALENDAR_SUPPORTED_THROUGH) {
5354
+ throw new RangeError(
5355
+ `${label} ${JSON.stringify(value)} is outside XNYS calendar revision ${XNYS_SESSION_CALENDAR_REVISION} [${XNYS_SESSION_CALENDAR_SUPPORTED_FROM}, ${XNYS_SESSION_CALENDAR_SUPPORTED_THROUGH}]`
5356
+ );
5357
+ }
5358
+ return parsed;
5359
+ }
5360
+ function nthWeekdayOfMonth(year, monthIndex, weekday, occurrence) {
5361
+ const first = utcDate(year, monthIndex, 1);
5362
+ const offset = (weekday - first.getUTCDay() + 7) % 7;
5363
+ return utcDate(year, monthIndex, 1 + offset + (occurrence - 1) * 7);
5364
+ }
5365
+ function lastWeekdayOfMonth(year, monthIndex, weekday) {
5366
+ const last = utcDate(year, monthIndex + 1, 0);
5367
+ const offset = (last.getUTCDay() - weekday + 7) % 7;
5368
+ return utcDate(year, monthIndex, last.getUTCDate() - offset);
5369
+ }
5370
+ function easterSunday(year) {
5371
+ const a = year % 19;
5372
+ const b = Math.floor(year / 100);
5373
+ const c = year % 100;
5374
+ const d = Math.floor(b / 4);
5375
+ const e = b % 4;
5376
+ const f = Math.floor((b + 8) / 25);
5377
+ const g = Math.floor((b - f + 1) / 3);
5378
+ const h = (19 * a + b - d - g + 15) % 30;
5379
+ const i = Math.floor(c / 4);
5380
+ const k = c % 4;
5381
+ const l = (32 + 2 * e + 2 * i - h - k) % 7;
5382
+ const m = Math.floor((a + 11 * h + 22 * l) / 451);
5383
+ const month = Math.floor((h + l - 7 * m + 114) / 31);
5384
+ const day = (h + l - 7 * m + 114) % 31 + 1;
5385
+ return utcDate(year, month - 1, day);
5386
+ }
5387
+ function addDays(date, days) {
5388
+ return new Date(date.getTime() + days * MS_PER_DAY2);
5389
+ }
5390
+ function observedFixedHoliday(year, monthIndex, day) {
5391
+ const holiday = utcDate(year, monthIndex, day);
5392
+ if (holiday.getUTCDay() === 6) return addDays(holiday, -1);
5393
+ if (holiday.getUTCDay() === 0) return addDays(holiday, 1);
5394
+ return holiday;
5395
+ }
5396
+ function addNewYearsClosure(closures, holidayYear) {
5397
+ const holiday = utcDate(holidayYear, 0, 1);
5398
+ if (holiday.getUTCDay() === 6) {
5399
+ return;
5400
+ }
5401
+ closures.add(isoDate(holiday.getUTCDay() === 0 ? addDays(holiday, 1) : holiday));
5402
+ }
5403
+ function holidayClosures(year) {
5404
+ const closures = /* @__PURE__ */ new Set();
5405
+ const add = (date) => {
5406
+ closures.add(isoDate(date));
5407
+ };
5408
+ addNewYearsClosure(closures, year);
5409
+ addNewYearsClosure(closures, year + 1);
5410
+ add(nthWeekdayOfMonth(year, 0, 1, 3));
5411
+ add(nthWeekdayOfMonth(year, 1, 1, 3));
5412
+ add(addDays(easterSunday(year), -2));
5413
+ add(lastWeekdayOfMonth(year, 4, 1));
5414
+ add(observedFixedHoliday(year, 5, 19));
5415
+ add(observedFixedHoliday(year, 6, 4));
5416
+ add(nthWeekdayOfMonth(year, 8, 1, 1));
5417
+ add(nthWeekdayOfMonth(year, 10, 4, 4));
5418
+ add(observedFixedHoliday(year, 11, 25));
5419
+ for (const date of SPECIAL_CLOSURES) {
5420
+ if (date.startsWith(`${year}-`)) closures.add(date);
5421
+ }
5422
+ return closures;
5423
+ }
5424
+ var CLOSURES_BY_YEAR = /* @__PURE__ */ new Map();
5425
+ function closuresForYear(year) {
5426
+ let closures = CLOSURES_BY_YEAR.get(year);
5427
+ if (!closures) {
5428
+ closures = holidayClosures(year);
5429
+ CLOSURES_BY_YEAR.set(year, closures);
5430
+ }
5431
+ return closures;
5432
+ }
5433
+ function isXnysSessionDate(value) {
5434
+ const date = parseSupportedDate(value, "XNYS session date");
5435
+ const weekday = date.getUTCDay();
5436
+ if (weekday === 0 || weekday === 6) return false;
5437
+ return !closuresForYear(date.getUTCFullYear()).has(value);
5438
+ }
5439
+ function enumerateXnysSessions(from, through) {
5440
+ const first = parseSupportedDate(from, "XNYS session range from");
5441
+ const last = parseSupportedDate(through, "XNYS session range through");
5442
+ if (first.getTime() > last.getTime()) {
5443
+ throw new RangeError(
5444
+ `XNYS session range from ${JSON.stringify(from)} exceeds through ${JSON.stringify(through)}`
5445
+ );
5446
+ }
5447
+ const sessions = [];
5448
+ for (let cursor = first; cursor.getTime() <= last.getTime(); cursor = addDays(cursor, 1)) {
5449
+ const date = isoDate(cursor);
5450
+ if (isXnysSessionDate(date)) sessions.push(date);
5451
+ }
5452
+ return Object.freeze(sessions);
5453
+ }
5454
+
5330
5455
  // ../lib/calculations/static-dataset-matcher.ts
5331
5456
  function getDatasetValueAvailableAt(dataset, row, column) {
5332
5457
  if (!dataset.columns.includes(column)) throw new Error(`Unknown dataset column: ${column}`);
@@ -5347,7 +5472,9 @@ function getDatasetValueAvailableAt(dataset, row, column) {
5347
5472
  return combineDateAndTime(next, "00:00");
5348
5473
  }
5349
5474
  var availabilityIndexes = /* @__PURE__ */ new WeakMap();
5350
- function resolveDatasetColumnAtTime(dataset, rows, column, entryTime) {
5475
+ function resolveDatasetColumnAtTime(dataset, rows, column, entryTime, maxMissedSessions) {
5476
+ if (maxMissedSessions !== void 0 && (!Number.isInteger(maxMissedSessions) || maxMissedSessions < 0))
5477
+ throw new Error("maxMissedSessions must be a nonnegative integer");
5351
5478
  if (!dataset.columns.includes(column)) throw new Error(`Unknown dataset column: ${column}`);
5352
5479
  let rowIndexes = availabilityIndexes.get(dataset);
5353
5480
  if (!rowIndexes) {
@@ -5380,7 +5507,22 @@ function resolveDatasetColumnAtTime(dataset, rows, column, entryTime) {
5380
5507
  }
5381
5508
  if (!left) return null;
5382
5509
  const match = index[left - 1];
5383
- return { value: match.row.values[column], row: match.row, availableAt: new Date(match.time) };
5510
+ const sourceDay = getDateOnly(new Date(match.row.timestamp));
5511
+ const entryDay = getDateOnly(entryTime);
5512
+ let sessionAge = "unsupported";
5513
+ if (dataset.timingMode === "declared" && sourceDay >= XNYS_SESSION_CALENDAR_SUPPORTED_FROM && entryDay <= XNYS_SESSION_CALENDAR_SUPPORTED_THROUGH) {
5514
+ const includeToday = dataset.columnTiming?.[column] === "open" && entryTime >= combineDateAndTime(/* @__PURE__ */ new Date(`${entryDay}T00:00:00Z`), dataset.knownBy ?? "00:00");
5515
+ sessionAge = enumerateXnysSessions(sourceDay, entryDay).filter(
5516
+ (day) => day > sourceDay && (day < entryDay || includeToday)
5517
+ ).length;
5518
+ }
5519
+ return {
5520
+ value: match.row.values[column],
5521
+ row: match.row,
5522
+ availableAt: new Date(match.time),
5523
+ sessionAge,
5524
+ accepted: maxMissedSessions === void 0 || sessionAge !== "unsupported" && sessionAge <= maxMissedSessions
5525
+ };
5384
5526
  }
5385
5527
  function combineDateAndTime(dateOpened, timeOpened) {
5386
5528
  const d = new Date(dateOpened);
@@ -5406,10 +5548,10 @@ function combineDateAndTime(dateOpened, timeOpened) {
5406
5548
  minutes = parseInt(timeParts[1], 10) || 0;
5407
5549
  seconds = timeParts.length > 2 ? parseInt(timeParts[2], 10) || 0 : 0;
5408
5550
  }
5409
- const utcDate = Date.UTC(year, month, day, hours, minutes, seconds, 0);
5410
- const testDate = new Date(utcDate);
5551
+ const utcDate2 = Date.UTC(year, month, day, hours, minutes, seconds, 0);
5552
+ const testDate = new Date(utcDate2);
5411
5553
  const etOffset = getEasternTimeOffset(testDate);
5412
- return new Date(utcDate - etOffset * 60 * 1e3);
5554
+ return new Date(utcDate2 - etOffset * 60 * 1e3);
5413
5555
  }
5414
5556
  function getEasternTimeOffset(date) {
5415
5557
  const formatter = new Intl.DateTimeFormat("en-US", {
@@ -5941,4 +6083,4 @@ export {
5941
6083
  searchTrades,
5942
6084
  getTradesPage
5943
6085
  };
5944
- //# sourceMappingURL=chunk-4UU7IT2A.js.map
6086
+ //# sourceMappingURL=chunk-ENXBPJ7Y.js.map