public static void ProccessProfit(bool isTestAccount) { EscrowOperations escrow = new EscrowOperations(isTestAccount); //Get total amount in escrow account. decimal totalMoneyInEscrowBitCoinAcount = escrow.GetAmountInEscrowAccount(); //minimum buffer to hold above the escrow's debt decimal minDebtBuffer = Decimal.Parse(ConfigurationManager.AppSettings["minDebtBuffer"]); //minimum profit to take decimal minProfitTransaction = Decimal.Parse(ConfigurationManager.AppSettings["minProfitTransaction"]); var openAccounts = escrow.GetOpenAccounts(); Console.WriteLine("{0} open accounts", openAccounts); //Sum up all money owed. decimal amountHeldInEscrow = openAccounts.Sum(account => escrow.GetAccountBalance(account.EscrowAccountAddress)); //Total profit decimal totalProfit = totalMoneyInEscrowBitCoinAcount - amountHeldInEscrow; var logMessage = String.Format("Finished processing accounts the account: IsTestAccount: {0} has total balance {1} owed {2} profit {3}", isTestAccount, totalMoneyInEscrowBitCoinAcount, amountHeldInEscrow, totalProfit); Logger log = LogManager.GetCurrentClassLogger(); log.Info(logMessage); totalProfit -= minDebtBuffer; if (totalProfit > minProfitTransaction) { escrow.SendBitCoinsToAddress(escrow.HouseAddress, totalProfit); } }