mirror of
https://github.com/bitburner-official/bitburner-src.git
synced 2024-11-09 17:23:53 +01:00
Re-added the getStockPurchaseCost() and getStockSaleGain() functions so we don't break user scripts
This commit is contained in:
parent
e5e3fec1a9
commit
0b4968d148
@ -22,6 +22,8 @@ access even after you 'reset' by installing Augmentations
|
||||
getStockBidPrice() <tixapi/getStockBidPrice>
|
||||
getStockPosition() <tixapi/getStockPosition>
|
||||
getStockMaxShares() <tixapi/getStockMaxShares>
|
||||
getStockPurchaseCost() <tixapi/getStockPurchaseCost>
|
||||
getStockSaleGain() <tixapi/getStockSaleGain>
|
||||
buyStock() <tixapi/buyStock>
|
||||
sellStock() <tixapi/sellStock>
|
||||
shortStock() <tixapi/shortStock>
|
||||
|
14
doc/source/netscript/tixapi/getStockPurchaseCost.rst
Normal file
14
doc/source/netscript/tixapi/getStockPurchaseCost.rst
Normal file
@ -0,0 +1,14 @@
|
||||
getStockPurchaseCost() Netscript Function
|
||||
=========================================
|
||||
|
||||
.. js:function:: getStockPurchaseCost(sym, shares, posType)
|
||||
|
||||
:param string sym: Stock symbol
|
||||
:param number shares: Number of shares to purchase
|
||||
:param string posType: Specifies whether the order is a "Long" or "Short" position.
|
||||
The values "L" or "S" can also be used.
|
||||
:RAM cost: 2 GB
|
||||
|
||||
Calculates and returns how much it would cost to buy a given number of
|
||||
shares of a stock. This takes into account :ref:`spread <gameplay_stock_market_spread>`
|
||||
and commission fees.
|
14
doc/source/netscript/tixapi/getStockSaleGain.rst
Normal file
14
doc/source/netscript/tixapi/getStockSaleGain.rst
Normal file
@ -0,0 +1,14 @@
|
||||
getStockSaleGain() Netscript Function
|
||||
=====================================
|
||||
|
||||
.. js:function:: getStockSaleGain(sym, shares, posType)
|
||||
|
||||
:param string sym: Stock symbol
|
||||
:param number shares: Number of shares to sell
|
||||
:param string posType: Specifies whether the order is a "Long" or "Short" position.
|
||||
The values "L" or "S" can also be used.
|
||||
:RAM cost: 2 GB
|
||||
|
||||
Calculates and returns how much you would gain from selling a given number of
|
||||
shares of a stock. This takes into account :ref:`spread <gameplay_stock_market_spread>`
|
||||
and commission fees.
|
@ -224,10 +224,10 @@ export let CONSTANTS: IMap<any> = {
|
||||
v0.47.0
|
||||
* Stock Market changes:
|
||||
** Transactions no longer influence stock prices (but they still influence forecast)
|
||||
** Removed getStockPurchaseCost() and getStockSaleGain() Netscript functions
|
||||
**
|
||||
|
||||
* Scripts now start/stop instantly
|
||||
* Improved performance when starting up many copies of a new script (by Ornedan)
|
||||
* Dialog boxes can now be closed with the ESC key (by jaguilar)
|
||||
|
||||
v0.47.0
|
||||
* Stock Market changes:
|
||||
|
@ -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");
|
||||
|
@ -203,6 +203,9 @@ export function stockMarketCycle() {
|
||||
} else if (roll < 0.8) {
|
||||
stock.otlkMagForecast -= 0.5;
|
||||
stock.otlkMagForecast = stock.otlkMagForecast * (1 / 1.02);
|
||||
} else if (roll < 0.9) {
|
||||
stock.b = !stock.b;
|
||||
stock.flipForecastForecast();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user