private IEnumerator CloseAllPositionsCoroutine() { float delay = 1.5f; List <string> ownedStocksSymbols = new List <string>(Portfolio.Keys); foreach (var symbol in ownedStocksSymbols) { yield return(new WaitForSeconds(delay)); int quantity = Portfolio[symbol]; if (quantity > 0) { MessageCentral.Instance.DisplayMessage("Message", "Selling remaining " + symbol); SellAll(market.GetStock(symbol)); } else { MessageCentral.Instance.DisplayMessage("Message", "Buying remaining shorted " + symbol); BuyAllShorted(market.GetStock(symbol)); } } yield return(new WaitForSeconds(delay)); OnAllPositionsClosed(); }
private float CalculateAssetsValue() { float assetsValue = 0; foreach (var asset in player.Portfolio) { var stockSymbol = asset.Key; // using absolute value because shorted quantities are negative var quantity = Math.Abs(asset.Value); assetsValue += market.GetStock(stockSymbol).CurrentPrice() * quantity; } return(assetsValue); }