Bitburner All Stock Market Upgrade + Code

Bitburner All Stock Market Upgrade + Code 1 -
Bitburner All Stock Market Upgrade + Code 1 -

This script will automatically buy and sell stocks for you.

You need all Stock Market upgrades (WSE Account, TIX API Access, Market Data TIX API Access, 4S Market Data Access, $31.2b total cost) and 19.7 Gb RAM to run this script.
This is modification of the original script from another steam guide – []  , I’m not the primary creator

This modification has more potential in various situations, especially during growth phase: I got the “wolf of wall street” achievement (make 1q on the stock market) by running mod. script overnight.


Terminal: nano stockbot.js
Remove all the default file contents (blank file)
Copy-paste the below code in and save
Terminal: run stockbot.js
To quick launch this script after augmentation, use alias:
Terminal: alias restart=”run stockbot.js”
After, you able to type in terminal box restart to quick launch without necessity of type full command (you also able to add necessary commands to this alias through ; and they all would be executed).

// Stock market bot for bitburner, primary written by steamid/Meng-
// Modified by Tonalnan

export async function main(ns) {
let stockSymbols = ns.stock.getSymbols() // all symbols
let portfolio = [] // init portfolio
//~~~~~~~~~~~~~~~~~~~~~You can edit these~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
const FORECAST_THRESH = 0.6 // buy above this forecast value, 0.6=60% (0.6 default)
const MIN_CASH = 0 // minimum cash to keep (0 default)
const SELL_THRESH = 0.5 // sell belove this forecast value, 0.5=50% (0.5 default)
const SPEND_RATIO = 1 // spends up to this ratio of your total money to buy stocks (minus your min_cash set), 1=100% (1 default)
const MIN_SPEND=100000000 // minimum available money to buy stocks, limited due to 100k commission fees, 100000000=100m (100000000 default)

ns.print("Starting run - Do we own any stocks?") //Finds and adds any stocks we already own
for(const stock of stockSymbols){
let pos = ns.stock.getPosition(stock)
if(pos[0] > 0){
portfolio.push({sym: stock, value: pos[1], shares: pos[0]})
ns.print('Detected: '+ stock + ', quant: '+ pos[0] +' @ '+ pos[1])

if (ns.getServerMoneyAvailable('home') < MIN_CASH){
ns.print("Stockbot has no money to play with!")
ns.print("Stockbot will nap for 5 mins while you make some money")
await ns.sleep(300000)

let goodoffers=[]
let lenght=0
for(const stock of stockSymbols){ // for each stock symbol
if (portfolio.findIndex(obj => obj.sym === stock) !== -1){ //if we own the stock...
if (ns.stock.getForecast(stock) < SELL_THRESH) { //...look at forecast to decide sell it
if (ns.stock.getForecast(stock) >= FORECAST_THRESH){ //if the forecast is better than threshold then...
goodoffers.push([stock,(ns.stock.getForecast(stock)-0.5)*ns.stock.getVolatility(stock)]) //...record it to stock massive with information about profitability

for (let i = 0; i < lenght-1; i++) { //bubble sort stock with positive forecast from most profitable to less
for (let ii=0; ii < lenght-1-i; ii++) {
if (goodoffers[ii+1][1]>goodoffers[ii][1]) {
let t0=goodoffers[ii+1][0]
let t1=goodoffers[ii+1][1]

for (let i = 0; i < lenght; i++) { //buy stocks from most profitable to less
if ((ns.getServerMoneyAvailable('home')-MIN_CASH-100000)*SPEND_RATIO > MIN_SPEND) {

await ns.sleep(6000) //wait for stocks update

function buyStock(stock) {
let stockPrice = ns.stock.getAskPrice(stock) // Get the stockprice
let shares = stockBuyQuantCalc(stockPrice, stock) // calculate the shares to buy using stockBuyQuantCalc, shares)
ns.print('Bought: '+ stock + ', quant: '+ Math.round(shares) +' @ $'+ Math.round(stockPrice))
portfolio.push({sym: stock, value: stockPrice, shares: shares}) //store the purchase info in portfolio

function sellStock(stock) {
let position = ns.stock.getPosition(stock)
let stockPrice = ns.stock.getAskPrice(stock)
let i = portfolio.findIndex(obj => obj.sym === stock) //Find the stock info in the portfolio
ns.print('SOLD: '+ stock + ', quant: '+ Math.round(portfolio[i].shares) +' @ $'+ Math.round(stockPrice) + ' - bought at $' + Math.round(portfolio[i].value))
portfolio.splice(i, 1) // Remove the stock from portfolio
ns.stock.sell(stock, position[0])

function stockBuyQuantCalc(stockPrice, stock){ // Calculates how many shares to buy
let playerMoney = ns.getServerMoneyAvailable('home')-MIN_CASH-100000
let maxSpend = playerMoney*SPEND_RATIO
let calcShares = Math.floor(maxSpend/stockPrice)
let position = ns.stock.getPosition(stock)
let avShares = ns.stock.getMaxShares(stock)-position[0]
if (calcShares > avShares){return avShares}
else {return calcShares}



Ver. 1.0- comparison with the original script from – [] 

  • Removed some player-changeable variables due to trading strategy revision (will be listed below)
  • Changed some player-changeable variables values. Now all player money considered available basically: to make money you should spend money (changeable)
  • Added MIN_SPEND variable to prevent loss from commissions more than potential profit
  • Removed some obvious logs like cycle counter
  • Now script sells stocks before buys to be able spend newly acquired cash
  • Now script buys not the first stock with suitable conditions, but most profitable
  • Now script able to buy more already existing stocks, if they are most profitable
  • Script cured from volatilityphobia, futhermore volatility considered now as good property since stocks with more volatility usually more profitable


Written by Tonalnan

This is all for Bitburner All Stock Market Upgrade + Code hope you enjoy the post. If you believe we forget or we should update the post please let us know via comment, we will try our best to fix how fast is possible! Have a great day!

Be the first to comment

Leave a Reply

Your email address will not be published.