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);
|
||||
28
frontend/index.html
Normal file
28
frontend/index.html
Normal file
@@ -0,0 +1,28 @@
|
||||
<!doctype html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="utf-8" />
|
||||
<meta name="viewport" content="width=device-width,initial-scale=1" />
|
||||
<title>IB Dashboard</title>
|
||||
<style>
|
||||
body { font-family: system-ui, -apple-system, "Segoe UI", Roboto, Arial; margin: 20px; }
|
||||
input, button { padding: 6px 8px; margin-right: 6px }
|
||||
table { border-collapse: collapse; width: 100%; margin-top: 12px }
|
||||
th, td { border: 1px solid #ddd; padding: 8px; text-align: left }
|
||||
th { background: #f4f4f4 }
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<h1>Interactive Brokers Dashboard</h1>
|
||||
|
||||
<section>
|
||||
<h2>Positions</h2>
|
||||
<table id="positions-table">
|
||||
<thead><tr><th>Symbol</th><th>Position</th><th>Average Cost</th><th>Account</th></tr></thead>
|
||||
<tbody></tbody>
|
||||
</table>
|
||||
</section>
|
||||
|
||||
<script src="/static/app.js"></script>
|
||||
</body>
|
||||
</html>
|
||||
Reference in New Issue
Block a user