Trying out new layout
This commit is contained in:
24
scheduler.py
24
scheduler.py
@@ -32,6 +32,23 @@ SCHEDULE = [
|
||||
(17, 0, frozenset(range(5)), False, True),
|
||||
]
|
||||
|
||||
# Saxo's access token lasts ~20 min and its refresh token rolls on each refresh
|
||||
# but lapses if unused for ~1h. Trade windows are 2-3h apart, so we roll the
|
||||
# token forward here independently to keep the refresh chain alive between runs.
|
||||
SAXO_KEEPALIVE_SEC = 300
|
||||
|
||||
|
||||
def _saxo_keepalive() -> None:
|
||||
"""Roll the Saxo OAuth token forward so its refresh token never lapses in the
|
||||
gaps between scheduled runs. No-op when there's no stored OAuth token yet
|
||||
(e.g. only the 24h env token is present)."""
|
||||
try:
|
||||
from saxo_auth import _load, get_token
|
||||
if _load().get("refresh_token"):
|
||||
get_token() # auto-refreshes when near expiry; rolls the refresh token
|
||||
except Exception as exc:
|
||||
print(f"[scheduler] saxo keep-alive: {exc}", flush=True)
|
||||
|
||||
|
||||
def _log_path() -> Path:
|
||||
today = datetime.now(timezone.utc).strftime("%Y-%m-%d")
|
||||
@@ -60,10 +77,17 @@ def _run_job(analyze_only: bool, is_report: bool) -> None:
|
||||
|
||||
def main() -> None:
|
||||
last_run: dict = {}
|
||||
last_keepalive = 0.0
|
||||
print(f"[scheduler] started — LOG_DIR={LOG_DIR}", flush=True)
|
||||
|
||||
while True:
|
||||
now = datetime.now(timezone.utc)
|
||||
|
||||
# Keep the Saxo refresh-token chain alive between trade windows.
|
||||
if time.time() - last_keepalive >= SAXO_KEEPALIVE_SEC:
|
||||
last_keepalive = time.time()
|
||||
_saxo_keepalive()
|
||||
|
||||
dow = now.weekday()
|
||||
|
||||
for hour, minute, days, analyze_only, is_report in SCHEDULE:
|
||||
|
||||
Reference in New Issue
Block a user