GO: Various changes before 2.6.0 (#1120)

This commit is contained in:
Snarling
2024-02-26 08:05:10 -05:00
committed by GitHub
parent f6871f0911
commit 373ced2efe
62 changed files with 1626 additions and 2135 deletions
+16 -31
View File
@@ -26,17 +26,17 @@ export function NetscriptStockMarket(): InternalAPI<TIX> {
/** Checks if the player has TIX API access. Throws an error if the player does not */
const checkTixApiAccess = function (ctx: NetscriptContext): void {
if (!Player.hasWseAccount) {
throw helpers.makeRuntimeErrorMsg(ctx, `You don't have WSE Access! Cannot use ${ctx.function}()`);
throw helpers.errorMessage(ctx, `You don't have WSE Access! Cannot use ${ctx.function}()`);
}
if (!Player.hasTixApiAccess) {
throw helpers.makeRuntimeErrorMsg(ctx, `You don't have TIX API Access! Cannot use ${ctx.function}()`);
throw helpers.errorMessage(ctx, `You don't have TIX API Access! Cannot use ${ctx.function}()`);
}
};
const getStockFromSymbol = function (ctx: NetscriptContext, symbol: string): Stock {
const stock = SymbolToStockMap[symbol];
if (stock == null) {
throw helpers.makeRuntimeErrorMsg(ctx, `Invalid stock symbol: '${symbol}'`);
throw helpers.errorMessage(ctx, `Invalid stock symbol: '${symbol}'`);
}
return stock;
@@ -85,7 +85,7 @@ export function NetscriptStockMarket(): InternalAPI<TIX> {
checkTixApiAccess(ctx);
const stock = SymbolToStockMap[symbol];
if (stock == null) {
throw helpers.makeRuntimeErrorMsg(ctx, `Invalid stock symbol: ${symbol}`);
throw helpers.errorMessage(ctx, `Invalid stock symbol: ${symbol}`);
}
return [stock.playerShares, stock.playerAvgPx, stock.playerShortShares, stock.playerAvgShortPx];
},
@@ -169,10 +169,7 @@ export function NetscriptStockMarket(): InternalAPI<TIX> {
checkTixApiAccess(ctx);
if (Player.bitNodeN !== 8) {
if (Player.sourceFileLvl(8) <= 1) {
throw helpers.makeRuntimeErrorMsg(
ctx,
"You must either be in BitNode-8 or you must have Source-File 8 Level 2.",
);
throw helpers.errorMessage(ctx, "You must either be in BitNode-8 or you must have Source-File 8 Level 2.");
}
}
const stock = getStockFromSymbol(ctx, symbol);
@@ -186,10 +183,7 @@ export function NetscriptStockMarket(): InternalAPI<TIX> {
checkTixApiAccess(ctx);
if (Player.bitNodeN !== 8) {
if (Player.sourceFileLvl(8) <= 1) {
throw helpers.makeRuntimeErrorMsg(
ctx,
"You must either be in BitNode-8 or you must have Source-File 8 Level 2.",
);
throw helpers.errorMessage(ctx, "You must either be in BitNode-8 or you must have Source-File 8 Level 2.");
}
}
const stock = getStockFromSymbol(ctx, symbol);
@@ -206,10 +200,7 @@ export function NetscriptStockMarket(): InternalAPI<TIX> {
checkTixApiAccess(ctx);
if (Player.bitNodeN !== 8) {
if (Player.sourceFileLvl(8) <= 2) {
throw helpers.makeRuntimeErrorMsg(
ctx,
"You must either be in BitNode-8 or you must have Source-File 8 Level 3.",
);
throw helpers.errorMessage(ctx, "You must either be in BitNode-8 or you must have Source-File 8 Level 3.");
}
}
const stock = getStockFromSymbol(ctx, symbol);
@@ -226,7 +217,7 @@ export function NetscriptStockMarket(): InternalAPI<TIX> {
} else if (ltype.includes("stop") && ltype.includes("sell")) {
orderType = OrderType.StopSell;
} else {
throw helpers.makeRuntimeErrorMsg(ctx, `Invalid order type: ${type}`);
throw helpers.errorMessage(ctx, `Invalid order type: ${type}`);
}
const lpos = pos.toLowerCase();
@@ -235,7 +226,7 @@ export function NetscriptStockMarket(): InternalAPI<TIX> {
} else if (lpos.includes("s")) {
orderPos = PositionType.Short;
} else {
throw helpers.makeRuntimeErrorMsg(ctx, `Invalid position type: ${pos}`);
throw helpers.errorMessage(ctx, `Invalid position type: ${pos}`);
}
return placeOrder(stock, shares, price, orderType, orderPos, ctx);
@@ -249,18 +240,12 @@ export function NetscriptStockMarket(): InternalAPI<TIX> {
checkTixApiAccess(ctx);
if (Player.bitNodeN !== 8) {
if (Player.sourceFileLvl(8) <= 2) {
throw helpers.makeRuntimeErrorMsg(
ctx,
"You must either be in BitNode-8 or you must have Source-File 8 Level 3.",
);
throw helpers.errorMessage(ctx, "You must either be in BitNode-8 or you must have Source-File 8 Level 3.");
}
}
const stock = getStockFromSymbol(ctx, symbol);
if (isNaN(shares) || isNaN(price)) {
throw helpers.makeRuntimeErrorMsg(
ctx,
`Invalid shares or price. Must be numeric. shares=${shares}, price=${price}`,
);
throw helpers.errorMessage(ctx, `Invalid shares or price. Must be numeric. shares=${shares}, price=${price}`);
}
let orderType;
let orderPos;
@@ -274,7 +259,7 @@ export function NetscriptStockMarket(): InternalAPI<TIX> {
} else if (ltype.includes("stop") && ltype.includes("sell")) {
orderType = OrderType.StopSell;
} else {
throw helpers.makeRuntimeErrorMsg(ctx, `Invalid order type: ${type}`);
throw helpers.errorMessage(ctx, `Invalid order type: ${type}`);
}
const lpos = pos.toLowerCase();
@@ -283,7 +268,7 @@ export function NetscriptStockMarket(): InternalAPI<TIX> {
} else if (lpos.includes("s")) {
orderPos = PositionType.Short;
} else {
throw helpers.makeRuntimeErrorMsg(ctx, `Invalid position type: ${pos}`);
throw helpers.errorMessage(ctx, `Invalid position type: ${pos}`);
}
const params = {
stock: stock,
@@ -298,7 +283,7 @@ export function NetscriptStockMarket(): InternalAPI<TIX> {
checkTixApiAccess(ctx);
if (Player.bitNodeN !== 8) {
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.errorMessage(ctx, "You must either be in BitNode-8 or have Source-File 8 Level 3.");
}
}
@@ -325,7 +310,7 @@ export function NetscriptStockMarket(): InternalAPI<TIX> {
getVolatility: (ctx) => (_symbol) => {
const symbol = helpers.string(ctx, "symbol", _symbol);
if (!Player.has4SDataTixApi) {
throw helpers.makeRuntimeErrorMsg(ctx, "You don't have 4S Market Data TIX API Access!");
throw helpers.errorMessage(ctx, "You don't have 4S Market Data TIX API Access!");
}
const stock = getStockFromSymbol(ctx, symbol);
@@ -334,7 +319,7 @@ export function NetscriptStockMarket(): InternalAPI<TIX> {
getForecast: (ctx) => (_symbol) => {
const symbol = helpers.string(ctx, "symbol", _symbol);
if (!Player.has4SDataTixApi) {
throw helpers.makeRuntimeErrorMsg(ctx, "You don't have 4S Market Data TIX API Access!");
throw helpers.errorMessage(ctx, "You don't have 4S Market Data TIX API Access!");
}
const stock = getStockFromSymbol(ctx, symbol);