/// <summary> /// Get a Coin from a transaction /// </summary> /// <param name="transaction">New Transaction object</param> /// <returns>CoinInformation object</returns> private CoinInformation GetCoin(Contracts.CryptoBits.NewTransaction transaction) { CoinInformation thisCoin = this.coinInfoList.Where(c => c.symbol == transaction.symbol).FirstOrDefault(); if (thisCoin == null) { thisCoin = this.CreateCoin(transaction); } else { Wallet wallet = GetWallet(transaction, thisCoin); if (wallet == null && transaction.transactionType == TransactionType.BUY) { var buyList = CreateCoinBuyList(transaction); var newWallet = this.CreateCoinWallet(transaction, buyList); } else if (transaction.transactionType == TransactionType.BUY) { var coinBuy = CreateCoinBuy(transaction); wallet.coinBuyList.Add(coinBuy); } else if (transaction.transactionType == TransactionType.SELL) { var buyList = wallet.coinBuyList; wallet.coinBuyList = SellCoins(buyList, transaction); } } return(thisCoin); }
/// <summary> /// Process a new transaction from the UI /// </summary> /// <param name="transaction">NewTransaction object to process</param> /// <param name="updateCoin">Update coin in database? (default = true)</param> /// <returns>boolean when complete</returns> public bool NewTransaction(Contracts.CryptoBits.NewTransaction transaction, bool updateCoin = true) { this.newTransaction = transaction; var newCoin = GetCoin(transaction); if (updateCoin) { UpdateCoinInformation(newCoin); } var foundCoin = this.coinInfoList.FirstOrDefault(c => c.symbol.Equals(newCoin.symbol)); if (foundCoin == null) { this.coinInfoList.Add(newCoin); } else { foundCoin.walletList = newCoin.walletList; } return(true); }