Basic Script for BN8.1 Advanced Script for BN8.2-3 & BN8+ Achievement in Bitburner.
BN8.1
function round(価値) { let signs = ["", "k", "メートル", "b", "t"] let which = 0 その間 (価値 > 999 || 価値 < -999) { value = Math.round(価値 / 10) / 100 ++どれの } return value + 兆候[どれの] } /** @param {NS} ns */ 非同期関数メインのエクスポート(ns) { ns.disableLog("全て") let index = ns.args[0] // should be FSIG or FLCM let history = [] let max_shares = ns.stock.getMaxShares(索引) let max_history = 40 let fee = 100000 その間 (真実) { let money = (ns.getServerMoneyAvailable("家") - 手数料) * 0.9 let price = ns.stock.getPrice(索引) let my_shares = ns.stock.getPosition(索引)[0] ns.clearLog() もし (history.length > (max_history - 1)) { もし (price > Math.max(...history)) { let buy = Math.floor((お金 / price)) もし ((買う + my_shares) > max_shares) { buy = max_shares - my_shares } もし (買う > 0 && (price * 買う) > 10000000) { ns.print("買う(Long): " + ns.stock.buy(索引, 買う)) } } そうでなければ (price < Math.min(...history)) { もし (my_shares > 0) { ns.print("売る(Long): " + ns.stock.sell(索引, my_shares)) } } } history.splice(0, 0, price) もし (history.length > max_history) { history.pop() } let profit = ns.stock.getSaleGain(索引, my_shares, "Long") ns.print("Index: " + 索引) ns.print("Max Shares: " + ラウンド(max_shares)) ns.print("My Long Shares: " + ラウンド(ns.stock.getPosition(索引)[0])) ns.print("価格: $" + ラウンド(price)) ns.print("History saved: " + history.length) ns.print("Highest Price: $" + ラウンド(Math.max(...history))) ns.print("Lowest Price: $" + ラウンド(Math.min(...history))) ns.print("-------------------------") ns.print("利益: $" + ラウンド(利益)) ns.print("-------------------------") その間 (price == ns.stock.getPrice(索引)) { await ns.sleep(100) } } }
BN8.2-3 & BN8 + 成果
function round(価値) { let signs = ["", "k", "メートル", "b", "t", "Q"] let which = 0 その間 (価値 > 999 || 価値 < -999) { value = Math.round(価値 / 10) / 100 ++どれの } return value + 兆候[どれの] } /** @param {NS} ns */ 非同期関数メインのエクスポート(ns) { ns.disableLog("全て") let index = ns.args[0] // should be FSIG or FLCM let history = [] let max_shares = ns.stock.getMaxShares(索引) let max_history = 40 let fee = 100000 その間 (真実) { let money = (ns.getServerMoneyAvailable("家") - 手数料) * 0.9 let price = ns.stock.getPrice(索引) let my_shares = ns.stock.getPosition(索引)[0] let my_shorts = ns.stock.getPosition(索引)[2] ns.clearLog() もし (history.length > (max_history - 1)) { もし (price > Math.max(...history)) { もし (my_shorts > 0) { ns.print("売る(Short): " + ns.stock.sellShort(索引, my_shorts)) } let buy = Math.floor((お金 / price)) もし ((買う + my_shares) > max_shares) { buy = max_shares - my_shares } もし (買う > 0 && (price * 買う) > 10000000) { ns.print("買う(Long): " + ns.stock.buy(索引, 買う)) } } そうでなければ (price < Math.min(...history)) { もし (my_shares > 0) { ns.print("売る(Long): " + ns.stock.sell(索引, my_shares)) } もし (my_shorts == 0) { let buy = Math.floor(((ns.getServerMoneyAvailable("家") - 手数料) / price)) もし (買う > max_shares) { buy = max_shares } ns.print("買う(Short): " + ns.stock.short(索引, 買う)) } } } history.splice(0, 0, price) もし (history.length > max_history) { history.pop() } let profit if (my_shares > my_shorts) { profit = ns.stock.getSaleGain(索引, my_shares, "Long") } それ以外 { profit = ns.stock.getSaleGain(索引, my_shorts, "Short") } ns.print("Index: " + 索引) ns.print("Max Shares: " + ラウンド(max_shares)) ns.print("My Long Shares: " + ラウンド(ns.stock.getPosition(索引)[0])) ns.print("My Short Shares: " + ラウンド(ns.stock.getPosition(索引)[2])) ns.print("価格: $" + ラウンド(price)) ns.print("History saved: " + history.length) ns.print("Highest Price: $" + ラウンド(Math.max(...history))) ns.print("Lowest Price: $" + ラウンド(Math.min(...history))) ns.print("-------------------------") ns.print("利益: $" + ラウンド(利益)) ns.print("-------------------------") その間 (price == ns.stock.getPrice(索引)) { await ns.sleep(100) } } }