A short guide and simple working script for initially playing with the Bitburner Stock Market.
The Beginning
I never knew very much about the stock market other than it was like gambling and I am just terrible at gambling – I always seem to lose. But I got to a point in my early game where I was spending ~3t+ for each augment (they increase exponentially for each one you buy, in case you didn’t know, nog) and ~3t was about all I could make each day off hacking. I have access to 40 augments, Dus ik’m trying to buy all I can so I can get that achievement as well. Realizing it would take forever at this rate and considering the cost of each augment was increasing as well – I needed a better way to make money. So I decided to learn about how to play the stock market in Bitburner, besides it’s all virtual – what can I lose?
Turns out, the stock market isn’t so much like gambling in a casino and relying on the cards or slots and your luck to win. The market is like an ocean shore with its ebbs and flows that can be mostly predicted mathematically to take advantage of for profit, which is how people and corporations make money off the stock market and it’s actually allowed. Dat kan’t really do that in a casino – from what I hear that could actually get you in a lot of trouble. Information about a stock’s history is called market data, which can be purchased to formulate buying and selling strategies mathematically.
The Very Basics
Hier’s the real basics you’ll need to know:
What Is a Position?A position is the amount of stocks that is owned by the player for a given corporation. A player takes a position when they make a purchase through a buy order. Open positions can be either long or short depending on your progress through the game. Initially you only have access to Long Stocks, but later you will be able to purchase Short Stocks (much later it seems).
What are Long and Short Stocks?Long positions refers to the purchase of a stock with the expectation it will increase in value. Short positions profit when the underlying security falls in price. Short stocks often involve securities that are borrowed and then sold, to be bought back hopefully at a lower price.
For more basic information, consult the game docs hier.
The Bitburner Stock Market
Aanvankelijk, you go to the Stock Market through the map – all cities have access to it.
WSE Account –Costs 200m and is required for access to the stock market. Buying this will add the Stock Market to the left menu under ‘World’.
Market Data TIX API Access –Costs 5b for access to the API functions which will allow you to buy/sell stocks and other stock related tasks.
Four Sigma (4S) Market Data Access – Costs 1b for access to 4S forecast data. I read somewhere that using the 4S data will increase your profit by 60%. Which is what we need right now.
Four Sigma (4S) Market API Access –Costs 25b for the API access which lets you use the TIX functions that require 4S Market Data Access.
To start off with, Jij’ll want to just buy all the market access stuff at once when you can afford it. By the time you need the stock market, you should be making plenty off of hacking, which is more important initially (More hacking xp = more servers can be hacked = more $$ gained and even more hacking exp). Later, once you know more about what you’re doing, Jij’ll be required to do it all over again without 4S data access and little resources. So the goal now is simply to make a ton of cash to buy as many initial augments as possible while learning how the stock market works. Herinneren, once you augment, Jij’ll lose all your cash and have to start over, so all your money at this point is completely disposable and the more you spend on the market, the more you’ll make off the market.
The Codez
After scouring the internet for any available information I could find, I managed to cobble together a working script using the best code from many different sources and authors, mostly Reddit (which is notoriously unreliable), updated them to Bitburner 2.0 and NS2 syntax, cleaned up or added more comments so that it is easier to see exactly what the script is doing and made the general output more useful and more properly timestamped so you can see it actually running better. The purpose is to learn from the script, Dus ik’ve kept it as simple and self explanatory as possible while retaining the original math and logic. I’ve also found formulas from a data scientist for no 4S market access that claim to work, Maar ik’ll save that for later, maybe a more advanced guide. I have left in the short stocks code I found and wrapped it in a flag you can toggle it in the Globals header – it’s untested so beware if you play with this later when you have access to shorts.
The script will use as much money as possible to buy as much favorable stock at once for grinding profits. I’ve seen it use as much as 1q purchasing stocks when there is a huge market boom. I had 40t when I first started the script in the morning and made 150t by the afternoon just letting it run constantly. At this point now in my writing, I’ve purchased 35 augments (alleen 5 left to go!) with them costing ~45q now each and I’m making about ~10q a day now with this script. There is an achievement to make 2Q (Q not q), but this script would just take too long, so more stock market magic in the calculations would be needed or some other cheat. Note you can also influence the market through hacking/growing, stock purchases and even working for the company you have stock in. So really, this script is just scratching the surface of what you actually could do to make even more money.
I recommend just watching the script run for a few days. Get a good feel for the stock market behaviors – Het’S ‘ebbs and tides’. Remember to save your game file before you start in case of problems or you simply just want to go back. You should see debug messages for everything and you can add more if you like to see exactly what is going on. Ook, watching your ‘portfolio’ in the stock market menu you can see how much each position has made you currently and under ‘Statistieken – Algemeen – Geld’ you can see how much money you’ve made overall on the stock market. If you panic, just kill the script and sell everything, you won’t lose very much – just mostly commision fees.
Stock Position ->How much stock you have in the position.
4S Forcast ->What the 4S forecast in the next market ‘tick’ for the stock.
Current Stock Worth:In principe, how much money total you currently have tied up in stocks.
Current Net Worth:What you actually have now, should you kill the script and sell everything. Dus, this is more your current ‘bank’ rather than the overview display money or ‘total worth’ with everything tied up in the stock market.
/** @param {NS} ns */ export async function main(ns) { // Logging ns.disableLog('ALL'); //ns.disableLog('sleep'); //ns.disableLog('getServerMoneyAvailable'); ns.tail(); // Globals const scriptTimer = 2000; // Time script waits const moneyKeep = 1000000000; // Failsafe Money const stockBuyOver_Long = 0.60; // Buy stocks when forcast is over this % const stockBuyUnder_Short = 0.40; // Buy shorts when forcast is under this % const stockVolatility = 0.05; // Stocks must be under this volatility const minSharePercent = 5; const maxSharePercent = 1.00; const sellThreshold_Long = 0.55; // Sell Long when chance of increasing is under this const sellThreshold_Short = 0.40; // Sell Short when chance of increasing is under this const shortUnlock = false; // Set true when short stocks are available to player // Functions function buyPositions(stock) { let position = ns.stock.getPosition(stock); let maxShares = (ns.stock.getMaxShares(stock) * maxSharePercent) - positie[0]; let maxSharesShort = (ns.stock.getMaxShares(stock) * maxSharePercent) - positie[2]; let askPrice = ns.stock.getAskPrice(stock); let forecast = ns.stock.getForecast(stock); let volatilityPercent = ns.stock.getVolatility(stock); let playerMoney = ns.getPlayer().geld; // Look for Long Stocks to buy if (forecast >= stockBuyOver_Long && volatilityPercent <= stockVolatility) { if (playerMoney - moneyKeep > ns.stock.getPurchaseCost(stock, minSharePercent, "Long")) { let shares = Math.min((playerMoney - moneyKeep - 100000) / askPrice, maxShares); let boughtFor = ns.stock.buyStock(stock, shares); if (boughtFor > 0) { ns.print('Bought ' + shares + ' Long shares of ' + stock + ' for ' + ns.nFormat(boughtFor, '$0.000a')); } } } // Look for Short Stocks to buy if (shortUnlock) { if (forecast <= stockBuyUnder_Short && volatilityPercent <= stockVolatility) { if (playerMoney - moneyKeep > ns.stock.getPurchaseCost(stock, minSharePercent, "Short")) { let shares = Math.min((playerMoney - moneyKeep - 100000) / askPrice, maxSharesShort); let boughtFor = ns.stock.buyShort(stock, shares); if (boughtFor > 0) { ns.print('Bought ' + shares + ' Short shares of ' + stock + ' for ' + ns.nFormat(boughtFor, '$0.000a')); } } } } } function sellIfOutsideThreshdold(stock) { let position = ns.stock.getPosition(stock); let forecast = ns.stock.getForecast(stock); if (positie[0] > 0) { ns.print(stock + ' 4S Forcast -> ' + forecast.toFixed(2)); // Check if we need to sell Long stocks if (forecast < sellThreshold_Long) { let soldFor = ns.stock.sellStock(stock, position[0]); ns.print('Sold ' + stock + ' Long shares of ' + stock + ' for ' + ns.nFormat(soldFor, '$0.000a')); } } if (shortUnlock) { if (position[2] > 0) { ns.print(stock + ' 4S Forcast -> ' + forecast.toFixed(2)); // Check if we need to sell Short stocks if (forecast > sellThreshold_Short) { let soldFor = ns.stock.sellShort(stock, positie[2]); ns.print('Sold ' + stock + ' Short shares of ' + stock + ' for ' + ns.nFormat(soldFor, '$0.000a')); } } } } // Main Loop while (WAAR) { // Get stocks in order of favorable forcast let orderedStocks = ns.stock.getSymbols().sort(function (A, B) { return Math.abs(0.5 - ns.stock.getForecast(B)) - Math.abs(0.5 - ns.stock.getForecast(A)); }) let currentWorth = 0; ns.print("-------------------------------"); ns.print('Current Forceasts:'); voor (const stock of orderedStocks) { const position = ns.stock.getPosition(stock); if (positie[0] > 0 || positie[2] > 0) { ns.print(stock + ' Position -> ' + positie[0]); // Check if we need to sell sellIfOutsideThreshdold(stock); } // Check if we should buy buyPositions(stock); // Track out current profit over time... if (positie[0] > 0 || positie[2] > 0) { let longShares = position[0]; let longPrice = position[1]; let shortShares = position[2]; let shortPrice = position[3]; let bidPrice = ns.stock.getBidPrice(stock); // Calculate profit let profit = longShares * (bidPrice - longPrice) - (2 * 100000); let profitShort = shortShares * Math.abs(bidPrice - shortPrice) - (2 * 100000); // Calculate net worth currentWorth += profitShort + profit + (longShares * longPrice) + (shortShares * shortPrice); } } // Output Script Status ns.print('Current Stock Worth: ' + ns.nFormat(currentWorth, '$0.000a')); ns.print('Current Net Worth: ' + ns.nFormat(currentWorth + ns.getPlayer().geld, '$0.000a')); ns.print(new Date().toLocaleTimeString() + ' - Running...'); await ns.sleep(scriptTimer); } }
The Bugz
There seems to be a bug with the numeral.js library used by Netscript, when formatting numbers past ‘T’, so it does not display ‘q’. This is noted in the Bitburner source code and the developer has created his own function (formatReallyBigNumber) to display q+ values properly in the Bitburner Overview display. You can add the functions yourself to the script if this really bothers you because I wanted to just keep the script simple as possible:
Ook, when the script buys/sells, you see the message briefly, then disappears in the log text. Het’s still there – I can get it to display again briefly fiddling with the options and the UI so I suspect it’s a bug with the UI rather than the script because I cannot see anything else that could be wrong in the script. Maybe someone else may figure it out and post a comment for a possible fix.
Dat is alles wat we vandaag hiervoor delen Bitburner gids. Deze handleiding is oorspronkelijk gemaakt en geschreven door Zac Starfire. Voor het geval we er niet in slagen deze handleiding bij te werken, U kunt de laatste update vinden door dit te volgen link.