2019-05-05 06:03:40 +02:00
|
|
|
/**
|
|
|
|
* Functions for buying/selling stocks. There are four functions total, two for
|
|
|
|
* long positions and two for short positions.
|
|
|
|
*/
|
|
|
|
import { Stock } from "./Stock";
|
|
|
|
import {
|
2021-09-05 01:09:30 +02:00
|
|
|
getBuyTransactionCost,
|
|
|
|
getSellTransactionGain,
|
|
|
|
processTransactionForecastMovement,
|
2019-05-05 06:03:40 +02:00
|
|
|
} from "./StockMarketHelpers";
|
|
|
|
|
2023-06-12 06:34:20 +02:00
|
|
|
import { PositionType } from "@enums";
|
2019-05-05 06:03:40 +02:00
|
|
|
|
2023-08-01 04:12:49 +02:00
|
|
|
import { StockMarketConstants } from "./data/Constants";
|
2022-10-10 00:42:14 +02:00
|
|
|
import { Player } from "@player";
|
2019-05-05 06:03:40 +02:00
|
|
|
|
2023-02-11 19:18:50 +01:00
|
|
|
import { formatMoney, formatShares } from "../ui/formatNumber";
|
2021-03-31 06:45:21 +02:00
|
|
|
import { Money } from "../ui/React/Money";
|
2019-05-05 06:03:40 +02:00
|
|
|
|
2021-09-25 20:42:57 +02:00
|
|
|
import { dialogBoxCreate } from "../ui/React/DialogBox";
|
2019-05-05 06:03:40 +02:00
|
|
|
|
2021-03-31 06:45:21 +02:00
|
|
|
import * as React from "react";
|
2022-08-20 01:32:30 +02:00
|
|
|
import { NetscriptContext } from "../Netscript/APIWrapper";
|
|
|
|
import { helpers } from "../Netscript/NetscriptHelpers";
|
2021-03-31 06:45:21 +02:00
|
|
|
|
2022-10-04 12:40:10 +02:00
|
|
|
/** Each function takes an optional config object as its last argument */
|
2019-05-05 06:03:40 +02:00
|
|
|
interface IOptions {
|
2021-09-05 01:09:30 +02:00
|
|
|
rerenderFn?: () => void;
|
|
|
|
suppressDialog?: boolean;
|
2019-05-05 06:03:40 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Attempt to buy a stock in the long position
|
|
|
|
* @param {Stock} stock - Stock to buy
|
|
|
|
* @param {number} shares - Number of shares to buy
|
2022-08-20 01:32:30 +02:00
|
|
|
* @param {NetscriptContext} ctx - If this is being called through Netscript
|
2019-05-05 06:03:40 +02:00
|
|
|
* @param opts - Optional configuration for this function's behavior. See top of file
|
|
|
|
* @returns {boolean} - true if successful, false otherwise
|
|
|
|
*/
|
2021-09-05 01:09:30 +02:00
|
|
|
export function buyStock(
|
|
|
|
stock: Stock,
|
|
|
|
shares: number,
|
2022-08-20 01:32:30 +02:00
|
|
|
ctx: NetscriptContext | null = null,
|
2021-09-05 01:09:30 +02:00
|
|
|
opts: IOptions = {},
|
|
|
|
): boolean {
|
|
|
|
// Validate arguments
|
|
|
|
shares = Math.round(shares);
|
|
|
|
if (shares <= 0) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if (stock == null || isNaN(shares)) {
|
2022-08-20 01:32:30 +02:00
|
|
|
if (ctx) {
|
|
|
|
helpers.log(ctx, () => `Invalid arguments: stock='${stock}' shares='${shares}'`);
|
2021-09-05 01:09:30 +02:00
|
|
|
} else if (opts.suppressDialog !== true) {
|
2021-09-09 05:47:34 +02:00
|
|
|
dialogBoxCreate("Failed to buy stock. This may be a bug, contact developer");
|
2019-05-05 06:03:40 +02:00
|
|
|
}
|
|
|
|
|
2021-09-05 01:09:30 +02:00
|
|
|
return false;
|
|
|
|
}
|
2019-05-05 06:03:40 +02:00
|
|
|
|
2021-09-05 01:09:30 +02:00
|
|
|
// Does player have enough money?
|
2023-06-12 06:34:20 +02:00
|
|
|
const totalPrice = getBuyTransactionCost(stock, shares, PositionType.Long);
|
2021-09-05 01:09:30 +02:00
|
|
|
if (totalPrice == null) {
|
|
|
|
return false;
|
|
|
|
}
|
2021-11-12 02:42:19 +01:00
|
|
|
if (Player.money < totalPrice) {
|
2022-08-20 01:32:30 +02:00
|
|
|
if (ctx) {
|
|
|
|
helpers.log(
|
|
|
|
ctx,
|
2023-02-11 19:18:50 +01:00
|
|
|
() => `You do not have enough money to purchase this position. You need ${formatMoney(totalPrice)}.`,
|
2021-09-05 01:09:30 +02:00
|
|
|
);
|
|
|
|
} else if (opts.suppressDialog !== true) {
|
|
|
|
dialogBoxCreate(
|
|
|
|
<>
|
2021-09-09 05:47:34 +02:00
|
|
|
You do not have enough money to purchase this. You need <Money money={totalPrice} />
|
2021-09-05 01:09:30 +02:00
|
|
|
</>,
|
|
|
|
);
|
2019-05-05 06:03:40 +02:00
|
|
|
}
|
|
|
|
|
2021-09-05 01:09:30 +02:00
|
|
|
return false;
|
|
|
|
}
|
2019-05-05 06:03:40 +02:00
|
|
|
|
2021-09-05 01:09:30 +02:00
|
|
|
// Would this purchase exceed the maximum number of shares?
|
|
|
|
if (shares + stock.playerShares + stock.playerShortShares > stock.maxShares) {
|
2022-08-20 01:32:30 +02:00
|
|
|
if (ctx) {
|
|
|
|
helpers.log(
|
|
|
|
ctx,
|
2021-11-27 00:30:58 +01:00
|
|
|
() =>
|
|
|
|
`Purchasing '${shares + stock.playerShares + stock.playerShortShares}' shares would exceed ${
|
|
|
|
stock.symbol
|
|
|
|
}'s maximum (${stock.maxShares}) number of shares`,
|
2021-09-05 01:09:30 +02:00
|
|
|
);
|
2019-05-07 03:01:06 +02:00
|
|
|
} else if (opts.suppressDialog !== true) {
|
2021-09-05 01:09:30 +02:00
|
|
|
dialogBoxCreate(
|
2023-02-11 19:18:50 +01:00
|
|
|
`You cannot purchase this many shares. ${stock.symbol} has a maximum of ${formatShares(
|
2021-09-05 01:09:30 +02:00
|
|
|
stock.maxShares,
|
|
|
|
)} shares.`,
|
|
|
|
);
|
2019-05-05 06:03:40 +02:00
|
|
|
}
|
|
|
|
|
2021-09-05 01:09:30 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
const origTotal = stock.playerShares * stock.playerAvgPx;
|
2021-10-27 20:18:33 +02:00
|
|
|
Player.loseMoney(totalPrice, "stock");
|
2023-08-01 04:12:49 +02:00
|
|
|
const newTotal = origTotal + totalPrice - StockMarketConstants.StockMarketCommission;
|
2021-09-05 01:09:30 +02:00
|
|
|
stock.playerShares = Math.round(stock.playerShares + shares);
|
|
|
|
stock.playerAvgPx = newTotal / stock.playerShares;
|
|
|
|
processTransactionForecastMovement(stock, shares);
|
|
|
|
if (opts.rerenderFn != null && typeof opts.rerenderFn === "function") {
|
|
|
|
opts.rerenderFn();
|
|
|
|
}
|
|
|
|
|
2022-08-20 01:32:30 +02:00
|
|
|
if (ctx) {
|
2023-02-11 19:18:50 +01:00
|
|
|
const resultTxt = `Bought ${formatShares(shares)} shares of ${stock.symbol} for ${formatMoney(
|
|
|
|
totalPrice,
|
2023-08-01 04:12:49 +02:00
|
|
|
)}. Paid ${formatMoney(StockMarketConstants.StockMarketCommission)} in commission fees.`;
|
2022-08-20 01:32:30 +02:00
|
|
|
helpers.log(ctx, () => resultTxt);
|
2021-09-05 01:09:30 +02:00
|
|
|
} else if (opts.suppressDialog !== true) {
|
|
|
|
dialogBoxCreate(
|
|
|
|
<>
|
2023-02-11 19:18:50 +01:00
|
|
|
Bought {formatShares(shares)} shares of {stock.symbol} for <Money money={totalPrice} />. Paid{" "}
|
2023-08-01 04:12:49 +02:00
|
|
|
<Money money={StockMarketConstants.StockMarketCommission} /> in commission fees.
|
2021-09-05 01:09:30 +02:00
|
|
|
</>,
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
2019-05-05 06:03:40 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Attempt to sell a stock in the long position
|
|
|
|
* @param {Stock} stock - Stock to sell
|
|
|
|
* @param {number} shares - Number of shares to sell
|
2022-08-20 01:32:30 +02:00
|
|
|
* @param {NetscriptContext} ctx - If this is being called through Netscript
|
2019-05-05 06:03:40 +02:00
|
|
|
* @param opts - Optional configuration for this function's behavior. See top of file
|
|
|
|
* returns {boolean} - true if successfully sells given number of shares OR MAX owned, false otherwise
|
|
|
|
*/
|
2021-09-05 01:09:30 +02:00
|
|
|
export function sellStock(
|
|
|
|
stock: Stock,
|
|
|
|
shares: number,
|
2022-08-20 01:32:30 +02:00
|
|
|
ctx: NetscriptContext | null = null,
|
2021-09-05 01:09:30 +02:00
|
|
|
opts: IOptions = {},
|
|
|
|
): boolean {
|
|
|
|
// Sanitize/Validate arguments
|
|
|
|
if (stock == null || shares < 0 || isNaN(shares)) {
|
2022-08-20 01:32:30 +02:00
|
|
|
if (ctx) {
|
|
|
|
helpers.log(ctx, () => `Invalid arguments: stock='${stock}' shares='${shares}'`);
|
2021-09-05 01:09:30 +02:00
|
|
|
} else if (opts.suppressDialog !== true) {
|
|
|
|
dialogBoxCreate(
|
|
|
|
"Failed to sell stock. This is probably due to an invalid quantity. Otherwise, this may be a bug, contact developer",
|
|
|
|
);
|
2019-05-05 06:03:40 +02:00
|
|
|
}
|
|
|
|
|
2021-09-05 01:09:30 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
shares = Math.round(shares);
|
|
|
|
if (shares > stock.playerShares) {
|
|
|
|
shares = stock.playerShares;
|
|
|
|
}
|
|
|
|
if (shares === 0) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2023-06-12 06:34:20 +02:00
|
|
|
const gains = getSellTransactionGain(stock, shares, PositionType.Long);
|
2021-09-05 01:09:30 +02:00
|
|
|
if (gains == null) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
let netProfit = gains - stock.playerAvgPx * shares;
|
|
|
|
if (isNaN(netProfit)) {
|
|
|
|
netProfit = 0;
|
|
|
|
}
|
2021-10-27 20:18:33 +02:00
|
|
|
Player.gainMoney(gains, "stock");
|
2022-08-20 01:32:30 +02:00
|
|
|
if (ctx) {
|
|
|
|
ctx.workerScript.scriptRef.onlineMoneyMade += netProfit;
|
2021-09-05 01:09:30 +02:00
|
|
|
Player.scriptProdSinceLastAug += netProfit;
|
|
|
|
}
|
|
|
|
|
|
|
|
stock.playerShares = Math.round(stock.playerShares - shares);
|
|
|
|
if (stock.playerShares === 0) {
|
|
|
|
stock.playerAvgPx = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
processTransactionForecastMovement(stock, shares);
|
|
|
|
|
|
|
|
if (opts.rerenderFn != null && typeof opts.rerenderFn === "function") {
|
|
|
|
opts.rerenderFn();
|
|
|
|
}
|
|
|
|
|
2022-08-20 01:32:30 +02:00
|
|
|
if (ctx) {
|
2021-09-05 01:09:30 +02:00
|
|
|
const resultTxt =
|
2023-02-11 19:18:50 +01:00
|
|
|
`Sold ${formatShares(shares)} shares of ${stock.symbol}. ` +
|
|
|
|
`After commissions, you gained a total of ${formatMoney(gains)}.`;
|
2022-08-20 01:32:30 +02:00
|
|
|
helpers.log(ctx, () => resultTxt);
|
2021-09-05 01:09:30 +02:00
|
|
|
} else if (opts.suppressDialog !== true) {
|
|
|
|
dialogBoxCreate(
|
|
|
|
<>
|
2023-02-11 19:18:50 +01:00
|
|
|
Sold {formatShares(shares)} shares of {stock.symbol}. After commissions, you gained a total of{" "}
|
2021-09-09 05:47:34 +02:00
|
|
|
<Money money={gains} />.
|
2021-09-05 01:09:30 +02:00
|
|
|
</>,
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
2019-05-05 06:03:40 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Attempt to buy a stock in the short position
|
|
|
|
* @param {Stock} stock - Stock to sell
|
|
|
|
* @param {number} shares - Number of shares to short
|
2022-08-20 01:32:30 +02:00
|
|
|
* @param {NetscriptContext} ctx - If this is being called through Netscript
|
2019-05-05 06:03:40 +02:00
|
|
|
* @param opts - Optional configuration for this function's behavior. See top of file
|
|
|
|
* @returns {boolean} - true if successful, false otherwise
|
|
|
|
*/
|
2021-09-05 01:09:30 +02:00
|
|
|
export function shortStock(
|
|
|
|
stock: Stock,
|
|
|
|
shares: number,
|
2022-08-20 01:32:30 +02:00
|
|
|
ctx: NetscriptContext | null = null,
|
2021-09-05 01:09:30 +02:00
|
|
|
opts: IOptions = {},
|
|
|
|
): boolean {
|
|
|
|
// Validate arguments
|
|
|
|
shares = Math.round(shares);
|
|
|
|
if (shares <= 0) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if (stock == null || isNaN(shares)) {
|
2022-08-20 01:32:30 +02:00
|
|
|
if (ctx) {
|
|
|
|
helpers.log(ctx, () => `Invalid arguments: stock='${stock}' shares='${shares}'`);
|
2021-09-05 01:09:30 +02:00
|
|
|
} else if (opts.suppressDialog !== true) {
|
|
|
|
dialogBoxCreate(
|
|
|
|
"Failed to initiate a short position in a stock. This is probably " +
|
|
|
|
"due to an invalid quantity. Otherwise, this may be a bug, so contact developer",
|
|
|
|
);
|
2019-05-05 06:03:40 +02:00
|
|
|
}
|
2021-09-05 01:09:30 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Does the player have enough money?
|
2023-06-12 06:34:20 +02:00
|
|
|
const totalPrice = getBuyTransactionCost(stock, shares, PositionType.Short);
|
2021-09-05 01:09:30 +02:00
|
|
|
if (totalPrice == null) {
|
|
|
|
return false;
|
|
|
|
}
|
2021-11-12 02:42:19 +01:00
|
|
|
if (Player.money < totalPrice) {
|
2022-08-20 01:32:30 +02:00
|
|
|
if (ctx) {
|
|
|
|
helpers.log(
|
|
|
|
ctx,
|
2023-02-11 19:18:50 +01:00
|
|
|
() => "You do not have enough " + "money to purchase this short position. You need " + formatMoney(totalPrice),
|
2021-09-05 01:09:30 +02:00
|
|
|
);
|
|
|
|
} else if (opts.suppressDialog !== true) {
|
|
|
|
dialogBoxCreate(
|
|
|
|
<>
|
2021-09-09 05:47:34 +02:00
|
|
|
You do not have enough money to purchase this short position. You need <Money money={totalPrice} />
|
2021-09-05 01:09:30 +02:00
|
|
|
</>,
|
|
|
|
);
|
2019-05-05 06:03:40 +02:00
|
|
|
}
|
|
|
|
|
2021-09-05 01:09:30 +02:00
|
|
|
return false;
|
|
|
|
}
|
2019-05-05 06:03:40 +02:00
|
|
|
|
2021-09-05 01:09:30 +02:00
|
|
|
// Would this purchase exceed the maximum number of shares?
|
|
|
|
if (shares + stock.playerShares + stock.playerShortShares > stock.maxShares) {
|
2022-08-20 01:32:30 +02:00
|
|
|
if (ctx) {
|
|
|
|
helpers.log(
|
|
|
|
ctx,
|
2021-11-27 00:30:58 +01:00
|
|
|
() =>
|
|
|
|
`This '${shares + stock.playerShares + stock.playerShortShares}' short shares would exceed ${
|
|
|
|
stock.symbol
|
|
|
|
}'s maximum (${stock.maxShares}) number of shares.`,
|
2021-09-05 01:09:30 +02:00
|
|
|
);
|
|
|
|
} else if (opts.suppressDialog !== true) {
|
|
|
|
dialogBoxCreate(
|
|
|
|
`You cannot purchase this many shares. ${stock.symbol} has a maximum of ${stock.maxShares} shares.`,
|
|
|
|
);
|
2019-05-05 06:03:40 +02:00
|
|
|
}
|
|
|
|
|
2021-09-05 01:09:30 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
const origTotal = stock.playerShortShares * stock.playerAvgShortPx;
|
2021-10-27 20:18:33 +02:00
|
|
|
Player.loseMoney(totalPrice, "stock");
|
2023-08-01 04:12:49 +02:00
|
|
|
const newTotal = origTotal + totalPrice - StockMarketConstants.StockMarketCommission;
|
2021-09-05 01:09:30 +02:00
|
|
|
stock.playerShortShares = Math.round(stock.playerShortShares + shares);
|
|
|
|
stock.playerAvgShortPx = newTotal / stock.playerShortShares;
|
|
|
|
processTransactionForecastMovement(stock, shares);
|
|
|
|
|
|
|
|
if (opts.rerenderFn != null && typeof opts.rerenderFn === "function") {
|
|
|
|
opts.rerenderFn();
|
|
|
|
}
|
|
|
|
|
2022-08-20 01:32:30 +02:00
|
|
|
if (ctx) {
|
2021-09-05 01:09:30 +02:00
|
|
|
const resultTxt =
|
2023-02-11 19:18:50 +01:00
|
|
|
`Bought a short position of ${formatShares(shares)} shares of ${stock.symbol} ` +
|
2023-08-01 04:12:49 +02:00
|
|
|
`for ${formatMoney(totalPrice)}. Paid ${formatMoney(StockMarketConstants.StockMarketCommission)} ` +
|
2021-09-05 01:09:30 +02:00
|
|
|
`in commission fees.`;
|
2022-08-20 01:32:30 +02:00
|
|
|
helpers.log(ctx, () => resultTxt);
|
2021-09-05 01:09:30 +02:00
|
|
|
} else if (!opts.suppressDialog) {
|
|
|
|
dialogBoxCreate(
|
|
|
|
<>
|
2023-02-11 19:18:50 +01:00
|
|
|
Bought a short position of {formatShares(shares)} shares of {stock.symbol} for <Money money={totalPrice} />.
|
2023-08-01 04:12:49 +02:00
|
|
|
Paid <Money money={StockMarketConstants.StockMarketCommission} /> in commission fees.
|
2021-09-05 01:09:30 +02:00
|
|
|
</>,
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
2019-05-05 06:03:40 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Attempt to sell a stock in the short position
|
|
|
|
* @param {Stock} stock - Stock to sell
|
|
|
|
* @param {number} shares - Number of shares to sell
|
2022-08-20 01:32:30 +02:00
|
|
|
* @param {NetscriptContext} ctx - If this is being called through Netscript
|
2019-05-05 06:03:40 +02:00
|
|
|
* @param opts - Optional configuration for this function's behavior. See top of file
|
|
|
|
* @returns {boolean} true if successfully sells given amount OR max owned, false otherwise
|
|
|
|
*/
|
2021-09-05 01:09:30 +02:00
|
|
|
export function sellShort(
|
|
|
|
stock: Stock,
|
|
|
|
shares: number,
|
2022-08-20 01:32:30 +02:00
|
|
|
ctx: NetscriptContext | null = null,
|
2021-09-05 01:09:30 +02:00
|
|
|
opts: IOptions = {},
|
|
|
|
): boolean {
|
|
|
|
if (stock == null || isNaN(shares) || shares < 0) {
|
2022-08-20 01:32:30 +02:00
|
|
|
if (ctx) {
|
|
|
|
helpers.log(ctx, () => `Invalid arguments: stock='${stock}' shares='${shares}'`);
|
2021-09-05 01:09:30 +02:00
|
|
|
} else if (!opts.suppressDialog) {
|
|
|
|
dialogBoxCreate(
|
|
|
|
"Failed to sell a short position in a stock. This is probably " +
|
|
|
|
"due to an invalid quantity. Otherwise, this may be a bug, so contact developer",
|
|
|
|
);
|
2019-05-05 06:03:40 +02:00
|
|
|
}
|
|
|
|
|
2021-09-05 01:09:30 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
shares = Math.round(shares);
|
|
|
|
if (shares > stock.playerShortShares) {
|
|
|
|
shares = stock.playerShortShares;
|
|
|
|
}
|
|
|
|
if (shares === 0) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
const origCost = shares * stock.playerAvgShortPx;
|
2023-06-12 06:34:20 +02:00
|
|
|
const totalGain = getSellTransactionGain(stock, shares, PositionType.Short);
|
2021-09-05 01:09:30 +02:00
|
|
|
if (totalGain == null || isNaN(totalGain) || origCost == null) {
|
2022-08-20 01:32:30 +02:00
|
|
|
if (ctx) {
|
|
|
|
helpers.log(
|
|
|
|
ctx,
|
2021-11-27 00:30:58 +01:00
|
|
|
() => `Failed to sell short position in a stock. This is probably either due to invalid arguments, or a bug`,
|
2021-09-05 01:09:30 +02:00
|
|
|
);
|
2019-05-05 06:03:40 +02:00
|
|
|
} else if (!opts.suppressDialog) {
|
2021-09-05 01:09:30 +02:00
|
|
|
dialogBoxCreate(
|
|
|
|
`Failed to sell short position in a stock. This is probably either due to invalid arguments, or a bug`,
|
|
|
|
);
|
2019-05-05 06:03:40 +02:00
|
|
|
}
|
|
|
|
|
2021-09-05 01:09:30 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
let profit = totalGain - origCost;
|
|
|
|
if (isNaN(profit)) {
|
|
|
|
profit = 0;
|
|
|
|
}
|
2021-10-27 20:18:33 +02:00
|
|
|
Player.gainMoney(totalGain, "stock");
|
2022-08-20 01:32:30 +02:00
|
|
|
if (ctx) {
|
|
|
|
ctx.workerScript.scriptRef.onlineMoneyMade += profit;
|
2021-09-05 01:09:30 +02:00
|
|
|
Player.scriptProdSinceLastAug += profit;
|
|
|
|
}
|
|
|
|
|
|
|
|
stock.playerShortShares = Math.round(stock.playerShortShares - shares);
|
|
|
|
if (stock.playerShortShares === 0) {
|
|
|
|
stock.playerAvgShortPx = 0;
|
|
|
|
}
|
|
|
|
processTransactionForecastMovement(stock, shares);
|
|
|
|
|
|
|
|
if (opts.rerenderFn != null && typeof opts.rerenderFn === "function") {
|
|
|
|
opts.rerenderFn();
|
|
|
|
}
|
|
|
|
|
2022-08-20 01:32:30 +02:00
|
|
|
if (ctx) {
|
2021-09-05 01:09:30 +02:00
|
|
|
const resultTxt =
|
2023-02-11 19:18:50 +01:00
|
|
|
`Sold your short position of ${formatShares(shares)} shares of ${stock.symbol}. ` +
|
|
|
|
`After commissions, you gained a total of ${formatMoney(totalGain)}`;
|
2022-08-20 01:32:30 +02:00
|
|
|
helpers.log(ctx, () => resultTxt);
|
2021-09-05 01:09:30 +02:00
|
|
|
} else if (!opts.suppressDialog) {
|
|
|
|
dialogBoxCreate(
|
|
|
|
<>
|
2023-02-11 19:18:50 +01:00
|
|
|
Sold your short position of {formatShares(shares)} shares of {stock.symbol}. After commissions, you gained a
|
|
|
|
total of <Money money={totalGain} />
|
2021-09-05 01:09:30 +02:00
|
|
|
</>,
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
2019-05-05 06:03:40 +02:00
|
|
|
}
|