//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 += '
';
html += '
';
html += data.positions[index].instrument;
html += ' ';
// html += '' + data.positions[index].instrument + ' ';
html += '' + formatNumber(data.positions[index].long.units) + ' ';
html += '' + data.positions[index].long.averagePrice + ' ';
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 += '' + purchasePrice2 + ' ';
/////
var profit = data.positions[index].long.unrealizedPL;
console.log("profit /" + profit);
var totalpositionworth = parseFloat(purchasePrice) + parseFloat(profit);
console.log("totalpositionworth /" + totalpositionworth);
html += '' + formatDollar(totalpositionworth) + ' ';
if (data.positions[index].long.unrealizedPL > 0) {
html += '' + formatDollar(data.positions[index].long.unrealizedPL) + '
';
} else {
html += ' ' + formatDollar(data.positions[index].long.unrealizedPL) + '
';
}
html += ' ';
}
}
$('#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 += '';
html += '
';
html += data.positions[index].instrument;
html += ' ';
// html += '' + data.positions[index].instrument + ' ';
html += '' + data.positions[index].short.units + ' ';
html += '' + data.positions[index].short.averagePrice + ' ';
html += '' + data.positions[index].short.units * data.positions[index].short.averagePrice + ' ';
html += '' + (parseFloat(data.positions[index].short.units * data.positions[index].short.averagePrice) + parseFloat(data.positions[index].short.unrealizedPL)) + ' ';
if (data.positions[index].short.unrealizedPL > 0) {
html += '' + data.positions[index].short.unrealizedPL + '
';
} else {
html += ' $ ' + data.positions[index].short.unrealizedPL + '
';
}
html += ' ';
}
}
$('#table-positions-short > tbody').html(html);
}
function recycle() {
html += ' $ ' + response.executionReports[index].triggerJustificationReport.sma.toFixed(2) + ' ';
html += ' $ ' + response.executionReports[index].triggerJustificationReport.price.toFixed(2) + ' ';
html += '' + response.executionReports[index].triggerJustificationReport.reason + ' ';
if (response.executionReports[index].trigger) {
html += '' +
response.executionReports[index].trigger + ' ';
} else {
html += '' +
response.executionReports[index].trigger + ' ';
}
}