NETSCRIPT: Add ns.stock.getConstants (#692)

This commit is contained in:
Snarling 2023-07-31 23:08:42 -04:00 committed by GitHub
parent a85efbc4da
commit 1c6369ffa4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
18 changed files with 230 additions and 56 deletions

@ -34,12 +34,10 @@ declare enum JobName
| IT3 | <code>&quot;Systems Administrator&quot;</code> | | | IT3 | <code>&quot;Systems Administrator&quot;</code> | |
| networkEng0 | <code>&quot;Network Engineer&quot;</code> | | | networkEng0 | <code>&quot;Network Engineer&quot;</code> | |
| networkEng1 | <code>&quot;Network Administrator&quot;</code> | | | networkEng1 | <code>&quot;Network Administrator&quot;</code> | |
| security0 | <code>&quot;Police Officer&quot;</code> | | | security0 | <code>&quot;Security Guard&quot;</code> | |
| security1 | <code>&quot;Police Chief&quot;</code> | | | security1 | <code>&quot;Security Officer&quot;</code> | |
| security2 | <code>&quot;Security Guard&quot;</code> | | | security2 | <code>&quot;Security Supervisor&quot;</code> | |
| security3 | <code>&quot;Security Officer&quot;</code> | | | security3 | <code>&quot;Head of Security&quot;</code> | |
| security4 | <code>&quot;Security Supervisor&quot;</code> | |
| security5 | <code>&quot;Head of Security&quot;</code> | |
| securityEng | <code>&quot;Security Engineer&quot;</code> | | | securityEng | <code>&quot;Security Engineer&quot;</code> | |
| software0 | <code>&quot;Software Engineering Intern&quot;</code> | | | software0 | <code>&quot;Software Engineering Intern&quot;</code> | |
| software1 | <code>&quot;Junior Software Engineer&quot;</code> | | | software1 | <code>&quot;Junior Software Engineer&quot;</code> | |

@ -98,6 +98,7 @@
| [SleevePerson](./bitburner.sleeveperson.md) | | | [SleevePerson](./bitburner.sleeveperson.md) | |
| [SourceFileLvl](./bitburner.sourcefilelvl.md) | | | [SourceFileLvl](./bitburner.sourcefilelvl.md) | |
| [Stanek](./bitburner.stanek.md) | Stanek's Gift API. | | [Stanek](./bitburner.stanek.md) | Stanek's Gift API. |
| [StockMarketConstants](./bitburner.stockmarketconstants.md) | Constants used for the stockmarket game mechanic. |
| [StockOrder](./bitburner.stockorder.md) | <p>Return value of [getOrders](./bitburner.tix.getorders.md)</p><p>Keys are stock symbols, properties are arrays of [StockOrderObject](./bitburner.stockorderobject.md)</p> | | [StockOrder](./bitburner.stockorder.md) | <p>Return value of [getOrders](./bitburner.tix.getorders.md)</p><p>Keys are stock symbols, properties are arrays of [StockOrderObject](./bitburner.stockorderobject.md)</p> |
| [StockOrderObject](./bitburner.stockorderobject.md) | Value in map of [StockOrder](./bitburner.stockorder.md) | | [StockOrderObject](./bitburner.stockorderobject.md) | Value in map of [StockOrder](./bitburner.stockorder.md) |
| [TailProperties](./bitburner.tailproperties.md) | | | [TailProperties](./bitburner.tailproperties.md) | |

@ -0,0 +1,13 @@
<!-- Do not edit this file. It is automatically generated by API Documenter. -->
[Home](./index.md) &gt; [bitburner](./bitburner.md) &gt; [StockMarketConstants](./bitburner.stockmarketconstants.md) &gt; [MarketData4SCost](./bitburner.stockmarketconstants.marketdata4scost.md)
## StockMarketConstants.MarketData4SCost property
Cost of the 4S Market Data
**Signature:**
```typescript
MarketData4SCost: number;
```

@ -0,0 +1,13 @@
<!-- Do not edit this file. It is automatically generated by API Documenter. -->
[Home](./index.md) &gt; [bitburner](./bitburner.md) &gt; [StockMarketConstants](./bitburner.stockmarketconstants.md) &gt; [MarketDataTixApi4SCost](./bitburner.stockmarketconstants.marketdatatixapi4scost.md)
## StockMarketConstants.MarketDataTixApi4SCost property
Cost of the 4S Market Data TIX API integration
**Signature:**
```typescript
MarketDataTixApi4SCost: number;
```

@ -0,0 +1,27 @@
<!-- Do not edit this file. It is automatically generated by API Documenter. -->
[Home](./index.md) &gt; [bitburner](./bitburner.md) &gt; [StockMarketConstants](./bitburner.stockmarketconstants.md)
## StockMarketConstants interface
Constants used for the stockmarket game mechanic.
**Signature:**
```typescript
interface StockMarketConstants
```
## Properties
| Property | Modifiers | Type | Description |
| --- | --- | --- | --- |
| [MarketData4SCost](./bitburner.stockmarketconstants.marketdata4scost.md) | | number | Cost of the 4S Market Data |
| [MarketDataTixApi4SCost](./bitburner.stockmarketconstants.marketdatatixapi4scost.md) | | number | Cost of the 4S Market Data TIX API integration |
| [msPerStockUpdate](./bitburner.stockmarketconstants.msperstockupdate.md) | | number | Normal time in ms between stock market updates |
| [msPerStockUpdateMin](./bitburner.stockmarketconstants.msperstockupdatemin.md) | | number | Minimum time in ms between stock market updates if there is stored offline/bonus time |
| [StockMarketCommission](./bitburner.stockmarketconstants.stockmarketcommission.md) | | number | Commission fee for transactions |
| [TicksPerCycle](./bitburner.stockmarketconstants.tickspercycle.md) | | number | An internal constant used while determining when to flip a stock's forecast |
| [TIXAPICost](./bitburner.stockmarketconstants.tixapicost.md) | | number | Cost of the TIX API |
| [WSEAccountCost](./bitburner.stockmarketconstants.wseaccountcost.md) | | number | Cost of the WSE account |

@ -0,0 +1,13 @@
<!-- Do not edit this file. It is automatically generated by API Documenter. -->
[Home](./index.md) &gt; [bitburner](./bitburner.md) &gt; [StockMarketConstants](./bitburner.stockmarketconstants.md) &gt; [msPerStockUpdate](./bitburner.stockmarketconstants.msperstockupdate.md)
## StockMarketConstants.msPerStockUpdate property
Normal time in ms between stock market updates
**Signature:**
```typescript
msPerStockUpdate: number;
```

@ -0,0 +1,13 @@
<!-- Do not edit this file. It is automatically generated by API Documenter. -->
[Home](./index.md) &gt; [bitburner](./bitburner.md) &gt; [StockMarketConstants](./bitburner.stockmarketconstants.md) &gt; [msPerStockUpdateMin](./bitburner.stockmarketconstants.msperstockupdatemin.md)
## StockMarketConstants.msPerStockUpdateMin property
Minimum time in ms between stock market updates if there is stored offline/bonus time
**Signature:**
```typescript
msPerStockUpdateMin: number;
```

@ -0,0 +1,13 @@
<!-- Do not edit this file. It is automatically generated by API Documenter. -->
[Home](./index.md) &gt; [bitburner](./bitburner.md) &gt; [StockMarketConstants](./bitburner.stockmarketconstants.md) &gt; [StockMarketCommission](./bitburner.stockmarketconstants.stockmarketcommission.md)
## StockMarketConstants.StockMarketCommission property
Commission fee for transactions
**Signature:**
```typescript
StockMarketCommission: number;
```

@ -0,0 +1,13 @@
<!-- Do not edit this file. It is automatically generated by API Documenter. -->
[Home](./index.md) &gt; [bitburner](./bitburner.md) &gt; [StockMarketConstants](./bitburner.stockmarketconstants.md) &gt; [TicksPerCycle](./bitburner.stockmarketconstants.tickspercycle.md)
## StockMarketConstants.TicksPerCycle property
An internal constant used while determining when to flip a stock's forecast
**Signature:**
```typescript
TicksPerCycle: number;
```

@ -0,0 +1,13 @@
<!-- Do not edit this file. It is automatically generated by API Documenter. -->
[Home](./index.md) &gt; [bitburner](./bitburner.md) &gt; [StockMarketConstants](./bitburner.stockmarketconstants.md) &gt; [TIXAPICost](./bitburner.stockmarketconstants.tixapicost.md)
## StockMarketConstants.TIXAPICost property
Cost of the TIX API
**Signature:**
```typescript
TIXAPICost: number;
```

@ -0,0 +1,13 @@
<!-- Do not edit this file. It is automatically generated by API Documenter. -->
[Home](./index.md) &gt; [bitburner](./bitburner.md) &gt; [StockMarketConstants](./bitburner.stockmarketconstants.md) &gt; [WSEAccountCost](./bitburner.stockmarketconstants.wseaccountcost.md)
## StockMarketConstants.WSEAccountCost property
Cost of the WSE account
**Signature:**
```typescript
WSEAccountCost: number;
```

@ -0,0 +1,21 @@
<!-- Do not edit this file. It is automatically generated by API Documenter. -->
[Home](./index.md) &gt; [bitburner](./bitburner.md) &gt; [TIX](./bitburner.tix.md) &gt; [getConstants](./bitburner.tix.getconstants.md)
## TIX.getConstants() method
Get game constants for the stock market mechanic.
**Signature:**
```typescript
getConstants(): StockMarketConstants;
```
**Returns:**
[StockMarketConstants](./bitburner.stockmarketconstants.md)
## Remarks
RAM cost: 0 GB

@ -21,6 +21,7 @@ export interface TIX
| [cancelOrder(sym, shares, price, type, pos)](./bitburner.tix.cancelorder.md) | Cancel order for stocks. | | [cancelOrder(sym, shares, price, type, pos)](./bitburner.tix.cancelorder.md) | Cancel order for stocks. |
| [getAskPrice(sym)](./bitburner.tix.getaskprice.md) | Returns the ask price of that stock. | | [getAskPrice(sym)](./bitburner.tix.getaskprice.md) | Returns the ask price of that stock. |
| [getBidPrice(sym)](./bitburner.tix.getbidprice.md) | Returns the bid price of that stock. | | [getBidPrice(sym)](./bitburner.tix.getbidprice.md) | Returns the bid price of that stock. |
| [getConstants()](./bitburner.tix.getconstants.md) | Get game constants for the stock market mechanic. |
| [getForecast(sym)](./bitburner.tix.getforecast.md) | Returns the probability that the specified stocks price will increase (as opposed to decrease) during the next tick. | | [getForecast(sym)](./bitburner.tix.getforecast.md) | Returns the probability that the specified stocks price will increase (as opposed to decrease) during the next tick. |
| [getMaxShares(sym)](./bitburner.tix.getmaxshares.md) | Returns the maximum number of shares of a stock. | | [getMaxShares(sym)](./bitburner.tix.getmaxshares.md) | Returns the maximum number of shares of a stock. |
| [getOrders()](./bitburner.tix.getorders.md) | Returns your order book for the stock market. | | [getOrders()](./bitburner.tix.getorders.md) | Returns your order book for the stock market. |

@ -228,6 +228,11 @@ Changes below include spoilers.
### NETSCRIPT: ### NETSCRIPT:
* Added ns.stock.getConstants (@Snarling)
* ns.sleeve.setToFactionWork no longer allows working for factions the player has not joined. (@Snarling) * ns.sleeve.setToFactionWork no longer allows working for factions the player has not joined. (@Snarling)
### Internal Code Refactors
* Reorganize game constants (@zerbosh)
`, `,
}; };

