public async Task <bool> WithdrawFromAccount(string clientId, string accountId, double amount, MarginPaymentType paymentType) { var request = new AccountDepositWithdrawRequest { AccountId = accountId, ClientId = clientId, Amount = amount, PaymentType = paymentType.ConvertToDto() }; var result = await Api.ApiBackofficeMarginTradingAccountsWithdrawPostWithHttpMessagesAsync(_settings.ApiKey, request); return(result.Body == true); }
public async Task <BackendResponse <AccountDepositWithdrawResponse> > AccountWithdraw([FromBody] AccountDepositWithdrawRequest request) { var account = _accountsCacheService.Get(request.ClientId, request.AccountId); var freeMargin = account.GetFreeMargin(); if (freeMargin < Math.Abs(request.Amount)) { return(BackendResponse <AccountDepositWithdrawResponse> .Error( "Requested withdrawal amount is less than free margin")); } var changeTransferLimit = _marginSettings.IsLive && request.PaymentType == PaymentType.Transfer && !IsCrypto(account.BaseAssetId); try { var transactionId = await _accountManager.UpdateBalanceAsync(account, -Math.Abs(request.Amount), AccountHistoryType.Withdraw, "Account withdraw", null, changeTransferLimit); _operationsLogService.AddLog($"account withdraw {request.PaymentType}", request.ClientId, request.AccountId, request.ToJson(), true.ToJson()); return(BackendResponse <AccountDepositWithdrawResponse> .Ok( new AccountDepositWithdrawResponse { TransactionId = transactionId })); } catch (Exception e) { await _log.WriteErrorAsync(nameof(AccountsBalanceController), "AccountWithdraw", request?.ToJson(), e); return(BackendResponse <AccountDepositWithdrawResponse> .Error(e.Message)); } }
public async Task <bool> AccountWithdrawOld([FromBody] AccountDepositWithdrawRequest request) { return((await AccountWithdraw(request)).IsOk); }