Bitburner - Stock market trading Script bot To automatically Sell And Buy Stock

By Meng

This script will robotically purchase and promote inventory for you

You want the WSE account, and 4S upgrades to run this script

There are 2 variables at line 14/15 which will be modified.

Table of Contents

The primary will amend the boldness you need to purchase at (65% default)

The second will will let you set a reserve pool of cash

As a result of nature of inventory market, it would typically sit with out doing a lot (ie. if it is not the appropriate time to purchase or promote), simply go away the sport open and it will do it is factor.


Terminal > nano stockbot.js

Copy paste the beneath code in and save

Terminal > run stockbot.js

// Inventory market bot for bitburner, written by steamid/Meng-

// Runs infinitely – buys and sells inventory, hopefully for a revenue…

// model 1.21 – Added test for max shares, cleaned issues up a bit, cycle full prints much less steadily

export async operate predominant(ns) {

    ns.print(“Beginning script right here”);



    let stockSymbols = ns.inventory.getSymbols(); // all symbols

    let portfolio = []; // init portfolio

    let cycle = 0;

// ~~~~~~~You’ll be able to edit these~~~~~~~~

    const forecastThresh = 0.65; // Purchase above this confidence stage (forecast%)

    const minimumCash = 50000000; // Minimal money to maintain

// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

    ns.print(“Beginning run – Will we personal any shares?”); //Finds and provides any shares we already personal

    for(const inventory of stockSymbols){

        let pos = ns.inventory.getPosition(inventory);

        if(pos[0] > 0){


            ns.print(‘Detected: ‘+ inventory + ‘ quant: ‘+ pos[0] +’ @ ‘+ pos[1]);




        for(const inventory of stockSymbols){ // for every inventory image

            if (portfolio.findIndex(obj => obj.sym === inventory) !== -1){ //if we have already got this inventory

                let i = portfolio.findIndex(obj => obj.sym === inventory); // log index of image as i

                if(ns.inventory.getAskPrice(inventory) >= portfolio.worth*1.1)

               else if(ns.inventory.getForecast(inventory) < 0.4)




           else if (ns.inventory.getForecast(inventory) >= forecastThresh) // if the forecast is healthier than threshold and we do not personal then BUY



       } // finish of for loop (iterating stockSymbols)


       if (cycle % 5 === 0);

       await ns.sleep(6000);

   } // finish of whereas true loop

   operate buyStock(inventory) {

       let stockPrice = ns.inventory.getAskPrice(inventory); // Get the stockprice

       let shares = stockBuyQuantCalc(stockPrice, inventory); // calculate the shares to purchase utilizing StockBuyQuantCalc

       if (ns.inventory.getVolatility(inventory) <= 0.05){ // if volatility is < 5%, purchase the inventory

           ns.inventory.purchase(inventory, shares);

           ns.print(‘Purchased: ‘+ inventory + ‘ quant: ‘+ Math.spherical(shares) +’ @ ‘+ Math.spherical(stockPrice));

           portfolio.push(); //retailer the acquisition data in portfolio



   operate sellStock(inventory) {

       let place = ns.inventory.getPosition(inventory);

       var forecast = ns.inventory.getForecast(inventory);

       if (forecast < 0.55)


   operate stockBuyQuantCalc(stockPrice, inventory){ // Calculates what number of shares to purchase

       let playerMoney = ns.getServerMoneyAvailable(‘dwelling’) – minimumCash;

       let maxSpend = playerMoney * 0.25;

       let calcShares = maxSpend/stockPrice;

       let maxShares = ns.inventory.getMaxShares(inventory);

       if (calcShares > maxShares){

           return maxShares


       else {return calcShares}



Previous articleChronostorm: Siberian Border – White Screen Crash on Startup Fix
Next articleRoblox Solo Blox Leveling Codes – April 2024 (Class Reset)


Please enter your comment!
Please enter your name here

This site uses Akismet to reduce spam. Learn how your comment data is processed.