Пример #1
0
        public async Task <OperationResponse> CashOutAsync(string brokerId, CashInOutModel model)
        {
            var wallet = await _accountsClient.Wallet.GetAsync((long)model.WalletId, brokerId);

            if (wallet == null)
            {
                throw new ArgumentException($"Wallet '{model.WalletId}' does not exist.");
            }

            var volume = model.Volume >= 0 ? -model.Volume : model.Volume;

            var request = new CashInOutOperation
            {
                Id          = Guid.NewGuid().ToString(),
                BrokerId    = brokerId,
                AccountId   = model.AccountId,
                WalletId    = model.WalletId,
                AssetId     = model.Asset,
                Volume      = volume.ToString(CultureInfo.InvariantCulture),
                Description = model.Description
            };

            var fee = await GetFeeAsync(brokerId, model.Asset, RequestType.CashOut);

            request.Fees.Add(fee);

            var result = await _matchingEngineClient.CashOperations.CashInOutAsync(request);

            return(new OperationResponse(result));
        }
        public async Task CashOut_ExistedFee_ExistedSettings_PositiveVolumeToNegative_Test()
        {
            // arrange

            var assertCalls = new AssertCalls();

            var feeModel             = GetCashOperationsFeeModel(CashOutNegativeVolume, CashType.CashOut);
            var settings             = GetSettingsModel();
            var feesClient           = InitializeFeesClient(feeModel, settings);
            var accountsClient       = InitializeAccountsClient();
            var matchingEngineClient = InitializeMatchingEngineClient(AssertMatchingEngineClientInput, null, assertCalls);
            var logger = InitializeLogger <CashOperations>(AssertLoggerWarning, assertCalls);

            var cashOperations = new CashOperations(matchingEngineClient, feesClient, accountsClient, logger);

            // Volume is positive here and will 'converted' to negative
            var model = new CashInOutModel(Btc, CashOutPositiveVolume, AccountId, WalletId, Description);

            // act

            await cashOperations.CashOutAsync(BrokerId, model);

            // assert

            void AssertMatchingEngineClientInput(CashInOutOperation cashInOutOperation)
            {
                AssertCashInOutOperation(cashInOutOperation, CashOutNegativeVolume);

                AssertFees(cashInOutOperation.Fees, CashOutNegativeVolume / 100);
            }

            Assert.Equal(1, assertCalls.Count);
        }
        public async Task CashOut_NoFee_NoSettings_Test()
        {
            // arrange

            var assertCalls = new AssertCalls();

            var matchingEngineClient = InitializeMatchingEngineClient(AssertMatchingEngineClientInput, null, assertCalls);
            var feesClient           = InitializeFeesClient(null, null);
            var accountsClient       = InitializeAccountsClient();
            var logger = InitializeLogger <CashOperations>(AssertLoggerWarning, assertCalls);

            var cashOperations = new CashOperations(matchingEngineClient, feesClient, accountsClient, logger);

            var model = new CashInOutModel(Btc, CashOutNegativeVolume, AccountId, WalletId, Description);

            // act

            await cashOperations.CashOutAsync(BrokerId, model);

            // assert

            void AssertMatchingEngineClientInput(CashInOutOperation cashInOutOperation)
            {
                AssertCashInOutOperation(cashInOutOperation, CashOutNegativeVolume);

                AssertFees(cashInOutOperation.Fees, 0);
            }

            Assert.Equal(2, assertCalls.Count);
        }
Пример #4
0
        public async Task <OperationResponse> CashInAsync(string brokerId, CashInOutModel model)
        {
            var wallet = await _accountsClient.Wallet.GetAsync((long)model.WalletId, brokerId);

            if (wallet == null)
            {
                throw new ArgumentException($"Wallet '{model.WalletId}' does not exist.");
            }

            if (!wallet.IsEnabled)
            {
                throw new ArgumentException($"Wallet '{model.WalletId}' is disabled.");
            }

            if (wallet.Type != WalletType.Main)
            {
                throw new ArgumentException($"Wallet type must have type '{WalletType.Main}' for deposit / withdrawal operations.");
            }

            var request = new CashInOutOperation
            {
                Id          = Guid.NewGuid().ToString(),
                BrokerId    = brokerId,
                AccountId   = model.AccountId,
                WalletId    = model.WalletId,
                AssetId     = model.Asset,
                Volume      = model.Volume.ToString(CultureInfo.InvariantCulture),
                Description = model.Description
            };

            var fee = await GetFeeAsync(brokerId, model.Asset, RequestType.CashIn);

            request.Fees.Add(fee);

            var result = await _matchingEngineClient.CashOperations.CashInOutAsync(request);

            return(new OperationResponse(result));
        }
Пример #5
0
        public async Task <IActionResult> CashOutAsync([FromBody] CashInOutModel model)
        {
            var response = await _cashOperations.CashOutAsync(User.GetTenantId(), model);

            return(Ok(response));
        }