Fix live mt5 ea's page to fetch ftp data, then update cache before rendering.
Fix Live mt5 ea's autofresh to fetch ftp data, update cache then render.
This commit is contained in:
+11
-14
@@ -457,9 +457,10 @@ cache/
|
|||||||
|
|
||||||
acc_map = {a["account"]: a for a in acc_cfgs}
|
acc_map = {a["account"]: a for a in acc_cfgs}
|
||||||
|
|
||||||
# Initialise auto-refresh timer to now on first page load
|
# Initialise auto-refresh timer — first load always pulls from FTP
|
||||||
if "ftp_last_auto_refresh" not in st.session_state:
|
first_load = "ftp_last_auto_refresh" not in st.session_state
|
||||||
st.session_state["ftp_last_auto_refresh"] = datetime.now().timestamp()
|
if first_load:
|
||||||
|
st.session_state["ftp_last_auto_refresh"] = 0 # force pull on first load
|
||||||
|
|
||||||
# ── Auto-load on first visit + Refresh ────────────────────────────────────
|
# ── Auto-load on first visit + Refresh ────────────────────────────────────
|
||||||
ages = [cache_age_minutes(a["account"]) for a in acc_cfgs
|
ages = [cache_age_minutes(a["account"]) for a in acc_cfgs
|
||||||
@@ -480,19 +481,15 @@ cache/
|
|||||||
oldest = max(ages)
|
oldest = max(ages)
|
||||||
st.caption(f"Updated {oldest:.0f}m ago")
|
st.caption(f"Updated {oldest:.0f}m ago")
|
||||||
|
|
||||||
# Auto-refresh via polling — only trigger after poll_interval has passed
|
# Auto-refresh: trigger on first load, manual refresh, or when interval elapsed
|
||||||
# since the last actual refresh (tracked in session state)
|
last_auto = st.session_state.get("ftp_last_auto_refresh", 0)
|
||||||
auto_refresh = False
|
now_ts = datetime.now().timestamp()
|
||||||
if poll_interval > 0 and ages and not no_cache:
|
interval_elapsed = poll_interval > 0 and (now_ts - last_auto) >= poll_interval * 60
|
||||||
last_auto = st.session_state.get("ftp_last_auto_refresh", 0)
|
auto_refresh = first_load or interval_elapsed
|
||||||
now_ts = datetime.now().timestamp()
|
|
||||||
if (now_ts - last_auto) >= poll_interval * 60:
|
|
||||||
auto_refresh = True
|
|
||||||
|
|
||||||
if do_refresh or no_cache or auto_refresh:
|
if do_refresh or no_cache or auto_refresh:
|
||||||
if auto_refresh and not do_refresh:
|
st.session_state["ftp_last_auto_refresh"] = datetime.now().timestamp()
|
||||||
st.session_state["ftp_last_auto_refresh"] = datetime.now().timestamp()
|
label_text = "Loading..." if (no_cache or first_load) else "Refreshing..."
|
||||||
label_text = "Loading..." if no_cache else "Refreshing..."
|
|
||||||
prog = st.progress(0, text=label_text)
|
prog = st.progress(0, text=label_text)
|
||||||
errors = []
|
errors = []
|
||||||
for i, acfg in enumerate(acc_cfgs):
|
for i, acfg in enumerate(acc_cfgs):
|
||||||
|
|||||||
Reference in New Issue
Block a user