scripts/net-monitor.js
/**
 * Print our Stock Status into the box.
 * @param {string} logType
 * @param {Object.<string,Server>} servers
 * @param {Element} box
 * @param {NS} ns
 */
Print our Stock Status into the box.
Print our Stock Status into the box .
function printStockStatus(logType, servers, box, ns) {
    const insideWidth = 48;
    let positionSummary = [];
    let output = [];
    let printfn = (obj) => output.push(obj);
    let print1Column = (data) => printItemsNColumns(data, 1, printfn);
    let print2Column = (data) => printItemsNColumns(data, 2, printfn);
    let print3Column = (data) => printItemsNColumns(data, 3, printfn);
    let symbols = ns.stock.getSymbols().sort();
    for (const symbol of symbols) {
        let position = ns.stock.getPosition(symbol);
        let nLong = position[0];
        let pLong = position[1];
        let nShort = position[2];
        let pShort = position[3];
        if (nLong + nShort > 0) {
            let lines = [];
            lines.push(`Current Price ${ns.nFormat(ns.stock.getPrice(symbol), '$0.00a')}`);
            if (nLong > 0) {
                const spent = nLong * pLong;
                let profit = ns.stock.getSaleGain(symbol, nLong, 'Long') - spent;
                let profits = ns.nFormat(profit, '$0.00a');
                if (profit > 0) profits = '+' + profits;
                let part1 = pad(Array(40).join(' '), `Holding ${ns.nFormat(nLong, '0.0a')} @ ${ns.nFormat(pLong, '$0.00a')} (${ns.nFormat(spent, '$0.0a')}) `);
                let part2 = pad(Array(10).join(' '), `${profits}`, true);
                lines.push(`${part1}${part2}`);
            }
            if (nShort > 0) {
                const spent = nShort * pShort;
                let profit = ns.stock.getSaleGain(symbol, nShort, 'Short') - spent;
                let profits = ns.nFormat(profit, '$0.00a');
                if (profit > 0) profits = '+' + profits;
                let part1 = pad(Array(40).join(' '), `Shorted ${ns.nFormat(nShort, '0.0a')} @ ${ns.nFormat(pShort, '$0.00a')} (${ns.nFormat(spent, '$0.0a')}) `);
                let part2 = pad(Array(10).join(' '), `${profits}`, true);
                lines.push(`${part1}${part2}`);
            }
            positionSummary.push(boxdraw(lines, symbol, insideWidth));
        }
    }
    let htmlFormat = (s) => {
        if (s === '') return '</br>';
        return `<p>${s}</p>`;
    };
    let monitorElem = box.querySelector('.panopticon-monitor');
    if (positionSummary.length > 16) {
        print3Column(positionSummary);
    } else if (positionSummary.length > 8) {
        print2Column(positionSummary);
    } else {
        print1Column(positionSummary);
    }
    monitorElem.innerHTML = output.map((line) => htmlFormat(line)).join('');
}
function printStockStatus ( logType , servers , box , ns ) { const insideWidth = 48 ; let positionSummary = [ ] ; let output = [ ] ; let printfn = ( obj ) => output . push ( obj ) ; let print1Column = ( data ) => printItemsNColumns ( data , 1 , printfn ) ; let print2Column = ( data ) => printItemsNColumns ( data , 2 , printfn ) ; let print3Column = ( data ) => printItemsNColumns ( data , 3 , printfn ) ; let symbols = ns . stock . getSymbols ( ) . sort ( ) ; for ( const symbol of symbols ) { let position = ns . stock . getPosition ( symbol ) ; let nLong = position [ 0 ] ; let pLong = position [ 1 ] ; let nShort = position [ 2 ] ; let pShort = position [ 3 ] ; if ( nLong + nShort > 0 ) { let lines = [ ] ; lines . push ( ` ${ ns . nFormat ( ns . stock . getPrice ( symbol ) , '$0.00a' ) } ` ) ; if ( nLong > 0 ) { const spent = nLong * pLong ; let profit = ns . stock . getSaleGain ( symbol , nLong , 'Long' ) - spent ; let profits = ns . nFormat ( profit , '$0.00a' ) ; if ( profit > 0 ) profits = '+' + profits ; let part1 = pad ( Array ( 40 ) . join ( ' ' ) , ` ${ ns . nFormat ( nLong , '0.0a' ) } ${ ns . nFormat ( pLong , '$0.00a' ) } ${ ns . nFormat ( spent , '$0.0a' ) } ` ) ; let part2 = pad ( Array ( 10 ) . join ( ' ' ) , ` ${ profits } ` , true ) ; lines . push ( ` ${ part1 } ${ part2 } ` ) ; } if ( nShort > 0 ) { const spent = nShort * pShort ; let profit = ns . stock . getSaleGain ( symbol , nShort , 'Short' ) - spent ; let profits = ns . nFormat ( profit , '$0.00a' ) ; if ( profit > 0 ) profits = '+' + profits ; let part1 = pad ( Array ( 40 ) . join ( ' ' ) , ` ${ ns . nFormat ( nShort , '0.0a' ) } ${ ns . nFormat ( pShort , '$0.00a' ) } ${ ns . nFormat ( spent , '$0.0a' ) } ` ) ; let part2 = pad ( Array ( 10 ) . join ( ' ' ) , ` ${ profits } ` , true ) ; lines . push ( ` ${ part1 } ${ part2 } ` ) ; } positionSummary . push ( boxdraw ( lines , symbol , insideWidth ) ) ; } } let htmlFormat = ( s ) => { if ( s === '' ) return '</br>' ; return ` ${ s } ` ; } ; let monitorElem = box . querySelector ( '.panopticon-monitor' ) ; if ( positionSummary . length > 16 ) { print3Column ( positionSummary ) ; } else if ( positionSummary . length > 8 ) { print2Column ( positionSummary ) ; } else { print1Column ( positionSummary ) ; } monitorElem . innerHTML = output . map ( ( line ) => htmlFormat ( line ) ) . join ( '' ) ; }
Print our Stock Status into the box.
Print our Stock Status into the box .