← Kembali

Watchlist Enhancements — IHSG, Top Picks & Auto-Refresh

cron dashboard ihsg watchlist

errors

  • Cron timezone mismatch (critical): Semua cron job di PM2 berjalan pada waktu yang salah. radar-analysis di-set 0 4 * * * (asumsi 04:00 WIB), tapi server menggunakan UTC. Akibatnya analysis berjalan jam 04:00 UTC = 11:00 WIB (pagi, pas market baru buka). Sniper-fetcher di-set 0 12 * * * (asumsi 12:00 WIB) tapi jalan jam 12:00 UTC = 19:00 WIB (salah — harusnya 03:00 WIB dini hari).
  • IHSG fetch error di log: ERROR yfinance $^JKSE: possibly delisted; no price data found (period=2d) WARNING dashboard.context_processors IHSG fetch failed: single positional indexer is out-of-bounds Ini terjadi terutama di weekend/hari libur saat yfinance return data kosong.
  • IHSG tidak ada: User harus buka website terpisah untuk liat indeks harga saham gabungan.
  • Tidak ada highlight saham terbaik: Score ≥ 8 tidak ditampilkan secara khusus — tenggelam di antara 900+ saham lain.

context

Watchlist adalah halaman utama yang dilihat user setiap kali buka dashboard. Tapi halaman ini masih kurang fitur overview: tidak ada IHSG bar, tidak ada section untuk saham terbaik (top recommended / most potential), dan tidak ada auto-refresh — user harus refresh browser manual setiap kali mau liat update harga real-time. Di sisi infrastruktur, cron job radar-analysis dan sniper-fetcher berjalan di waktu yang salah karena timezone mismatch antara konfigurasi dan server.

investigation

  1. Cron timezone: Cek log PM2 — radar-analysis jalan jam 11:00 WIB (seharusnya 04:00 WIB atau 18:00 WIB). Cek dokumentasi PM2 cron — PM2 menggunakan system timezone servers, yaitu UTC. Semua cron ditulis dengan asumsi WIB. Debug timezone: bash # Cara debug timezone PM2 cron: # $ pm2 show radar-analysis | grep "restart at" # Atau cek langsung: system timezone = UTC # $ timedatectl | grep "Time zone" → "Etc/UTC" Fix: konversi semua jadwal WIB ke UTC.
  2. 08:00 WIB = 01:00 UTC → 0 1 * * *
  3. 17:00 WIB = 10:00 UTC → 0 10 * * *
  4. 03:00 WIB = 20:00 UTC (hari sebelumnya) → 0 20 * * *
  5. IHSG: Cek endpoint — yfinance bisa fetch ^JKSE untuk IHSG. Tapi panggilan tiap render bakal boros (rate limit yfinance). Solusi: context processor dengan in-memory cache 5 menit TTL.
  6. Top picks: Cek data — ada stocks dengan score ≥ 8 di smart_stock_scores. Cukup query WHERE score >= 8 di context processor. Most Potential: top 20 by score.
  7. Auto-refresh: Cek JavaScript existing — watchlist pake jQuery + DataTables. Bisa tambah setInterval untuk reload sebagian (pake AJAX) atau reload penuh.

root-cause

  1. Cron timezone: Root cause: semua cron dikonfigurasi di ecosystem.config.js tanpa mempertimbangkan timezone server. Developer ngetik jam WIB secara intuitif, lupa bahwa server pake UTC. Ini masalah umum di server yang user-base-nya di timezone berbeda.
  2. Missing features: Watchlist dikembangkan incremental — fitur overview (IHSG, top picks, auto-refresh) tidak termasuk di MVP karena prioritas awal adalah fungsi dasar (tabel, filter, sort). Sekarang setelah basic functional, saatnya polish.
  3. IHSG cache: Tanpa cache, setiap page load akan fetch yfinance — ini boros dan riskan kena rate limit. Context processor jalan di setiap request, jadi harus di-cache.

solution

  1. Cron UTC fix di ecosystem.config.js: javascript // ecosystem.config.js — cron dalam UTC // Sebelum (salah — asumsi WIB): // "0 4 * * *" = 04:00 WIB → sebenernya 04:00 UTC = 11:00 WIB ❌ // Sesudah (benar — UTC): // "0 11,21 * * *" = 11:00 UTC = 18:00 WIB, 21:00 UTC = 04:00 WIB ✅
  2. radar-analysis: 0 11,21 * * * (18:00 & 04:00 WIB)
  3. sniper-fetcher: 0 20 * * * (03:00 WIB — masih UTC hari sebelumnya, tapi untuk daily cron dianggap next-day)
  4. radar-analysis-quick: */10 1-10 * * * (08:00-17:50 WIB = 01:00-10:50 UTC)
  5. radar-tier-classifier: 0 1 * * * (08:00 WIB — sudah benar)
  6. IHSG Bar: Tambah ^JKSE fetch di context processor dengan in-memory cache dictionary + time.time() check. 5 menit TTL. Warna hijau/merah berdasarkan change.
  7. Top Recommended: Query SELECT * FROM smart_stock_scores WHERE score >= 8 — tampilkan di watchlist atas.
  8. Most Potential: Top 20 stocks by score — tampilkan di samping Top Recommended.
  9. Auto-Refresh: JavaScript setInterval(5000) untuk reload tiap 5 menit. Pake location.reload() sederhana — tidak perlu partial update karena DataTables akan maintain state.

insight

  • Timezone adalah akar banyak bug cron: PM2, cron system, dan Docker semuanya bisa punya timezone berbeda. Selalu dokumentasikan timezone di konfigurasi cron, dan lebih baik pake UTC + mapping WIB di komentar.
  • Cache pattern sederhana: In-memory cache dictionary dengan time.time() lebih dari cukup untuk use case ini. Tidak perlu Redis atau memcached — 5 menit TTL dengan data kecil (1 baris IHSG) aman di memory.
  • Auto-refresh 5 menit cukup: Tidak perlu real-time streaming. Untuk dashboard investasi, refresh 5 menit sudah dianggap real-time oleh user.
  • Sort by column + sektor hidden: Fitur sort yang interaktif (click header) bikin UX lebih baik. Sektor yang banyak (Uncategorized di bottom) bisa di-hidden.

gotchas

  • DST (Daylight Saving Time): Indonesia tidak pakai DST (WIB konsisten UTC+7), tapi tetap hati-hati kalau server di zona yang pake DST. PM2 cron selalu UTC — jadi aman.
  • IHSG cache TTL: 5 menit TTL berarti ada delay maksimal 5 menit dari market real IHSG. Acceptable untuk dashboard, tapi jangan dipakai untuk trading decision real-time.
  • Auto-refresh vs user sort: location.reload() akan reset sort/filter user. Kalau mau lebih advanced, perlu partial refresh via AJAX.
  • yfinance rate limit: IHSG fetch pake yfinance — meski 1 request per 5 menit, tetap riskan kalau banyak user. Context processor di sisi server artinya 1 fetch untuk semua user — aman.
  • Score ≥ 8 mungkin kosong: Kalau threshold scoring lagi ketat (seperti sekarang, banyak AVOID), Top Recommended bisa kosong. Siapkan fallback messaging: "Tidak ada saham dengan skor ≥ 8 saat ini."

Terakhir diperbarui 31 Jul 2026 00:15

Comments