STOCK: ns.stock.getOrganization added for getting org from stock symbol (#234)

Authored-by: SamuraiNinjaGuy <branmiller+bitburner@gmail.com>
This commit is contained in:
Snarling 2022-11-28 10:33:28 -05:00 committed by GitHub
parent 837c6bd1c2
commit 0fb7200b4b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 48 additions and 0 deletions

@ -127,6 +127,7 @@ const stock = {
has4SDataTIXAPI: 0.05, has4SDataTIXAPI: 0.05,
getSymbols: RamCostConstants.ScriptGetStockRamCost, getSymbols: RamCostConstants.ScriptGetStockRamCost,
getPrice: RamCostConstants.ScriptGetStockRamCost, getPrice: RamCostConstants.ScriptGetStockRamCost,
getOrganization: RamCostConstants.ScriptGetStockRamCost,
getAskPrice: RamCostConstants.ScriptGetStockRamCost, getAskPrice: RamCostConstants.ScriptGetStockRamCost,
getBidPrice: RamCostConstants.ScriptGetStockRamCost, getBidPrice: RamCostConstants.ScriptGetStockRamCost,
getPosition: RamCostConstants.ScriptGetStockRamCost, getPosition: RamCostConstants.ScriptGetStockRamCost,

@ -60,6 +60,13 @@ export function NetscriptStockMarket(): InternalAPI<TIX> {
return stock.price; 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) => { getAskPrice: (ctx) => (_symbol) => {
const symbol = helpers.string(ctx, "symbol", _symbol); const symbol = helpers.string(ctx, "symbol", _symbol);
checkTixApiAccess(ctx); checkTixApiAccess(ctx);

@ -1061,6 +1061,46 @@ export interface TIX {
*/ */
getPrice(sym: string): number; 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. * Returns the ask price of that stock.
* @remarks RAM cost: 2 GB * @remarks RAM cost: 2 GB