Exemplo n.º 1
0
        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));
            }
        }
Exemplo n.º 2
0
        public async Task <BackendResponse <AccountChargeManuallyResponse> > ChargeManually([FromBody] AccountChargeManuallyRequest request)
        {
            if (string.IsNullOrEmpty(request?.Reason?.Trim()))
            {
                return(BackendResponse <AccountChargeManuallyResponse> .Error("Reason must be set."));
            }

            var account = _accountsCacheService.Get(request.ClientId, request.AccountId);

            try
            {
                var transactionId = await _accountManager.UpdateBalanceAsync(account, request.Amount,
                                                                             AccountHistoryType.Manual, request.Reason, auditLog : request.ToJson());

                _operationsLogService.AddLog("account charge manually", request.ClientId, request.AccountId,
                                             request.ToJson(), true.ToJson());

                return(BackendResponse <AccountChargeManuallyResponse> .Ok(
                           new AccountChargeManuallyResponse { TransactionId = transactionId }));
            }
            catch (Exception e)
            {
                await _log.WriteErrorAsync(nameof(AccountsBalanceController), "ChargeManually", request?.ToJson(), e);

                return(BackendResponse <AccountChargeManuallyResponse> .Error(e.Message));
            }
        }
Exemplo n.º 3
0
        public async Task <BackendResponse <AccountResetResponse> > AccountResetDemo([FromBody] AccounResetRequest request)
        {
            if (_marginSettings.IsLive)
            {
                return(BackendResponse <AccountResetResponse> .Error("Account reset is available only for DEMO accounts"));
            }

            var transactionId = await _accountManager.ResetAccountAsync(request.ClientId, request.AccountId);

            _operationsLogService.AddLog("account reset", request.ClientId, request.AccountId, request.ToJson(), true.ToJson());

            return(BackendResponse <AccountResetResponse> .Ok(
                       new AccountResetResponse { TransactionId = transactionId }));
        }
Exemplo n.º 4
0
        public async Task <BackendResponse <AccountAssetPairContract> > InsertOrUpdateAccountAsset([FromBody] AccountAssetPairContract model)
        {
            var assetPair = await _accountAssetsManager.AddOrReplaceAccountAssetAsync(Convert(model));

            return(BackendResponse <AccountAssetPairContract> .Ok(Convert(assetPair)));
        }