Basic Script for BN8.1 Advanced Script for BN8.2-3 & BN8+ Achievement in Bitburner.
BN8.1
function round(value) { let signs = ["", "k", "m", "b", "t"] let which = 0 while (value > 999 || value < -999) { value = Math.round(value / 10) / 100 ++which } return value + signs[which] } /** @param {NS} ns */ export async function main(ns) { ns.disableLog("ALL") let index = ns.args[0] // should be FSIG or FLCM let history = [] let max_shares = ns.stock.getMaxShares(index) let max_history = 40 let fee = 100000 while (true) { let money = (ns.getServerMoneyAvailable("home") - fee) * 0.9 let price = ns.stock.getPrice(index) let my_shares = ns.stock.getPosition(index)[0] ns.clearLog() if (history.length > (max_history - 1)) { if (price > Math.max(...history)) { let buy = Math.floor((money / price)) if ((buy + my_shares) > max_shares) { buy = max_shares - my_shares } if (buy > 0 && (price * buy) > 10000000) { ns.print("Buy(Long): " + ns.stock.buy(index, buy)) } } else if (price < Math.min(...history)) { if (my_shares > 0) { ns.print("Sell(Long): " + ns.stock.sell(index, my_shares)) } } } history.splice(0, 0, price) if (history.length > max_history) { history.pop() } let profit = ns.stock.getSaleGain(index, my_shares, "Long") ns.print("Index: " + index) ns.print("Max Shares: " + round(max_shares)) ns.print("My Long Shares: " + round(ns.stock.getPosition(index)[0])) ns.print("Price: $" + round(price)) ns.print("History saved: " + history.length) ns.print("Highest Price: $" + round(Math.max(...history))) ns.print("Lowest Price: $" + round(Math.min(...history))) ns.print("-------------------------") ns.print("Profit: $" + round(profit)) ns.print("-------------------------") while (price == ns.stock.getPrice(index)) { await ns.sleep(100) } } }
BN8.2-3 & BN8 + Achievement
function round(value) { let signs = ["", "k", "m", "b", "t", "q"] let which = 0 while (value > 999 || value < -999) { value = Math.round(value / 10) / 100 ++which } return value + signs[which] } /** @param {NS} ns */ export async function main(ns) { ns.disableLog("ALL") let index = ns.args[0] // should be FSIG or FLCM let history = [] let max_shares = ns.stock.getMaxShares(index) let max_history = 40 let fee = 100000 while (true) { let money = (ns.getServerMoneyAvailable("home") - fee) * 0.9 let price = ns.stock.getPrice(index) let my_shares = ns.stock.getPosition(index)[0] let my_shorts = ns.stock.getPosition(index)[2] ns.clearLog() if (history.length > (max_history - 1)) { if (price > Math.max(...history)) { if (my_shorts > 0) { ns.print("Sell(Short): " + ns.stock.sellShort(index, my_shorts)) } let buy = Math.floor((money / price)) if ((buy + my_shares) > max_shares) { buy = max_shares - my_shares } if (buy > 0 && (price * buy) > 10000000) { ns.print("Buy(Long): " + ns.stock.buy(index, buy)) } } else if (price < Math.min(...history)) { if (my_shares > 0) { ns.print("Sell(Long): " + ns.stock.sell(index, my_shares)) } if (my_shorts == 0) { let buy = Math.floor(((ns.getServerMoneyAvailable("home") - fee) / price)) if (buy > max_shares) { buy = max_shares } ns.print("Buy(Short): " + ns.stock.short(index, buy)) } } } history.splice(0, 0, price) if (history.length > max_history) { history.pop() } let profit if (my_shares > my_shorts) { profit = ns.stock.getSaleGain(index, my_shares, "Long") } else { profit = ns.stock.getSaleGain(index, my_shorts, "Short") } ns.print("Index: " + index) ns.print("Max Shares: " + round(max_shares)) ns.print("My Long Shares: " + round(ns.stock.getPosition(index)[0])) ns.print("My Short Shares: " + round(ns.stock.getPosition(index)[2])) ns.print("Price: $" + round(price)) ns.print("History saved: " + history.length) ns.print("Highest Price: $" + round(Math.max(...history))) ns.print("Lowest Price: $" + round(Math.min(...history))) ns.print("-------------------------") ns.print("Profit: $" + round(profit)) ns.print("-------------------------") while (price == ns.stock.getPrice(index)) { await ns.sleep(100) } } }
That's everything we are sharing today for this Bitburner guide. This guide was originally created and written by LorDamned. In case we fail to update this guide, you can find the latest update by following this link.