Re-added the getStockPurchaseCost() and getStockSaleGain() functions so we don't break user scripts

This commit is contained in:
danielyxie
2019-06-02 20:28:02 -07:00
parent e5e3fec1a9
commit 0b4968d148
6 changed files with 81 additions and 2 deletions
+46
View File
@@ -98,6 +98,10 @@ import {
cancelOrder,
displayStockMarketContent,
} from "./StockMarket/StockMarket";
import {
getBuyTransactionCost,
getSellTransactionGain,
} from "./StockMarket/StockMarketHelpers";
import { OrderTypes } from "./StockMarket/data/OrderTypes";
import { PositionTypes } from "./StockMarket/data/PositionTypes";
import { StockSymbols } from "./StockMarket/data/StockSymbols";
@@ -1492,6 +1496,48 @@ function NetscriptFunctions(workerScript) {
return stock.maxShares;
},
getStockPurchaseCost: function(symbol, shares, posType) {
updateDynamicRam("getStockPurchaseCost", getRamCost("getStockPurchaseCost"));
checkTixApiAccess("getStockPurchaseCost");
const stock = getStockFromSymbol(symbol, "getStockPurchaseCost");
shares = Math.round(shares);
let pos;
const sanitizedPosType = posType.toLowerCase();
if (sanitizedPosType.includes("l")) {
pos = PositionTypes.Long;
} else if (sanitizedPosType.includes("s")) {
pos = PositionTypes.Short;
} else {
return Infinity;
}
const res = getBuyTransactionCost(stock, shares, pos);
if (res == null) { return Infinity; }
return res;
},
getStockSaleGain: function(symbol, shares, posType) {
updateDynamicRam("getStockSaleGain", getRamCost("getStockSaleGain"));
checkTixApiAccess("getStockSaleGain");
const stock = getStockFromSymbol(symbol, "getStockSaleGain");
shares = Math.round(shares);
let pos;
const sanitizedPosType = posType.toLowerCase();
if (sanitizedPosType.includes("l")) {
pos = PositionTypes.Long;
} else if (sanitizedPosType.includes("s")) {
pos = PositionTypes.Short;
} else {
return 0;
}
const res = getSellTransactionGain(stock, shares, pos);
if (res == null) { return 0; }
return res;
},
buyStock: function(symbol, shares) {
updateDynamicRam("buyStock", getRamCost("buyStock"));
checkTixApiAccess("buyStock");