Bitburner

Bitburner

40 ratings
Bitburner Stock Market for Dummies
By Zac Starfire
A short guide and simple working script for initially playing with the Bitburner Stock Market.
5
   
Award
Favorite
Favorited
Unfavorite
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, yet) and ~3t was about all I could make each day off hacking and my hacknets. I have access to 40 augments, so I’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 tides 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. You can’t really do that in a casino and from what I hear that could actually get you in a lot of trouble if you tried to do so. Information about a stock’s history is called market data, which can be purchased to formulate buying and selling strategies mathematically.
The Very Basicz
Here’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 here: https://bitburner.readthedocs.io/en/latest/basicgameplay/stockmarket.html

This is also a good read about how the Stock Market works in real life from Investopedia:
Stock Market Positions[www.investopedia.com]
The Bitburner Stock Market
Initially, 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 exactly 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, you’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, you’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.

     Remember, once you augment, you’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 Information Pleaz
       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, authors and suggestions in posts, 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, so I’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, but I’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. There are some other settings in the Globals header you can play with, but everything is set to go full bore once you start it. But you want to have more than 1b, that's what the failsafe is set to, but you can set it to what you like, so don't forget to set it to 1m if you have less than 1b.

      The 'q+' formatting code and the +/- forecast code actually came from the game's source itself, I converted it from React to NS2 and I stripped it down so it's easier to understand. I recommend using those code blocks in your own scripts, since they are very helpful. I had to keep some of that part in short-hand, so save help keep the script short and simple still as possible.

          The script will use as much money as possible to buy as much favorable stock at once for grinding huge 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 (only 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 1Q (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 - it’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. Also, watching your ‘portfolio’ in the stock market menu you can see how much each position has made you currently and under ‘Stats - General - Money’ 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 commission fees.



Script General Display Output:
4S Forcast -> What the 4S forecast will be in the next market 'tick' for the stock.
Position -> How much stock you have in the position.
Profit -> Profit made with stock position, minus commissions.
Current Stock Worth: Basically, 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. So, this is more your current ‘bank’ rather than the overview display money or ‘total worth’ with everything tied up in the stock market.
The Codez
I had to move the code to Github because Steam kept modifying it and introducing errors. If you copy pasted it before from Steam, you may want to get it again from Github because several things will be broken.

https://github.com/zacstarfire/bitburner/blob/main/stocks/stockTrader5.js
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 in the Bitburner Overview. I've updated the script to use formatReallyBigNumber() now because it was bugging me not to see q+ values right.

            Also the buy/sell should be now toast messages and the script clears the tail window each cycle, making it more static looking. Log History is lost because of this, but it didn't work well anyways and that probably should probably be saved to a text file.

The End
         Well, hopefully I have helped you along in your Bitburner journey and have inspired you to continue playing Bitburner addictively and maybe leave a good review for it so that maybe someday it will be recognized by Steam as a regular game (then the Steam achievements will hopefully apply officially)!

          Go ahead and use my scripts as templates to learn from and build your own scripts. I’ve been programming for over 30 years (I am a retired Software Engineer) since the dawn of personal computers in way too many different languages and platforms including mainframes even - really! So, I think I've learned some good programming habits and programming patterns over the years, if very old-school-ish.

Please rate & favorite my Bitburner guides. The game has a very small community and I could use any help getting the rating stars going on them. I'll also return the favor if you tell me what you need.

Also, please read the entire series:
https://steamcommunity.com/sharedfiles/filedetails/?id=2860828429

https://steamcommunity.com/sharedfiles/filedetails/?id=2860330999

https://steamcommunity.com/sharedfiles/filedetails/?id=2863116304

https://steamcommunity.com/sharedfiles/filedetails/?id=2874771586

Disclaimer: 'The For Dummies' in the title is just a name I borrowed from an old series of books from the 1990's, by the way, not to call anyone a Dummy or even an Ape. :p

https://en.wikipedia.org/wiki/For_Dummies

This guide was created by Zac Starfire on Steam. If you found it on another server, that is where it originated.
Change Log
3/2/23
- Added Scripts guide link

10/13/22
- Moved code to Github because Steam kept changing it and causing errors.

9/25/22
- Fixed spelling of forecast in the script.
- Updated script picture.
- Rounded the shares bought amount.

9/21/22
- Flipped Forecast and Position in script display.
- Added stock profit.
- Fixed selling toast messages.
- Updated script image.

9/20/22
- Added picture of the script's output.
- Made adjustments to the display of the script, added the +/- forecast symbols.
- Fixed some minor bugs.

9/19/22
- Added 'The Information Pleaze' section.
- Added formatReallyBigNumber() to stock script.
- Buying/Selling messages are now toast messages.
- Fixed display problems by adding clearLog() at end of stock script.
- Fixed 'Forecasts' spelling - oops!
- Introduced a bug, but I think I got it, leave comment if you see something weird selling stocks.

9/15/22
- Added my share automation script and fixed a few things

9/16/22
- Added Change Log section and moved my change comments to that section.
- Some More stuff
30 Comments
NeoG Apr 20 @ 12:52pm 
Also consider changing the default cycle time of the script from 2 seconds (2000) to 30 seconds:

const scriptTimer = 30000; // Time script waits (30000ms = 30 seconds)

Because every time you execute a trade you pay 100K in fees! This is important when your income per second is very limited and you want to reduce the fee load on your finances.

Adjust the value as you see fit.
NeoG Apr 20 @ 12:47pm 
for whoever follows here: as of at least v2.6.0, make sure you edit the deprecated function every time it is called. If you only correct the first instance, the game will bug out later when it needs to sell stocks (it wont crash until the deprecated function is called).

A specific example for one of the times:

ns.formatNumber(position[0], 2, 100000, '0.00a')

notice that the integer above is "2" because only 2 digits show after decimal point (as defined by script writer.

After having made these edits/corrections, the script seems to run beautifully.
NeoG Apr 20 @ 12:34pm 
looks like the script works by changing the nFormat function to something like this: "ns.formatNumber(number, 3, 100000, '$0.000a')"

Really appreciate the effort you put into it and the comments to explain -Thanks!
Zac Starfire  [author] Jan 24 @ 1:34pm 
@Good I'm glad.

I've been too busy to update thing, but perhaps I should put a day or two aside to get the scripts updated before something really does breaks.
Element Jan 23 @ 11:25pm 
Thank you so much for this! Still works in 2024, however, ns.nFormat(number, string) is deprecated and noted as going to be removed in 2.4, but I'm on 2.5.2 and it still works. I'm not savvy enough to want try to change it...I have a basic understanding of coding and I play this game by looking up scripts online and then learning from them by reading, tinkering, and more searching, so thank god it still works. Just thought I'd let you know so you can update it!
Zac Starfire  [author] Oct 23, 2023 @ 10:02am 
stockTrader5.js is the file you download from this guide, it is probably the one that is working - it should have the display like the screenshot above. 'stocks' I don't know about - it may be your own file.
Skayleef Oct 23, 2023 @ 3:31am 
Hi Zac, I'm a bit confused as to which stock js to use, I put both stock5 and stocks and only stock5 works, stocks will work but it crashes in less than 30 seconds. Is this because I have a hacking script running as well? Is this outdated? help if you can :)
zufilico Oct 19, 2023 @ 4:25am 
thanks for atention @Zac , I will read it for sure in future, but now I need to spend more time in my offline life lol .:savedisk::health:
Zac Starfire  [author] Oct 18, 2023 @ 2:27pm 
@Kraasel and anyone playing with growing stocks:

I originally figured this out by looking at the game source. I noticed now they actually have it documented, but the threads and the flag are reversed in the object. So, if my script doesn't seem to be effecting the market, try swapping the values in the object - they may have changed it, or I had it wrong (I could have sworn it was working for me before), or the docs maybe slightly incorrect.
Zac Starfire  [author] Oct 18, 2023 @ 2:15pm 
Here is the link to the grow function in the docs:
https://bitburner.readthedocs.io/en/latest/netscript/basicfunctions/grow.html

grow() Netscript Function

grow(hostname[, opts={}])
RAM cost: 0.15 GB
Arguments: hostname (string) – Hostname of the target server.
opts (object) –

Optional parameters for configuring function behavior. Properties:
threads (number) - Number of threads to use for this function. Must be less than or equal to the number of threads the script is running with.
stock (boolean) - If true, the function can affect the stock market. See Player Actions Influencing Stocks