diff --git a/src/Netscript/RamCostGenerator.ts b/src/Netscript/RamCostGenerator.ts index a50a0ef75..909bf2b36 100644 --- a/src/Netscript/RamCostGenerator.ts +++ b/src/Netscript/RamCostGenerator.ts @@ -127,6 +127,7 @@ const stock = { has4SDataTIXAPI: 0.05, getSymbols: RamCostConstants.ScriptGetStockRamCost, getPrice: RamCostConstants.ScriptGetStockRamCost, + getOrganization: RamCostConstants.ScriptGetStockRamCost, getAskPrice: RamCostConstants.ScriptGetStockRamCost, getBidPrice: RamCostConstants.ScriptGetStockRamCost, getPosition: RamCostConstants.ScriptGetStockRamCost, diff --git a/src/NetscriptFunctions/StockMarket.ts b/src/NetscriptFunctions/StockMarket.ts index 0777df7d0..5db8b948a 100644 --- a/src/NetscriptFunctions/StockMarket.ts +++ b/src/NetscriptFunctions/StockMarket.ts @@ -60,6 +60,13 @@ export function NetscriptStockMarket(): InternalAPI { return stock.price; }, + getOrganization: (ctx) => (_symbol) => { + const symbol = helpers.string(ctx, "symbol", _symbol); + checkTixApiAccess(ctx); + const stock = getStockFromSymbol(ctx, symbol); + + return stock.name; + }, getAskPrice: (ctx) => (_symbol) => { const symbol = helpers.string(ctx, "symbol", _symbol); checkTixApiAccess(ctx); diff --git a/src/ScriptEditor/NetscriptDefinitions.d.ts b/src/ScriptEditor/NetscriptDefinitions.d.ts index ad78cd053..300c05174 100644 --- a/src/ScriptEditor/NetscriptDefinitions.d.ts +++ b/src/ScriptEditor/NetscriptDefinitions.d.ts @@ -1061,6 +1061,46 @@ export interface TIX { */ getPrice(sym: string): number; + /** + * Returns the organization associated with a 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 + * + * 1. TIX API Access + * + * @example + * ```ts + * // NS1 + * stock.getOrganization("FSIG"); + * + * // Choose the first stock symbol from the array of stock symbols. Get the + * // organization associated with the corresponding stock symbol + * var sym = stock.getSymbols()[0]; + * tprint("Stock symbol: " + sym); + * tprint("Stock organization: " + stock.getOrganization(sym)); + * ``` + * @example + * ```ts + * // NS2 + * 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)); + * ``` + * @param sym - Stock symbol. + * @returns The organization assicated with the stock symbol. + */ + getOrganization(sym: string): string; + /** * Returns the ask price of that stock. * @remarks RAM cost: 2 GB