@ -118,6 +118,7 @@ const hacknet = {
// Stock API // Stock API
const stock = { const stock = {
getConstants: 0,
hasWSEAccount: 0.05, hasWSEAccount: 0.05,
hasTIXAPIAccess: 0.05, hasTIXAPIAccess: 0.05,
has4SData: 0.05, has4SData: 0.05,
@ -348,7 +349,7 @@ const grafting = {
const corporation = { const corporation = {
hasCorporation: 0, // This one is free hasCorporation: 0, // This one is free
getConstants: RamCostConstants.Corporation, getConstants: 0,
getIndustryData: RamCostConstants.Corporation, getIndustryData: RamCostConstants.Corporation,
getMaterialData: RamCostConstants.Corporation, getMaterialData: RamCostConstants.Corporation,
issueNewShares: RamCostConstants.Corporation, issueNewShares: RamCostConstants.Corporation,

@ -1,4 +1,4 @@
import { Player as player } from "../Player"; import { Player } from "../Player";
import { buyStock, sellStock, shortStock, sellShort } from "../StockMarket/BuyingAndSelling"; import { buyStock, sellStock, shortStock, sellShort } from "../StockMarket/BuyingAndSelling";
import { StockMarket, SymbolToStockMap, placeOrder, cancelOrder, initStockMarket } from "../StockMarket/StockMarket"; import { StockMarket, SymbolToStockMap, placeOrder, cancelOrder, initStockMarket } from "../StockMarket/StockMarket";
import { getBuyTransactionCost, getSellTransactionGain } from "../StockMarket/StockMarketHelpers"; import { getBuyTransactionCost, getSellTransactionGain } from "../StockMarket/StockMarketHelpers";
@ -13,14 +13,16 @@ import { Stock } from "../StockMarket/Stock";
import { StockOrder, TIX } from "@nsdefs"; import { StockOrder, TIX } from "@nsdefs";
import { InternalAPI, NetscriptContext } from "../Netscript/APIWrapper"; import { InternalAPI, NetscriptContext } from "../Netscript/APIWrapper";
import { helpers } from "../Netscript/NetscriptHelpers"; import { helpers } from "../Netscript/NetscriptHelpers";
import { cloneDeep } from "lodash";
import { StockMarketConstants } from "../StockMarket/data/Constants";
export function NetscriptStockMarket(): InternalAPI<TIX> { export function NetscriptStockMarket(): InternalAPI<TIX> {
/** Checks if the player has TIX API access. Throws an error if the player does not */ /** Checks if the player has TIX API access. Throws an error if the player does not */
const checkTixApiAccess = function (ctx: NetscriptContext): void { const checkTixApiAccess = function (ctx: NetscriptContext): void {
if (!player.hasWseAccount) { if (!Player.hasWseAccount) {
throw helpers.makeRuntimeErrorMsg(ctx, `You don't have WSE Access! Cannot use ${ctx.function}()`); throw helpers.makeRuntimeErrorMsg(ctx, `You don't have WSE Access! Cannot use ${ctx.function}()`);
} }
if (!player.hasTixApiAccess) { if (!Player.hasTixApiAccess) {
throw helpers.makeRuntimeErrorMsg(ctx, `You don't have TIX API Access! Cannot use ${ctx.function}()`); throw helpers.makeRuntimeErrorMsg(ctx, `You don't have TIX API Access! Cannot use ${ctx.function}()`);
} }
}; };
@ -35,18 +37,11 @@ export function NetscriptStockMarket(): InternalAPI<TIX> {
}; };
return { return {
hasWSEAccount: () => () => { getConstants: () => () => cloneDeep(StockMarketConstants),
return player.hasWseAccount; hasWSEAccount: () => () => Player.hasWseAccount,
}, hasTIXAPIAccess: () => () => Player.hasTixApiAccess,
hasTIXAPIAccess: () => () => { has4SData: () => () => Player.has4SData,
return player.hasTixApiAccess; has4SDataTIXAPI: () => () => Player.has4SDataTixApi,
},
has4SData: () => () => {
return player.has4SData;
},
has4SDataTIXAPI: () => () => {
return player.has4SDataTixApi;
},
getSymbols: (ctx) => () => { getSymbols: (ctx) => () => {
checkTixApiAccess(ctx); checkTixApiAccess(ctx);
return Object.values(StockSymbol); return Object.values(StockSymbol);
@ -166,8 +161,8 @@ export function NetscriptStockMarket(): InternalAPI<TIX> {
const symbol = helpers.string(ctx, "symbol", _symbol); const symbol = helpers.string(ctx, "symbol", _symbol);
const shares = helpers.number(ctx, "shares", _shares); const shares = helpers.number(ctx, "shares", _shares);
checkTixApiAccess(ctx); checkTixApiAccess(ctx);
if (player.bitNodeN !== 8) { if (Player.bitNodeN !== 8) {
if (player.sourceFileLvl(8) <= 1) { if (Player.sourceFileLvl(8) <= 1) {
throw helpers.makeRuntimeErrorMsg( throw helpers.makeRuntimeErrorMsg(
ctx, ctx,
"You must either be in BitNode-8 or you must have Source-File 8 Level 2.", "You must either be in BitNode-8 or you must have Source-File 8 Level 2.",
@ -183,8 +178,8 @@ export function NetscriptStockMarket(): InternalAPI<TIX> {
const symbol = helpers.string(ctx, "symbol", _symbol); const symbol = helpers.string(ctx, "symbol", _symbol);
const shares = helpers.number(ctx, "shares", _shares); const shares = helpers.number(ctx, "shares", _shares);
checkTixApiAccess(ctx); checkTixApiAccess(ctx);
if (player.bitNodeN !== 8) { if (Player.bitNodeN !== 8) {
if (player.sourceFileLvl(8) <= 1) { if (Player.sourceFileLvl(8) <= 1) {
throw helpers.makeRuntimeErrorMsg( throw helpers.makeRuntimeErrorMsg(
ctx, ctx,
"You must either be in BitNode-8 or you must have Source-File 8 Level 2.", "You must either be in BitNode-8 or you must have Source-File 8 Level 2.",
@ -203,8 +198,8 @@ export function NetscriptStockMarket(): InternalAPI<TIX> {
const type = helpers.string(ctx, "type", _type); const type = helpers.string(ctx, "type", _type);
const pos = helpers.string(ctx, "pos", _pos); const pos = helpers.string(ctx, "pos", _pos);
checkTixApiAccess(ctx); checkTixApiAccess(ctx);
if (player.bitNodeN !== 8) { if (Player.bitNodeN !== 8) {
if (player.sourceFileLvl(8) <= 2) { if (Player.sourceFileLvl(8) <= 2) {
throw helpers.makeRuntimeErrorMsg( throw helpers.makeRuntimeErrorMsg(
ctx, ctx,
"You must either be in BitNode-8 or you must have Source-File 8 Level 3.", "You must either be in BitNode-8 or you must have Source-File 8 Level 3.",
@ -246,8 +241,8 @@ export function NetscriptStockMarket(): InternalAPI<TIX> {
const type = helpers.string(ctx, "type", _type); const type = helpers.string(ctx, "type", _type);
const pos = helpers.string(ctx, "pos", _pos); const pos = helpers.string(ctx, "pos", _pos);
checkTixApiAccess(ctx); checkTixApiAccess(ctx);
if (player.bitNodeN !== 8) { if (Player.bitNodeN !== 8) {
if (player.sourceFileLvl(8) <= 2) { if (Player.sourceFileLvl(8) <= 2) {
throw helpers.makeRuntimeErrorMsg( throw helpers.makeRuntimeErrorMsg(
ctx, ctx,
"You must either be in BitNode-8 or you must have Source-File 8 Level 3.", "You must either be in BitNode-8 or you must have Source-File 8 Level 3.",
@ -295,8 +290,8 @@ export function NetscriptStockMarket(): InternalAPI<TIX> {
}, },
getOrders: (ctx) => () => { getOrders: (ctx) => () => {
checkTixApiAccess(ctx); checkTixApiAccess(ctx);
if (player.bitNodeN !== 8) { if (Player.bitNodeN !== 8) {
if (player.sourceFileLvl(8) <= 2) { if (Player.sourceFileLvl(8) <= 2) {
throw helpers.makeRuntimeErrorMsg(ctx, "You must either be in BitNode-8 or have Source-File 8 Level 3."); throw helpers.makeRuntimeErrorMsg(ctx, "You must either be in BitNode-8 or have Source-File 8 Level 3.");
} }
} }
@ -323,7 +318,7 @@ export function NetscriptStockMarket(): InternalAPI<TIX> {
}, },
getVolatility: (ctx) => (_symbol) => { getVolatility: (ctx) => (_symbol) => {
const symbol = helpers.string(ctx, "symbol", _symbol); const symbol = helpers.string(ctx, "symbol", _symbol);
if (!player.has4SDataTixApi) { if (!Player.has4SDataTixApi) {
throw helpers.makeRuntimeErrorMsg(ctx, "You don't have 4S Market Data TIX API Access!"); throw helpers.makeRuntimeErrorMsg(ctx, "You don't have 4S Market Data TIX API Access!");
} }
const stock = getStockFromSymbol(ctx, symbol); const stock = getStockFromSymbol(ctx, symbol);
@ -332,7 +327,7 @@ export function NetscriptStockMarket(): InternalAPI<TIX> {
}, },
getForecast: (ctx) => (_symbol) => { getForecast: (ctx) => (_symbol) => {
const symbol = helpers.string(ctx, "symbol", _symbol); const symbol = helpers.string(ctx, "symbol", _symbol);
if (!player.has4SDataTixApi) { if (!Player.has4SDataTixApi) {
throw helpers.makeRuntimeErrorMsg(ctx, "You don't have 4S Market Data TIX API Access!"); throw helpers.makeRuntimeErrorMsg(ctx, "You don't have 4S Market Data TIX API Access!");
} }
const stock = getStockFromSymbol(ctx, symbol); const stock = getStockFromSymbol(ctx, symbol);
@ -342,69 +337,69 @@ export function NetscriptStockMarket(): InternalAPI<TIX> {
return forecast / 100; // Convert from percentage to decimal return forecast / 100; // Convert from percentage to decimal
}, },
purchase4SMarketData: (ctx) => () => { purchase4SMarketData: (ctx) => () => {
if (player.has4SData) { if (Player.has4SData) {
helpers.log(ctx, () => "Already purchased 4S Market Data."); helpers.log(ctx, () => "Already purchased 4S Market Data.");
return true; return true;
} }
if (player.money < getStockMarket4SDataCost()) { if (Player.money < getStockMarket4SDataCost()) {
helpers.log(ctx, () => "Not enough money to purchase 4S Market Data."); helpers.log(ctx, () => "Not enough money to purchase 4S Market Data.");
return false; return false;
} }
player.has4SData = true; Player.has4SData = true;
player.loseMoney(getStockMarket4SDataCost(), "stock"); Player.loseMoney(getStockMarket4SDataCost(), "stock");
helpers.log(ctx, () => "Purchased 4S Market Data"); helpers.log(ctx, () => "Purchased 4S Market Data");
return true; return true;
}, },
purchase4SMarketDataTixApi: (ctx) => () => { purchase4SMarketDataTixApi: (ctx) => () => {
checkTixApiAccess(ctx); checkTixApiAccess(ctx);
if (player.has4SDataTixApi) { if (Player.has4SDataTixApi) {
helpers.log(ctx, () => "Already purchased 4S Market Data TIX API"); helpers.log(ctx, () => "Already purchased 4S Market Data TIX API");
return true; return true;
} }
if (player.money < getStockMarket4STixApiCost()) { if (Player.money < getStockMarket4STixApiCost()) {
helpers.log(ctx, () => "Not enough money to purchase 4S Market Data TIX API"); helpers.log(ctx, () => "Not enough money to purchase 4S Market Data TIX API");
return false; return false;
} }
player.has4SDataTixApi = true; Player.has4SDataTixApi = true;
player.loseMoney(getStockMarket4STixApiCost(), "stock"); Player.loseMoney(getStockMarket4STixApiCost(), "stock");
helpers.log(ctx, () => "Purchased 4S Market Data TIX API"); helpers.log(ctx, () => "Purchased 4S Market Data TIX API");
return true; return true;
}, },
purchaseWseAccount: (ctx) => () => { purchaseWseAccount: (ctx) => () => {
if (player.hasWseAccount) { if (Player.hasWseAccount) {
helpers.log(ctx, () => "Already purchased WSE Account"); helpers.log(ctx, () => "Already purchased WSE Account");
return true; return true;
} }
if (player.money < getStockMarketWseCost()) { if (Player.money < getStockMarketWseCost()) {
helpers.log(ctx, () => "Not enough money to purchase WSE Account Access"); helpers.log(ctx, () => "Not enough money to purchase WSE Account Access");
return false; return false;
} }
player.hasWseAccount = true; Player.hasWseAccount = true;
initStockMarket(); initStockMarket();
player.loseMoney(getStockMarketWseCost(), "stock"); Player.loseMoney(getStockMarketWseCost(), "stock");
helpers.log(ctx, () => "Purchased WSE Account Access"); helpers.log(ctx, () => "Purchased WSE Account Access");
return true; return true;
}, },
purchaseTixApi: (ctx) => () => { purchaseTixApi: (ctx) => () => {
if (player.hasTixApiAccess) { if (Player.hasTixApiAccess) {
helpers.log(ctx, () => "Already purchased TIX API"); helpers.log(ctx, () => "Already purchased TIX API");
return true; return true;
} }
if (player.money < getStockMarketTixApiCost()) { if (Player.money < getStockMarketTixApiCost()) {
helpers.log(ctx, () => "Not enough money to purchase TIX API Access"); helpers.log(ctx, () => "Not enough money to purchase TIX API Access");
return false; return false;
} }
player.hasTixApiAccess = true; Player.hasTixApiAccess = true;
player.loseMoney(getStockMarketTixApiCost(), "stock"); Player.loseMoney(getStockMarketTixApiCost(), "stock");
helpers.log(ctx, () => "Purchased TIX API"); helpers.log(ctx, () => "Purchased TIX API");
return true; return true;
}, },

@ -393,6 +393,27 @@ interface StockOrder {
[key: string]: StockOrderObject[]; [key: string]: StockOrderObject[];
} }
/** Constants used for the stockmarket game mechanic.
* @public */
interface StockMarketConstants {
/** Normal time in ms between stock market updates */
msPerStockUpdate: number;
/** Minimum time in ms between stock market updates if there is stored offline/bonus time */
msPerStockUpdateMin: number;
/** An internal constant used while determining when to flip a stock's forecast */
TicksPerCycle: number;
/** Cost of the WSE account */
WSEAccountCost: number;
/** Cost of the TIX API */
TIXAPICost: number;
/** Cost of the 4S Market Data */
MarketData4SCost: number;
/** Cost of the 4S Market Data TIX API integration */
MarketDataTixApi4SCost: number;
/** Commission fee for transactions */
StockMarketCommission: number;
}
/** /**
* A single process on a server. * A single process on a server.
* @public * @public
@ -1077,6 +1098,9 @@ export interface NetscriptPort {
* @public * @public
*/ */
export interface TIX { export interface TIX {
/** Get game constants for the stock market mechanic.
* @remarks RAM cost: 0 GB */
getConstants(): StockMarketConstants;
/** /**
* Returns true if the player has access to a WSE Account * Returns true if the player has access to a WSE Account
* @remarks RAM cost: 0.05 GB * @remarks RAM cost: 0.05 GB

@ -1,12 +1,9 @@
export const StockMarketConstants = { import { StockMarketConstants as ConstantsType } from "@nsdefs";
//stock tick times in milliseconds
export const StockMarketConstants: ConstantsType = {
msPerStockUpdate: 6e3, msPerStockUpdate: 6e3,
msPerStockUpdateMin: 4e3, msPerStockUpdateMin: 4e3,
//defines the length of the flip timer in stock cycles
TicksPerCycle: 75, TicksPerCycle: 75,
// Stockmarket costs Constants
WSEAccountCost: 200e6, WSEAccountCost: 200e6,
TIXAPICost: 5e9, TIXAPICost: 5e9,
MarketData4SCost: 1e9, MarketData4SCost: 1e9,