Interface TIX

Stock market API

interface TIX {
    buyShort(sym, shares): number;
    buyStock(sym, shares): number;
    cancelOrder(sym, shares, price, type, pos): void;
    getAskPrice(sym): number;
    getBidPrice(sym): number;
    getBonusTime(): number;
    getConstants(): StockMarketConstants;
    getForecast(sym): number;
    getMaxShares(sym): number;
    getOrders(): StockOrder;
    getOrganization(sym): string;
    getPosition(sym): [number, number, number, number];
    getPrice(sym): number;
    getPurchaseCost(sym, shares, posType): number;
    getSaleGain(sym, shares, posType): number;
    getSymbols(): string[];
    getVolatility(sym): number;
    has4SData(): boolean;
    has4SDataTIXAPI(): boolean;
    hasTIXAPIAccess(): boolean;
    hasWSEAccount(): boolean;
    nextUpdate(): Promise<number>;
    placeOrder(sym, shares, price, type, pos): boolean;
    purchase4SMarketData(): boolean;
    purchase4SMarketDataTixApi(): boolean;
    purchaseTixApi(): boolean;
    purchaseWseAccount(): boolean;
    sellShort(sym, shares): number;
    sellStock(sym, shares): number;
}

Methods

  • Short stocks.

    Parameters

    • sym: string

      Stock symbol.

    • shares: number

      Number of shares to short. Must be positive. Will be rounded to the nearest integer.

    Returns number

    The stock price at which each share was purchased, otherwise 0 if the shares weren't purchased.

    Remarks

    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.

    Parameters

    • sym: string

      Stock symbol.

    • shares: number

      Number of shares to purchase. Must be positive. Will be rounded to the nearest integer.

    Returns number

    The stock price at which each share was purchased, otherwise 0 if the shares weren't purchased.

    Remarks

    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.

    Parameters

    • sym: string

      Stock symbol.

    • shares: number

      Number of shares for order. Must be positive. Will be rounded to the nearest integer.

    • price: number

      Execution price for the order.

    • type: string

      Type of order.

    • pos: string

      Specifies whether the order is a “Long” or “Short” position.

    Returns void

    Remarks

    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.

  • Returns the ask price of that stock.

    Parameters

    • sym: string

      Stock symbol.

    Returns number

    The ask price of a stock.

    Remarks

    RAM cost: 2 GB

  • Returns the bid price of that stock.

    Parameters

    • sym: string

      Stock symbol.

    Returns number

    The bid price of a stock.

    Remarks

    RAM cost: 2 GB

  • Get Stock Market bonus time.

    Returns number

    Amount of accumulated “bonus time” (milliseconds) for the Stock Market mechanic.

    Remarks

    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”.

  • Returns the probability that the specified stock’s price will increase (as opposed to decrease) during the next tick.

    Parameters

    • sym: string

      Stock symbol.

    Returns number

    Probability that the specified stock’s price will increase (as opposed to decrease) during the next tick.

    Remarks

    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 the maximum number of shares of a stock.

    Parameters

    • sym: string

      Stock symbol.

    Returns number

    Maximum number of shares that the stock has.

    Remarks

    RAM cost: 2 GB This is the maximum amount of the stock that can be purchased in both the Long and Short positions combined.

  • Returns your order book for the stock market.

    Returns StockOrder

    Object containing information for all the Limit and Stop Orders you have in the stock market.

    Remarks

    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.

    Example

    "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.

    Parameters

    • sym: string

      Stock symbol.

    Returns string

    The organization assicated with the stock symbol.

    Remarks

    RAM cost: 2 GB

    The organization associated with the corresponding stock symbol. This function requires that you have the following:

    1. WSE Account

    2. TIX API Access

    Example

    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.

    Parameters

    • sym: string

      Stock symbol.

    Returns [number, number, number, number]

    Array of four elements that represents the player’s position in a stock.

    Remarks

    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.

    Example

    const [sharesLong, avgLongPrice, sharesShort, avgShortPrice] = ns.stock.getPosition("ECP");
    
  • Returns the price of a stock.

    Parameters

    • sym: string

      Stock symbol.

    Returns number

    The price of a stock.

    Remarks

    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:

    1. WSE Account

    2. TIX API Access

    Example

    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.

    Parameters

    • sym: string

      Stock symbol.

    • shares: number

      Number of shares to purchase.

    • posType: string

      Specifies whether the order is a “Long” or “Short” position.

    Returns number

    Cost to buy a given number of shares of a stock.

    Remarks

    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.

    Parameters

    • sym: string

      Stock symbol.

    • shares: number

      Number of shares to sell.

    • posType: string

      Specifies whether the order is a “Long” or “Short” position.

    Returns number

    Gain from selling a given number of shares of a stock.

    Remarks

    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 an array of the symbols of the tradable stocks

    Returns string[]

    Array of the symbols of the tradable stocks.

    Remarks

    RAM cost: 2 GB

  • Returns the volatility of the specified stock.

    Parameters

    • sym: string

      Stock symbol.

    Returns number

    Volatility of the specified stock.

    Remarks

    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.

  • Returns true if the player has access to the 4S Data

    Returns boolean

    Remarks

    RAM cost: 0.05 GB

  • Returns true if the player has access to the 4SData TIX API

    Returns boolean

    Remarks

    RAM cost: 0.05 GB

  • Returns true if the player has access to the TIX API

    Returns boolean

    Remarks

    RAM cost: 0.05 GB

  • Returns true if the player has access to a WSE Account

    Returns boolean

    Remarks

    RAM cost: 0.05 GB

  • Sleep until the next Stock Market price update has happened.

    Returns Promise<number>

    Promise that resolves to the number of milliseconds of Stock Market time that were processed in the previous update (always 6000 ms).

    Remarks

    RAM cost: 1 GB

    The amount of real time spent asleep between updates can vary due to "bonus time" (usually 4 seconds - 6 seconds).

    Example

    while (true) {
    await ns.stock.nextUpdate();
    // Manage your stock portfolio
    }
  • Place order for stocks.

    Parameters

    • sym: string

      Stock symbol.

    • shares: number

      Number of shares for order. Must be positive. Will be rounded to the nearest integer.

    • price: number

      Execution price for the order.

    • type: string

      Type of order.

    • pos: string

      Specifies whether the order is a “Long” or “Short” position.

    Returns boolean

    True if the order is successfully placed, and false otherwise.

    Remarks

    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.

  • Purchase 4S Market Data Access.

    Returns boolean

    True if you successfully purchased it or if you already have access, false otherwise.

    Remarks

    RAM cost: 2.5 GB

  • Purchase 4S Market Data TIX API Access.

    Returns boolean

    True if you successfully purchased it or if you already have access, false otherwise.

    Remarks

    RAM cost: 2.5 GB

  • Purchase TIX API Access

    Returns boolean

    True if you successfully purchased it or if you already have access, false otherwise.

    Remarks

    RAM cost: 2.5 GB

  • Purchase WSE Account.

    Returns boolean

    True if you successfully purchased it or if you already have access, false otherwise.

    Remarks

    RAM cost: 2.5 GB

  • Sell short stock.

    Parameters

    • sym: string

      Stock symbol.

    • shares: number

      Number of shares to sell. Must be positive. Will be rounded to the nearest integer.

    Returns number

    The stock price at which each share was sold, otherwise 0 if the shares weren't sold.

    Remarks

    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.

    Parameters

    • sym: string

      Stock symbol.

    • shares: number

      Number of shares to sell. Must be positive. Will be rounded to the nearest integer.

    Returns number

    The stock price at which each share was sold, otherwise 0 if the shares weren't sold.

    Remarks

    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.