internal bool sell(int amount) { if (amount > numOwn) { amount = numOwn; } if (amount <= 0) { return(false); } int c = StockCompanyModule.calcCommition(currentPriceU, amount); long v = amount * currentPriceU - c; manager.earn(v, AccountGenre.OTHERS); int prev = averageBoughtPriceU; _numOwn -= amount; _numInMarket += amount; bool r = (_numOwn == 0); // lower the price according to the bought amount currentPriceU -= _currentPriceU * amount / numTotal; moneySpend = prev * _numOwn; return(r); }
internal bool buy(int amount) { if (amount > numInMarket) { amount = numInMarket; } if (amount <= 0) { return(false); } int c = StockCompanyModule.calcCommition(currentPriceU, amount); long v = amount * currentPriceU + c; manager.spend(v, AccountGenre.OTHERS); bool r = (_numOwn == 0); moneySpend += v; _numOwn += amount; _numInMarket -= amount; // raise the price according to the bought amount currentPriceU += _currentPriceU * amount / numTotal; return(r); }