Add live auto-refresh every 3s using streamlit-autorefresh

This commit is contained in:
addychai355-create
2026-05-12 22:32:49 +08:00
parent 539d313e59
commit d281799b30
3 changed files with 11 additions and 2 deletions
+5 -1
View File
@@ -31,6 +31,7 @@ st.markdown("""
# ─── Import strategy ───
from strategies.xau_scalp import add_indicators_xau, generate_signals_xau, calculate_performance_xau
from streamlit_autorefresh import st_autorefresh
# ─── Fetch XAU/USD data directly ───
def fetch_gold(tf="5m", days=3):
@@ -49,6 +50,9 @@ def fetch_gold(tf="5m", days=3):
def format_price(v):
return f"${v:,.2f}" if v == v else ""
# ─── Auto-refresh every 3 seconds ───
st_autorefresh(interval=3000, key="goldrefresh", limit=None)
# ─── Load & compute ───
df = fetch_gold("5m", 3)
if df is None or len(df) < 60:
@@ -199,4 +203,4 @@ else:
# ─── Footer ───
st.markdown("---")
st.markdown("<p style='text-align:center;color:#3D4048;font-size:0.6rem;'>Data: Yahoo Finance GC=F · Refresh page to update</p>", unsafe_allow_html=True)
st.markdown("<p style='text-align:center;color:#3D4048;font-size:0.6rem;'>Data: Yahoo Finance GC=F · Live auto-refresh</p>", unsafe_allow_html=True)
+1
View File
@@ -8,3 +8,4 @@ yfinance>=0.2.28
scikit-learn>=1.3
scipy>=1.11
python-dotenv>=1.0
streamlit-autorefresh>=1.0
+5 -1
View File
@@ -31,6 +31,7 @@ st.markdown("""
# ─── Import strategy ───
from strategies.xau_scalp import add_indicators_xau, generate_signals_xau, calculate_performance_xau
from streamlit_autorefresh import st_autorefresh
# ─── Fetch XAU/USD data directly ───
def fetch_gold(tf="5m", days=3):
@@ -49,6 +50,9 @@ def fetch_gold(tf="5m", days=3):
def format_price(v):
return f"${v:,.2f}" if v == v else ""
# ─── Auto-refresh every 3 seconds ───
st_autorefresh(interval=3000, key="goldrefresh", limit=None)
# ─── Load & compute ───
df = fetch_gold("5m", 3)
if df is None or len(df) < 60:
@@ -199,4 +203,4 @@ else:
# ─── Footer ───
st.markdown("---")
st.markdown("<p style='text-align:center;color:#3D4048;font-size:0.6rem;'>Data: Yahoo Finance GC=F · Refresh page to update</p>", unsafe_allow_html=True)
st.markdown("<p style='text-align:center;color:#3D4048;font-size:0.6rem;'>Data: Yahoo Finance GC=F · Live auto-refresh</p>", unsafe_allow_html=True)