private void AddPurchased(Cryptos crypto, KeyValuePair <string, BaseStockExchange> platformConfig, Balance platformBalance) { var platform = platformConfig.Value; var platformOrderHistory = platform.GetLastBuyOrdersByCurrencies(new string[] { platformBalance.Currency }); if (platformOrderHistory.Any()) { var order = platformOrderHistory.ElementAt(0); PurchasedCryptos purchased = new PurchasedCryptos() { Currency = crypto.Currency, Platform = platformConfig.Key, Amount = order.Amount, CurrentUnitPrice = Math.Round(platform.GetTickerByPair(crypto.Currency + platform.Config.PlatformCurrency), 6), SpentValue = Math.Round(order.Price * order.Amount, 6) }; if (purchased.SpentValue != 0) { purchased.CurrentValue = purchased.Amount * purchased.CurrentUnitPrice; purchased.PurchasedUnitPrice = Math.Round(purchased.SpentValue / order.Amount, 6); purchased.ProfitValue = Math.Round(crypto.CurrentValue - purchased.SpentValue, 6); purchased.ProfitPercentage = Math.Round(purchased.ProfitValue / purchased.SpentValue, 6); crypto.Purchaseds.Add(purchased); } } }
private PurchasedCryptos CreateTotalPurchased(string platform, decimal currentValue, decimal spentValue) { var totalCryptoPurchased = new PurchasedCryptos() { Platform = platform, CurrentValue = Math.Round(currentValue, 6), SpentValue = Math.Round(spentValue, 6) }; totalCryptoPurchased.ProfitValue = Math.Round(totalCryptoPurchased.CurrentValue - totalCryptoPurchased.SpentValue, 6); if (totalCryptoPurchased.SpentValue > 0) { totalCryptoPurchased.ProfitPercentage = Math.Round((totalCryptoPurchased.ProfitValue / totalCryptoPurchased.SpentValue) * 100, 6); } return(totalCryptoPurchased); }