public Account WithDrawlReqAdmin(Payment payment) { var wallet = _db.Wallets.Where(m => m.Account_Id == payment.Account_Id && m.Currency == payment.Currency).ToList(); if (wallet.Count > 0) { if (wallet.Select(x => x.Balance).FirstOrDefault().GetValueOrDefault() < payment.Amount.GetValueOrDefault()) { ExchangeException.Throw(ErrorCode.INSUFFICIANT_BALANCE, null); } } else { ExchangeException.Throw(ErrorCode.INSUFFICIANT_BALANCE, null); } Payment p = new Payment() { Account_Id = payment.Account_Id, Amount = payment.Amount, AmountSent = Convert.ToDecimal(payment.Amount), Currency = payment.Currency, Fee = payment.Fee, ToWalletAddress = payment.ToWalletAddress, TransectionId = "", PaymentType = "WITHDRAW", PaymentDate = DateTime.UtcNow, PaymentStatus_Id = (int)1, StatusMessage = "Withdrawal Requested", Source = "CRYPTO" }; //_db.Payments.Add(p); _db.Notifications.Add(new Notification() { IsViewed = false, NotificationDetails = "Crypto Withdraw is Requested", NotificationHeading = "Withdraw Request", RedirectAction = "WithDrawals", RedirectController = "Admin", NotificationType = "Desktop Notification" }); //wallet.FirstOrDefault().Balance -= payment.Amount.Value; _db.Configuration.ValidateOnSaveEnabled = false; _db.SaveChanges(); try { string _email = _db.Accounts.Where(x => x.AccountId == payment.Account_Id).Select(x => x.Email).FirstOrDefault(); SMTPMailClient.SendRawEmail("clientservice @nanopips.com", "Withdraw Request from " + _email + " of " + payment.Amount + " " + payment.Currency + " to address " + payment.ToWalletAddress + " has been made. Need approval !", "New Withdrawl Request"); SMTPMailClient.SendRawEmail(_email, "Thank you for contacting NanoPips. Please allow up to 24 hours for support to respond to your inquiry. ", "New Withdrawal Request"); } catch (Exception ex) { ExchangeException.Throw(ex.Message); } return(_db.Accounts.Find(payment.Account_Id)); }
public Account WireWithDrawlReqAdmin(Payment payment) { var wallet = _db.Wallets.Where(m => m.Account_Id == payment.Account_Id && m.Currency == payment.Currency).ToList(); if (wallet.Count > 0) { if (wallet.Select(x => x.Balance).FirstOrDefault().GetValueOrDefault() < payment.FiatAmount.GetValueOrDefault()) { ExchangeException.Throw(ErrorCode.INSUFFICIANT_BALANCE, null); } } else { ExchangeException.Throw(ErrorCode.INSUFFICIANT_BALANCE, null); } //_db.Payments.Add(payment); _db.Notifications.Add(new Notification() { IsViewed = false, NotificationDetails = "Fiat Withdraw is Requested", NotificationHeading = "Withdraw Request", RedirectAction = "WithDrawals", RedirectController = "Admin", NotificationType = "Desktop Notification" }); //wallet.FirstOrDefault().Balance -= payment.FiatAmount.Value; _db.Configuration.ValidateOnSaveEnabled = false; _db.SaveChanges(); try { string _email = _db.Accounts.Where(x => x.AccountId == payment.Account_Id).Select(x => x.Email).FirstOrDefault(); SMTPMailClient.SendRawEmail("clientservice @nanopips.com", "Withdraw Request from " + _email + " <br/> " + "Amount: " + payment.FiatAmount + " " + payment.Currency + " <br/> " + "Date: " + payment.PaymentDate + " <br/> " + "BankName: " + payment.BankName + " <br/> " + "ABA Routing #, IBN #,SWIFT Code: " + payment.IBAN + " <br/> " + "Address: " + payment.BankAddress + " <br/> " + "Full Name: " + payment.BankAccountTitle + " <br/> " + "Account Number: " + payment.BankAccountNumber + " <br/> " + ((payment.Reason != null) ? ("Reason: " + payment.Reason + "<br/>") : " <br/> "), "New Withdrawal Request"); SMTPMailClient.SendRawEmail(_email, "Thank you for contacting NanoPips. Please allow up to 24 hours for support to respond to your inquiry. ", "New Withdrawal Request"); } catch (Exception ex) { ExchangeException.Throw(ex.Message); } return(_db.Accounts.Find(payment.Account_Id)); }
public string Buy(long acId, string pair, decimal rate, decimal amount, int type, int expiretime, decimal timeOffset) { var ac = _db.Accounts.First(m => m.AccountId == acId); var firstSym = pair.Split('-')[0]; var secondSym = pair.Split('-')[1]; amount = Math.Abs(amount); var mFactor = 100; var tradeAmount = _db.Trades.Where(x => x.Account_Id == acId && x.Status == "PENDING" && x.Symbol == pair).ToList().Sum(t => t.Amount); //var creditAmount = _db.Payments.Where(x => x.Account_Id == acId && x.PaymentType == "DEPOSIT").ToList().Sum(y => y.Amount); var creditAmount = _db.Payments.Where(x => x.Account_Id == acId && x.PaymentType == "DEPOSIT").ToList().LastOrDefault(); var dbWallet = _db.Wallets.Where(m => m.Account_Id == acId && m.Currency == "USD").ToList(); if (dbWallet.Count == 0) { return("Your wallet balance is too low to make this trade, Please deposit funds, or place a smaller trade"); } else if ((dbWallet.First().Balance) <= 10) { return("Not Enough Margin"); } else if (dbWallet.First().Balance < amount) { return("Not Enough Margin"); } //else if ((dbWallet.First().Balance + totalAmount) < ((amount + totalAmount)*500)) //{ // return "Your wallet balance is too low to make this trade, please deposit funds, or place a smaller trade"; //} else if (creditAmount.Amount < ((amount / mFactor) * 500)) { return("Your wallet balance is too low to make this trade, please deposit funds, or place a smaller trade"); } dbWallet.First().Balance -= (amount); try { var bn = DateTime.UtcNow.AddHours(-1 * (double)(timeOffset / 60)); _db.Trades.Add(new Trade() { TradeType = (type == 1) ? "MARKET" : "LIMIT", TradeDate = DateTime.UtcNow, TradeTypeValue = type, Currency = firstSym, Symbol = pair, Amount = (amount / mFactor), Rate = rate, Value = mFactor, Fee = 0, //StopLoss_TakeProfitEn = true, //UpLimitValue = rate + ((rate * 70) / 100), //DownLimitValue = rate - ((rate * 70) / 100), expiryTime = expiretime, Account_Id = acId, Wallet_Id = dbWallet.FirstOrDefault().WalletId, Direction = "BUY", Status = (type == 1) ? "COMPLETED" : "PENDING" }); _db.Configuration.ValidateOnSaveEnabled = false; _db.SaveChanges(); return(""); } catch (ExchangeException ex) { ExchangeException.Throw(ex.ErrorMessage); } catch (Exception ex) { ExchangeException.Throw(ErrorCode.INSUFFICIANT_LIQUIDITY__PLEASE_CONTACT_SUPPORT, ex); } return(null); }