Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
b26457c
feat(fuse): add vendored FUSE-1 adapter and per-tier sizing isolation
Pigbibi Nov 25, 2026
970fd37
feat(feeder): isolate US 23/5 official close and bound upstream HTTP
Pigbibi Nov 25, 2026
5b63a6e
chore: merge main after SH-2 part 1 (#8)
Pigbibi Nov 26, 2026
d10093c
fix(fuse): honor O5 settled-cash alias, V7 session time, pyc flags
Pigbibi Nov 26, 2026
a4d6d63
chore: merge earlier SH-2 part into this part
Pigbibi Nov 26, 2026
649007c
fix(fuse): keep O5 counter aliases, forward H, drop return-as-loss
Pigbibi Nov 26, 2026
5751780
chore: merge earlier SH-2 part into this part
Pigbibi Nov 26, 2026
a9d93ba
docs(fuse): document O3 model self-reconciliation in Stage N
Pigbibi Nov 26, 2026
d77ff3a
chore: merge earlier SH-2 part into this part
Pigbibi Nov 26, 2026
b0e285a
fix(fuse): preserve explicitly null O5 session counters
Pigbibi Nov 26, 2026
85fe1a3
chore: merge earlier SH-2 part into this part
Pigbibi Nov 26, 2026
9137a64
fix(fuse): compare pyc code structurally and keep null settled cash
Pigbibi Nov 26, 2026
07b61e6
chore: merge earlier SH-2 part into this part
Pigbibi Nov 26, 2026
9734174
fix(fuse): resolve Astra P1s in adapter inputs and engine loading
Pigbibi Nov 26, 2026
f1ba4f6
chore: merge earlier SH-2 part into this part
Pigbibi Nov 26, 2026
f85af85
fix(fuse): label adapter self-heartbeat with heartbeat_source
Pigbibi Nov 26, 2026
bf62dd2
chore: merge earlier SH-2 part into this part
Pigbibi Nov 26, 2026
c221b30
docs(fuse): document EOD half-day O2 mapping and pin it with a test
Pigbibi Nov 26, 2026
4f00351
chore: merge earlier SH-2 part into this part
Pigbibi Nov 26, 2026
052c107
fix(fuse): resolve Astra round-2 P1s and default substitutions
Pigbibi Nov 26, 2026
736756d
chore: merge earlier SH-2 part into this part
Pigbibi Nov 26, 2026
94f9aa4
fix(fuse): compare caller and market closes by decimal value
Pigbibi Nov 26, 2026
f205738
chore: merge earlier SH-2 part into this part
Pigbibi Nov 26, 2026
cd7a2c1
fix(fuse): resolve Astra round-3 safety P1s in adapter and evaluator
Pigbibi Nov 26, 2026
46af4b8
chore: merge earlier SH-2 part into this part
Pigbibi Nov 26, 2026
f75ca8b
fix(fuse): guard source dates at evaluator, keep unknown shares None
Pigbibi Nov 26, 2026
4ec7887
chore: merge earlier SH-2 part into this part
Pigbibi Nov 26, 2026
784cbbd
Merge remote-tracking branch 'origin/main' into feat/sh2-part3-close-…
Pigbibi Nov 26, 2026
47f80d4
fix(feeder): address SH-2 part 3 Astra review findings
Pigbibi Nov 26, 2026
525581c
fix(feeder): reject post-cutoff or future-published market records
Pigbibi Nov 26, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
109 changes: 108 additions & 1 deletion src/shadow/calendar_consumer.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

import hashlib
import json
from collections.abc import Mapping
from datetime import date, datetime, time, timedelta, timezone
from pathlib import Path
from zoneinfo import ZoneInfo
Expand Down Expand Up @@ -242,7 +243,14 @@ def resolve_session(
"blocks_eligibility": False,
}

if observed_venue_status is not None and observed_venue_status != result["session_state"]:
venue_matches = (
observed_venue_status == result["session_state"]
or (
observed_venue_status == "core_session_open"
and result["session_state"] in ("regular", "half_day")
)
)
if observed_venue_status is not None and not venue_matches:
result["blocks_orders"] = True
result["blocks_eligibility"] = True
result["venue_disagreement"] = True
Expand Down Expand Up @@ -290,3 +298,102 @@ def resolve_prior_close_session(
return sess

return _unknown_session(venue, local_date.isoformat(), rules, spec_digest, "out_of_range")


def resolve_previous_trading_date(
spec: dict | None,
venue: str,
session_date: str,
) -> str | None:
"""Return the immediately preceding trading date strictly before session_date, or None."""
loaded = spec if spec is not None else load_spec()
rules = loaded["rules"]
if venue != rules["exchange"]:
return None
try:
cur = date.fromisoformat(session_date)
except ValueError:
return None
cov_start = date.fromisoformat(rules["coverage_start_date"])
cov_end = date.fromisoformat(rules["coverage_end_date"])
if cur <= cov_start or cur > cov_end:
return None
cand = cur - timedelta(days=1)
while cand >= cov_start:
sess = resolve_session(venue, cand.isoformat(), spec=loaded)
if sess.get("is_trading_day") and not sess.get("blocks_eligibility"):
return cand.isoformat()
cand -= timedelta(days=1)
return None


def classify_us_equity_session_window(
timestamp_utc: str,
calendar_session: Mapping[str, object],
) -> str:
"""Classify a UTC timestamp into core RTH vs US 23/5 extended/overnight session windows."""
tz = ZoneInfo(str(calendar_session.get("timezone", "America/New_York")))
iso_norm = timestamp_utc[:-1] + "+00:00" if timestamp_utc.endswith("Z") else timestamp_utc
dt_parsed = datetime.fromisoformat(iso_norm)
if dt_parsed.tzinfo is None:
raise ValueError(f"timezone_naive_timestamp:{timestamp_utc!r}")
dt_local = dt_parsed.astimezone(tz)
local_date_str = dt_local.date().isoformat()
local_t = dt_local.time()
trade_date = str(calendar_session.get("trade_date", ""))

if not calendar_session.get("is_trading_day") or calendar_session.get("blocks_eligibility"):
return "closed"
if local_date_str > trade_date:
return "next_trade_date_window"
if local_date_str < trade_date:
return "closed"
if local_t >= time(20, 0) or local_t < time(4, 0):
return "extended_overnight_open"

close_hhmm = str(calendar_session.get("close_local") or "16:00")
ch, cm = map(int, close_hhmm.split(":"))
close_t = time(ch, cm)
if time(9, 30) <= local_t <= close_t:
return "core_session_open"
if close_t < local_t < time(20, 0):
return "after_hours_extended"
if time(4, 0) <= local_t < time(9, 30):
return "pre_market_extended"
return "closed"


def is_official_close_bar_timestamp(
timestamp_utc: str,
calendar_session: Mapping[str, object],
) -> tuple[bool, str | None]:
"""Validate that a market print timestamp belongs to core RTH and not 23/5 overnight/T+1."""
tz = ZoneInfo(str(calendar_session.get("timezone", "America/New_York")))
iso_norm = timestamp_utc[:-1] + "+00:00" if timestamp_utc.endswith("Z") else timestamp_utc
try:
dt_parsed = datetime.fromisoformat(iso_norm)
if dt_parsed.tzinfo is None:
return False, "invalid_bar_timestamp"
dt_local = dt_parsed.astimezone(tz)
except ValueError:
return False, "invalid_bar_timestamp"

trade_date = str(calendar_session.get("trade_date", ""))
local_date_str = dt_local.date().isoformat()
if local_date_str > trade_date:
return False, "next_trade_date_contamination"
if local_date_str < trade_date:
return False, "session_not_in_payload"

if not calendar_session.get("is_trading_day") or calendar_session.get("blocks_eligibility"):
return False, "non_trading_session"

close_hhmm = str(calendar_session.get("close_local") or "16:00")
ch, cm = map(int, close_hhmm.split(":"))
close_t = time(ch, cm)
local_t = dt_local.time()
if local_t >= time(21, 0):
return False, "next_trade_date_contamination"
if local_t < time(9, 30) or local_t > close_t:
return False, "extended_hours_overnight_rejected"
return True, None
Loading
Loading