automated terminal push
This commit is contained in:
250
web/pages/populate-top-bar.js
Executable file
250
web/pages/populate-top-bar.js
Executable file
@@ -0,0 +1,250 @@
|
||||
|
||||
//var apiURL = "http://veneno.embanet.online:8888";
|
||||
|
||||
//var apiURL = "http://aventador.embanet.online:4242";
|
||||
|
||||
var apiURL = "https://apis.projectchimba.valorantdigital.com";
|
||||
|
||||
function formatNumber(number) {
|
||||
|
||||
return Math.round(number).toLocaleString();
|
||||
|
||||
}
|
||||
|
||||
|
||||
function formatDollar(number) {
|
||||
|
||||
return '$ ' + Math.round(number).toLocaleString();
|
||||
|
||||
}
|
||||
|
||||
|
||||
$(document).ready(function () {
|
||||
|
||||
getAccountInformation();
|
||||
|
||||
setInterval(getAccountInformation, 1000 * 10);
|
||||
|
||||
});
|
||||
|
||||
function getAccountInformation() {
|
||||
|
||||
console.debug("enter > getAccountInformation");
|
||||
|
||||
$.ajax({
|
||||
|
||||
type: "GET",
|
||||
|
||||
url: apiURL + "/broker/account",
|
||||
|
||||
contentType: "text/plain",
|
||||
|
||||
crossDomain: true,
|
||||
|
||||
success: function (data, status, exception) {
|
||||
|
||||
updateComponentsWithLiveData(data);
|
||||
|
||||
},
|
||||
|
||||
error: function (exception, status) {
|
||||
|
||||
console.log("exception", exception);
|
||||
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
console.debug("exit < getAccountInformation");
|
||||
|
||||
}
|
||||
|
||||
function updateComponentsWithLiveData(data) {
|
||||
|
||||
$('#account-sidebar-name').html(data.alias);
|
||||
|
||||
$('#account-topright-name').html(data.alias);
|
||||
|
||||
$('#account-bar-nav').html(formatDollar(data.nav));
|
||||
|
||||
$('#account-sidebar-nav').html(formatDollar(data.nav));
|
||||
|
||||
//////
|
||||
|
||||
$('#account-bar-balance').html(formatDollar(data.balance));
|
||||
|
||||
$('#account-bar-position-value').html(formatDollar(data.positionValue));
|
||||
|
||||
$('#account-bar-profit').html(formatDollar(data.pl));
|
||||
|
||||
|
||||
populateLongPositionsTable(data);
|
||||
|
||||
populateShortPositionsTable(data);
|
||||
|
||||
}
|
||||
|
||||
////////////////////////////
|
||||
|
||||
|
||||
function populateLongPositionsTable(data) {
|
||||
|
||||
var html = '';
|
||||
|
||||
var rowCount = 0;
|
||||
|
||||
for (var index = data.positions.length - 1; index >= 0; index--) {
|
||||
|
||||
// increment counter and break on threshold break
|
||||
|
||||
rowCount = rowCount + 1;
|
||||
|
||||
if (rowCount > 50) {
|
||||
|
||||
break;
|
||||
|
||||
}
|
||||
|
||||
if (data.positions[index].long.units > 0) {
|
||||
|
||||
html += '<tr>';
|
||||
|
||||
html += '<td> <div class="form-check form-check-muted m-0"> <label class="form-check-label"> <input type="checkbox" class="form-check-input"> <i class="input-helper"></i><i class="input-helper"></i><i class="input-helper"></i></label> </div> </td> <td> <img src="assets/images/faces/face1.jpg" alt="image"> <span class="ps-2">';
|
||||
|
||||
html += data.positions[index].instrument;
|
||||
|
||||
html += '</span> </td>';
|
||||
|
||||
// html += '<td class="">' + data.positions[index].instrument + '</td>';
|
||||
|
||||
html += '<td class="">' + formatNumber(data.positions[index].long.units) + '</td>';
|
||||
|
||||
html += '<td class="">' + data.positions[index].long.averagePrice + '</td>';
|
||||
|
||||
var purchasePrice = data.positions[index].long.units * data.positions[index].long.averagePrice;
|
||||
|
||||
console.log("purchasePrice /" + purchasePrice);
|
||||
|
||||
var purchasePrice2 = formatDollar(purchasePrice);
|
||||
|
||||
console.log("purchasePrice2 /" + purchasePrice2);
|
||||
|
||||
//alert(purchasePrice2);
|
||||
|
||||
html += '<td class="">' + purchasePrice2 + '</td>';
|
||||
|
||||
|
||||
|
||||
|
||||
/////
|
||||
|
||||
var profit = data.positions[index].long.unrealizedPL;
|
||||
|
||||
console.log("profit /" + profit);
|
||||
|
||||
var totalpositionworth = parseFloat(purchasePrice) + parseFloat(profit);
|
||||
|
||||
console.log("totalpositionworth /" + totalpositionworth);
|
||||
|
||||
|
||||
html += '<td class="">' + formatDollar(totalpositionworth) + '</td>';
|
||||
|
||||
if (data.positions[index].long.unrealizedPL > 0) {
|
||||
|
||||
html += '<td><div class="badge badge-outline-success">' + formatDollar(data.positions[index].long.unrealizedPL) + '</div></td>';
|
||||
|
||||
} else {
|
||||
|
||||
html += '<td><div class="badge badge-outline-danger"> ' + formatDollar(data.positions[index].long.unrealizedPL) + '</div></td>';
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
html += '</tr>';
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
$('#table-positions-long > tbody').html(html);
|
||||
|
||||
}
|
||||
|
||||
function populateShortPositionsTable(data) {
|
||||
|
||||
var html = '';
|
||||
|
||||
var rowCount = 0;
|
||||
|
||||
for (var index = data.positions.length - 1; index >= 0; index--) {
|
||||
|
||||
// increment counter and break on threshold break
|
||||
|
||||
rowCount = rowCount + 1;
|
||||
|
||||
if (rowCount > 50) {
|
||||
|
||||
break;
|
||||
|
||||
}
|
||||
|
||||
if (data.positions[index].short.units < 0) {
|
||||
|
||||
html += '<tr>';
|
||||
|
||||
html += '<td> <div class="form-check form-check-muted m-0"> <label class="form-check-label"> <input type="checkbox" class="form-check-input"> <i class="input-helper"></i><i class="input-helper"></i><i class="input-helper"></i></label> </div> </td> <td> <img src="assets/images/faces/face1.jpg" alt="image"> <span class="ps-2">';
|
||||
|
||||
html += data.positions[index].instrument;
|
||||
|
||||
|
||||
html += '</span> </td>';
|
||||
|
||||
// html += '<td class="">' + data.positions[index].instrument + '</td>';
|
||||
|
||||
html += '<td class="">' + data.positions[index].short.units + '</td>';
|
||||
html += '<td class="">' + data.positions[index].short.averagePrice + '</td>';
|
||||
|
||||
html += '<td class="">' + data.positions[index].short.units * data.positions[index].short.averagePrice + '</td>';
|
||||
|
||||
html += '<td class="">' + (parseFloat(data.positions[index].short.units * data.positions[index].short.averagePrice) + parseFloat(data.positions[index].short.unrealizedPL)) + '</td>';
|
||||
|
||||
if (data.positions[index].short.unrealizedPL > 0) {
|
||||
html += '<td><div class="badge badge-outline-success">' + data.positions[index].short.unrealizedPL + '</div></td>';
|
||||
} else {
|
||||
html += '<td><div class="badge badge-outline-danger"> $ ' + data.positions[index].short.unrealizedPL + '</div></td>';
|
||||
}
|
||||
html += '</tr>';
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
$('#table-positions-short > tbody').html(html);
|
||||
|
||||
}
|
||||
|
||||
function recycle() {
|
||||
|
||||
html += '<td> $ ' + response.executionReports[index].triggerJustificationReport.sma.toFixed(2) + '</td>';
|
||||
|
||||
html += '<td> $ ' + response.executionReports[index].triggerJustificationReport.price.toFixed(2) + '</td>';
|
||||
|
||||
html += '<td>' + response.executionReports[index].triggerJustificationReport.reason + '</td>';
|
||||
|
||||
if (response.executionReports[index].trigger) {
|
||||
|
||||
html += '<td><span class="badge pill bg-primary">' +
|
||||
response.executionReports[index].trigger + '</span></td>';
|
||||
|
||||
} else {
|
||||
|
||||
html += '<td><span class="badge pill bg-secondary">' +
|
||||
response.executionReports[index].trigger + '</span></td>';
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user