Update index.html
Browse files- index.html +14 -1
index.html
CHANGED
|
@@ -93,6 +93,7 @@
|
|
| 93 |
<div class="label">Position</div>
|
| 94 |
<div class="value" id="kpiPos">--</div>
|
| 95 |
<div class="small"><span class="muted">Avg cost:</span> <span id="kpiAvg">--</span></div>
|
|
|
|
| 96 |
</div>
|
| 97 |
</div>
|
| 98 |
|
|
@@ -186,6 +187,10 @@
|
|
| 186 |
orders: [],
|
| 187 |
leaderboard: []
|
| 188 |
};
|
|
|
|
|
|
|
|
|
|
|
|
|
| 189 |
|
| 190 |
const $ = (id) => document.getElementById(id);
|
| 191 |
|
|
@@ -206,8 +211,13 @@
|
|
| 206 |
txt.textContent = status[0] + status.slice(1).toLowerCase();
|
| 207 |
$("clientIdText").textContent = "路 " + state.clientId;
|
| 208 |
}
|
| 209 |
-
|
| 210 |
function recalcEquity(){
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 211 |
state.equity = state.cash + state.shares * state.price;
|
| 212 |
state.roi = ((state.equity - INITIAL_CASH) / INITIAL_CASH) * 100;
|
| 213 |
}
|
|
@@ -231,6 +241,9 @@
|
|
| 231 |
$("kpiPos").textContent = state.shares.toLocaleString();
|
| 232 |
$("kpiAvg").textContent = fmtPrice(state.avgCost);
|
| 233 |
|
|
|
|
|
|
|
|
|
|
| 234 |
const ob = $("ordersBody");
|
| 235 |
ob.innerHTML = "";
|
| 236 |
if (!state.orders.length) {
|
|
|
|
| 93 |
<div class="label">Position</div>
|
| 94 |
<div class="value" id="kpiPos">--</div>
|
| 95 |
<div class="small"><span class="muted">Avg cost:</span> <span id="kpiAvg">--</span></div>
|
| 96 |
+
<div class="small"><span class="muted">Unrealized P&L:</span> <span id="kpiUpnl">--</span></div>
|
| 97 |
</div>
|
| 98 |
</div>
|
| 99 |
|
|
|
|
| 187 |
orders: [],
|
| 188 |
leaderboard: []
|
| 189 |
};
|
| 190 |
+
|
| 191 |
+
state.upnl = 0;
|
| 192 |
+
state.upnlPct = 0;
|
| 193 |
+
|
| 194 |
|
| 195 |
const $ = (id) => document.getElementById(id);
|
| 196 |
|
|
|
|
| 211 |
txt.textContent = status[0] + status.slice(1).toLowerCase();
|
| 212 |
$("clientIdText").textContent = "路 " + state.clientId;
|
| 213 |
}
|
| 214 |
+
|
| 215 |
function recalcEquity(){
|
| 216 |
+
// Unrealized P&L of the open position
|
| 217 |
+
state.upnl = (state.price - state.avgCost) * state.shares; // works for long and short
|
| 218 |
+
const positionNotional = Math.abs(state.shares) * state.avgCost;
|
| 219 |
+
state.upnlPct = positionNotional > 0 ? (state.upnl / positionNotional) * 100 : 0;
|
| 220 |
+
|
| 221 |
state.equity = state.cash + state.shares * state.price;
|
| 222 |
state.roi = ((state.equity - INITIAL_CASH) / INITIAL_CASH) * 100;
|
| 223 |
}
|
|
|
|
| 241 |
$("kpiPos").textContent = state.shares.toLocaleString();
|
| 242 |
$("kpiAvg").textContent = fmtPrice(state.avgCost);
|
| 243 |
|
| 244 |
+
$("kpiUpnl").textContent = (state.shares === 0) ? "0" : fmtMoney(state.upnl);
|
| 245 |
+
$("kpiUpnl").style.color = (state.upnl >= 0) ? "var(--green)" : "var(--red)";
|
| 246 |
+
|
| 247 |
const ob = $("ordersBody");
|
| 248 |
ob.innerHTML = "";
|
| 249 |
if (!state.orders.length) {
|