Esempio n. 1
0
        public async Task DeleteAccountAsync(string clientId, string accountId)
        {
            var orders = _ordersCache.GetAll().Where(o => o.AccountId == accountId).ToArray();

            if (orders.Any())
            {
                throw new Exception(
                          $"Account [{accountId}] has not closed orders: [{orders.Select(o => $"{o.Id}:{o.Status.ToString()}").ToJson()}]");
            }

            var account = _accountsCacheService.Get(clientId, accountId);

            if (_marginSettings.IsLive && account.Balance > 0)
            {
                throw new Exception(
                          $"Account [{accountId}] balance is higher than zero: [{account.Balance}]");
            }

            await _clientAccountClient.DeleteWalletAsync(accountId);

            await _repository.DeleteAsync(clientId, accountId);

            await ProcessAccountsSetChange(clientId);

            await _rabbitMqNotifyService.AccountDeleted(account);
        }
Esempio n. 2
0
        public async Task <IActionResult> DeleteWallet(string id)
        {
            // checking if wallet exists and user owns the specified wallet
            var wallet = await GetClientWallet(id);

            if (wallet == null)
            {
                return(NotFound());
            }

            await _clientAccountService.DeleteWalletAsync(id);

            return(Ok());
        }
        public async Task <IActionResult> DeleteWallet(string id)
        {
            // checking if wallet exists and user owns the specified wallet
            var wallet = await GetClientWallet(id);

            if (wallet == null)
            {
                return(NotFound());
            }

            // todo: always delete wallet through ClientAccountService; HFT internal service should process deleted messages by itself
            var apiKey = (await _hftInternalService.GetKeysAsync(_requestContext.ClientId))?.FirstOrDefault(x => x.Wallet == id);

            if (apiKey != null)
            {
                await _hftInternalService.DeleteKeyAsync(apiKey.Key);
            }
            await _clientAccountService.DeleteWalletAsync(id);

            return(Ok());
        }