Stock Tread

Master the Markets with Real-time Simulation

doc.setFontSize(11); doc.setTextColor(100); doc.text(`User: ${user.email}`, 14, 30); doc.text(`Date: ${new Date().toLocaleString()}`, 14, 36); const headers = [['Time', 'Type', 'Symbol', 'Qty', 'Price', 'Total']]; const data = user.history.map(h => [ h.time, h.type.toUpperCase(), h.sym, h.qty, fmtMoney(h.price), fmtMoney(h.price * h.qty) ]); doc.autoTable({ head: headers, body: data, startY: 44, theme: 'grid', headStyles: { fillColor: [41, 98, 255] }, styles: { fontSize: 9 } }); doc.save(`trade_history_${new Date().toISOString().slice(0, 10)}.pdf`); } function fmtMoney(n) { return '$' + n.toLocaleString('en-US', { minimumFractionDigits: 2, maximumFractionDigits: 2 }); } function showSection(id) { document.querySelectorAll('.content-section').forEach(el => el.style.display = 'none'); document.querySelectorAll('.sidebar-btn').forEach(el => el.classList.remove('active')); document.getElementById(id + 'Section').style.display = 'block'; document.getElementById('nav-' + id).classList.add('active'); if (id === 'screener') renderScreener(); if (id === 'heatmap') renderHeatmap(); if (id === 'news') renderNews(); if (id === 'history') document.getElementById('historyList').innerHTML = user.history.map(h => `
${h.type.toUpperCase()}${h.sym}
${h.qty} @ ${fmtMoney(h.price)}
${h.time}
`).join(''); if (window.innerWidth < 768) { document.getElementById('sidebar').classList.remove('mobile-open'); document.querySelector('.sidebar-overlay').classList.remove('active'); } } function loadTheme() { const savedTheme=localStorage.getItem('stp_theme') || 'light' ; isDark=savedTheme==='dark' ; applyTheme(); } function toggleTheme() { isDark=!isDark; localStorage.setItem('stp_theme', isDark ? 'dark' : 'light' ); applyTheme(); } function applyTheme() { document.body.setAttribute('data-theme', isDark ? 'dark' : 'light' ); document.getElementById('themeBtn').innerHTML=isDark ? '' : '' ; if (chart) chart.updateOptions({ theme: { mode: isDark ? 'dark' : 'light' }, grid: { borderColor: isDark ? '#2b2b40' : '#e0e0e0' } }); if (portfolioChart) portfolioChart.updateOptions({ theme: { mode: isDark ? 'dark' : 'light' } }); } function updateUsername() { const newName=document.getElementById('settingsUsernameInput').value.trim(); if(newName) { user.username=newName; saveUserData(); showApp(); showToast('Username updated', 'success' ); } } function uploadAvatar(input) { if (input.files && input.files[0]) { const reader=new FileReader(); reader.onload=function(e) { user.avatar=e.target.result; saveUserData(); updateAvatarDisplay(); showToast('Profile picture updated', 'success' ); } reader.readAsDataURL(input.files[0]); } } function removeAvatar() { user.avatar=null; saveUserData(); updateAvatarDisplay(); showToast('Profile picture removed', 'info' ); } function updateAvatarDisplay() { const name=user.username || user.email || 'User' ; const def=`https://ui-avatars.com/api/?name=${encodeURIComponent(name)}&background=2962ff&color=fff&size=150`; const src=user.avatar || def; document.getElementById('sidebarAvatar').src=src; document.getElementById('settingsAvatar').src=src; } function populateAlertSelect() { document.getElementById('alertSymbol').innerHTML=stocks.map(s=> ` `).join(''); } function showToast(m, t) { const a = document.getElementById('toastArea'), e = document.createElement('div'); e.className = `toast align-items-center text-white bg-${t === 'error' ? 'danger' : (t === 'success' ? 'success' : 'dark')} border-0 show mb-2 shadow`; e.innerHTML = `
${m}
`; a.appendChild(e); setTimeout(() => e.remove(), 3000); }