Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
4 changes: 4 additions & 0 deletions qtrade/intraday/crm_sheet.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@

TAB = "CRM tracker"
BOOK_USD = 10_000.0
MARK_AFTER_MIN = 17 * 60 # mark only after 17:00 New York (metal futures settle 13:30-14:00, REMX/PICK at 16:00)
LOG_HEADER = ["Date", "Day P&L $", "Day %", "Equity $", "Legs open", "Rebalanced", "Note"]
POS_HEADER = ["Source", "Commodity", "Instrument", "Signal", "Position", "Notional $", "Entry date", "Entry price",
"Last mark", "Mark price", "Open P&L $"]
Expand Down Expand Up @@ -152,6 +153,9 @@ def run(rules: list[dict], sat_cache: Path, dry_run: bool = False) -> dict:
now = pd.Timestamp.now(tz="America/New_York")
today = now.tz_localize(None).normalize()
day = f"{today:%Y-%m-%d}"
if now.hour * 60 + now.minute < MARK_AFTER_MIN:
# futures trade overnight, so before the close Yahoo already has a partial bar for today
return {"skipped": f"{now:%H:%M} New York is before the {MARK_AFTER_MIN // 60}:{MARK_AFTER_MIN % 60:02d} mark"}
sheet = None if dry_run else CrmSheet(os.environ["HFT_SHEET_ID"], os.environ["GOOGLE_SERVICE_ACCOUNT_JSON"])
log, positions = sheet.state() if sheet else ([], pd.DataFrame(columns=POS_HEADER))
if log and str(log[-1][0])[:10] == day:
Expand Down
11 changes: 11 additions & 0 deletions tests/test_crm_so2_tracker.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,3 +135,14 @@ def fake_collect(a, b):
assert len(out) == 2
assert not (tmp_path / "s5p_2021-05.parquet").exists()
assert (tmp_path / "s5p_2021-06.parquet").exists()


def test_tracker_does_not_mark_before_the_close(monkeypatch):
import pandas as pd

from qtrade.intraday import crm_sheet as T

monkeypatch.setattr(T.pd.Timestamp, "now", classmethod(
lambda cls, tz=None: pd.Timestamp("2026-11-24 01:25", tz="America/New_York")))
out = T.run([], T.Path("."), dry_run=True)
assert "before" in out["skipped"]
Loading