Initial working version, positions show.
This commit is contained in:
32
frontend/app.js
Normal file
32
frontend/app.js
Normal file
@@ -0,0 +1,32 @@
|
||||
// Minimal vanilla-JS frontend to poll only positions and render the positions table
|
||||
const qs = (s) => document.querySelector(s);
|
||||
const ptbody = qs('#positions-table tbody');
|
||||
|
||||
async function fetchJson(path) {
|
||||
const res = await fetch(path);
|
||||
if (!res.ok) throw new Error('Network response not ok');
|
||||
return res.json();
|
||||
}
|
||||
|
||||
function renderPositions(list) {
|
||||
ptbody.innerHTML = '';
|
||||
for (const p of list) {
|
||||
const row = document.createElement('tr');
|
||||
const avg = p.averageCost ?? p.average_cost ?? '';
|
||||
row.innerHTML = `<td>${p.symbol}</td><td>${p.position}</td><td>${avg}</td><td>${p.account ?? ''}</td>`;
|
||||
ptbody.appendChild(row);
|
||||
}
|
||||
}
|
||||
|
||||
async function pollPositions() {
|
||||
try {
|
||||
const positions = await fetchJson('/api/positions');
|
||||
renderPositions(positions);
|
||||
} catch (e) {
|
||||
console.warn('Positions polling error', e);
|
||||
}
|
||||
}
|
||||
|
||||
// start polling every 2 seconds
|
||||
pollPositions();
|
||||
setInterval(pollPositions, 2000);
|
||||
Reference in New Issue
Block a user