Short stocks.
Stock symbol.
Number of shares to short. Must be positive. Will be rounded to the nearest integer.
The stock price at which each share was purchased, otherwise 0 if the shares weren't purchased.
RAM cost: 2.5 GB Attempts to purchase a short position of a stock using a Market Order.
The ability to short a stock is not immediately available to the player and must be unlocked later on in the game.
If the player does not have enough money to purchase the specified number of shares, then no shares will be purchased. Remember that every transaction on the stock exchange costs a certain commission fee.
If the purchase is successful, this function will return the stock price at which each share was purchased. Otherwise, it will return 0.
Buy stocks.
Stock symbol.
Number of shares to purchase. Must be positive. Will be rounded to the nearest integer.
The stock price at which each share was purchased, otherwise 0 if the shares weren't purchased.
RAM cost: 2.5 GB Attempts to purchase shares of a stock using a Market Order.
If the player does not have enough money to purchase the specified number of shares, then no shares will be purchased. Remember that every transaction on the stock exchange costs a certain commission fee.
If this function successfully purchases the shares, it will return the stock price at which each share was purchased. Otherwise, it will return 0.
Cancel order for stocks.
Stock symbol.
Number of shares for order. Must be positive. Will be rounded to the nearest integer.
Execution price for the order.
Type of order.
Specifies whether the order is a “Long” or “Short” position.
RAM cost: 2.5 GB Cancels an outstanding Limit or Stop order on the stock market.
The ability to use limit and stop orders is not immediately available to the player and must be unlocked later on in the game.
Get Stock Market bonus time.
Amount of accumulated “bonus time” (milliseconds) for the Stock Market mechanic.
RAM cost: 0 GB
“Bonus time” is accumulated when the game is offline or if the game is inactive in the browser.
Stock Market prices update more frequently during “bonus time”.
Get game constants for the stock market mechanic.
RAM cost: 0 GB
Returns the probability that the specified stock’s price will increase (as opposed to decrease) during the next tick.
Stock symbol.
Probability that the specified stock’s price will increase (as opposed to decrease) during the next tick.
RAM cost: 2.5 GB The probability is returned as a decimal value, NOT a percentage (e.g. if a stock has a 60% chance of increasing, then this function will return 0.6, NOT 60).
In other words, if this function returned 0.30 for a stock, then this means that the stock’s price has a 30% chance of increasing and a 70% chance of decreasing during the next tick.
In order to use this function, you must first purchase access to the Four Sigma (4S) Market Data TIX API.
Returns your order book for the stock market.
Object containing information for all the Limit and Stop Orders you have in the stock market.
RAM cost: 2.5 GB This is an object containing information for all the Limit and Stop Orders you have in the stock market. For each symbol you have a position in, the returned object will have a key with that symbol's name. The object's properties are each an array of StockOrderObject The object has the following structure:
{
string1: [ // Array of orders for this stock
{
shares: Order quantity
price: Order price
type: Order type
position: Either "L" or "S" for Long or Short position
},
{
...
},
...
],
string2: [ // Array of orders for this stock
...
],
...
}
The “Order type” property can have one of the following four values: "Limit Buy Order", "Limit Sell Order", "Stop Buy Order", "Stop Sell Order". Note that the order book will only contain information for stocks that you actually have orders in.
"If you do not have orders in Nova Medical (NVMD), then the returned object will not have a “NVMD” property."
{
ECP: [
{
shares: 5,
price: 100,000
type: "Stop Buy Order",
position: "S",
},
{
shares: 25,
price: 125,000
type: "Limit Sell Order",
position: "L",
},
],
SYSC: [
{
shares: 100,
price: 10,000
type: "Limit Buy Order",
position: "L",
},
],
}
Returns the organization associated with a stock symbol.
Stock symbol.
The organization assicated with the stock symbol.
RAM cost: 2 GB
The organization associated with the corresponding stock symbol. This function requires that you have the following:
WSE Account
TIX API Access
ns.stock.getOrganization("FSIG");
// Choose the first stock symbol from the array of stock symbols. Get the
// organization associated with the corresponding stock symbol.
const sym = ns.stock.getSymbols()[0];
ns.tprint("Stock symbol: " + sym);
ns.tprint("Stock organization: " + ns.stock.getOrganization(sym));
Returns the player’s position in a stock.
Stock symbol.
Array of four elements that represents the player’s position in a stock.
RAM cost: 2 GB Returns an array of four elements that represents the player’s position in a stock.
The first element in the returned array is the number of shares the player owns of the stock in the Long position. The second element in the array is the average price of the player’s shares in the Long position.
The third element in the array is the number of shares the player owns of the stock in the Short position. The fourth element in the array is the average price of the player’s Short position.
All elements in the returned array are numeric.
const [sharesLong, avgLongPrice, sharesShort, avgShortPrice] = ns.stock.getPosition("ECP");
Returns the price of a stock.
Stock symbol.
The price of a stock.
RAM cost: 2 GB
The stock’s price is the average of its bid and ask prices. This function requires that you have the following:
WSE Account
TIX API Access
const fourSigmaStockPrice = ns.stock.getPrice("FSIG");
// Choose the first stock symbol from the array of stock symbols. Get the price
// of the corresponding stock.
const sym = ns.stock.getSymbols()[0];
ns.tprint("Stock symbol: " + sym);
ns.tprint("Stock price: " + ns.stock.getPrice(sym));
Calculates cost of buying stocks.
Stock symbol.
Number of shares to purchase.
Specifies whether the order is a “Long” or “Short” position.
Cost to buy a given number of shares of a stock.
RAM cost: 2 GB Calculates and returns how much it would cost to buy a given number of shares of a stock. This takes into account spread, large transactions influencing the price of the stock and commission fees.
Calculate profit of selling stocks.
Stock symbol.
Number of shares to sell.
Specifies whether the order is a “Long” or “Short” position.
Gain from selling a given number of shares of a stock.
RAM cost: 2 GB Calculates and returns how much you would gain from selling a given number of shares of a stock. This takes into account spread, large transactions influencing the price of the stock and commission fees.
Returns the volatility of the specified stock.
Stock symbol.
Volatility of the specified stock.
RAM cost: 2.5 GB Volatility represents the maximum percentage by which a stock’s price can change every tick. The volatility is returned as a decimal value, NOT a percentage (e.g. if a stock has a volatility of 3%, then this function will return 0.03, NOT 3).
In order to use this function, you must first purchase access to the Four Sigma (4S) Market Data TIX API.
Sleep until the next Stock Market price update has happened.
Promise that resolves to the number of milliseconds of Stock Market time that were processed in the previous update (always 6000 ms).
RAM cost: 1 GB
The amount of real time spent asleep between updates can vary due to "bonus time" (usually 4 seconds - 6 seconds).
while (true) {
await ns.stock.nextUpdate();
// Manage your stock portfolio
}
Place order for stocks.
Stock symbol.
Number of shares for order. Must be positive. Will be rounded to the nearest integer.
Execution price for the order.
Type of order.
Specifies whether the order is a “Long” or “Short” position.
True if the order is successfully placed, and false otherwise.
RAM cost: 2.5 GB Places an order on the stock market. This function only works for Limit and Stop Orders.
The ability to place limit and stop orders is not immediately available to the player and must be unlocked later on in the game.
Returns true if the order is successfully placed, and false otherwise.
Sell short stock.
Stock symbol.
Number of shares to sell. Must be positive. Will be rounded to the nearest integer.
The stock price at which each share was sold, otherwise 0 if the shares weren't sold.
RAM cost: 2.5 GB Attempts to sell a short position of a stock using a Market Order.
The ability to short a stock is not immediately available to the player and must be unlocked later on in the game.
If the specified number of shares exceeds the amount that the player actually owns, then this function will sell all owned shares. Remember that every transaction on the stock exchange costs a certain commission fee.
If the sale is successful, this function will return the stock price at which each share was sold. Otherwise, it will return 0.
Sell stocks.
Stock symbol.
Number of shares to sell. Must be positive. Will be rounded to the nearest integer.
The stock price at which each share was sold, otherwise 0 if the shares weren't sold.
RAM cost: 2.5 GB Attempts to sell shares of a stock using a Market Order.
If the specified number of shares in the function exceeds the amount that the player actually owns, then this function will sell all owned shares. Remember that every transaction on the stock exchange costs a certain commission fee.
The net profit made from selling stocks with this function is reflected in the script’s statistics. This net profit is calculated as:
shares * (sell_price - average_price_of_purchased_shares)
If the sale is successful, this function will return the stock price at which each share was sold. Otherwise, it will return 0.
Stock market API