Refactored stock buying/selling code into its own file. Refactored WorkerScript & NetscriptEnvironment into their own Typescript classes. Refactored a ton of code to remove circular dependencies

This commit is contained in:
danielyxie
2019-05-04 21:03:40 -07:00
parent 585e1ac7aa
commit 8a5b6f6cbc
47 changed files with 2867 additions and 2773 deletions
+16 -1
View File
@@ -22,11 +22,26 @@ export class Order {
readonly pos: PositionTypes;
readonly price: number;
readonly shares: number;
shares: number;
readonly stock: Stock;
readonly type: OrderTypes;
constructor(stk: Stock = new Stock(), shares: number=0, price: number=0, typ: OrderTypes=OrderTypes.LimitBuy, pos: PositionTypes=PositionTypes.Long) {
// Validate arguments
let invalidArgs: boolean = false;
if (typeof shares !== "number" || typeof price !== "number") {
invalidArgs = true;
}
if (isNaN(shares) || isNaN(price)) {
invalidArgs = true;
}
if (!(stk instanceof Stock)) {
invalidArgs = true;
}
if (invalidArgs) {
throw new Error(`Invalid constructor paramters for Order`);
}
this.stock = stk;
this.shares = shares;
this.price = price;