public async Task CashTransfer_NoFee_ExistedSettings_Test() { // arrange var assertCalls = new AssertCalls(); var settings = GetSettingsModel(); var feesClient = InitializeFeesClient(null, settings); var accountsClient = InitializeAccountsClient(); var matchingEngineClient = InitializeMatchingEngineClient(null, AssertMatchingEngineClientInput, assertCalls); var logger = InitializeLogger <CashOperations>(AssertLoggerWarning, assertCalls); var cashOperations = new CashOperations(matchingEngineClient, feesClient, accountsClient, logger); var model = new CashTransferModel(Btc, CashTransferVolume, AccountId, FromWalletId, ToWalletId, Description); // act await cashOperations.CashTransferAsync(BrokerId, model); // assert void AssertMatchingEngineClientInput(CashTransferOperation cashTransferOperation) { AssertCashTransferOperation(cashTransferOperation, CashTransferVolume); AssertFees(cashTransferOperation.Fees, 0); } Assert.Equal(2, assertCalls.Count); }
public async Task <OperationResponse> CashTransferAsync(string brokerId, CashTransferModel model) { var wallets = await _accountsClient.Wallet.GetAllAsync(new[] { (long)model.FromWalletId, (long)model.ToWalletId }, brokerId); var fromWallet = wallets.SingleOrDefault(x => x.Id == (long)model.FromWalletId); var toWallet = wallets.SingleOrDefault(x => x.Id == (long)model.ToWalletId); if (fromWallet == null) { throw new ArgumentException($"Source wallet '{model.FromWalletId}' doesn't exist."); } if (toWallet == null) { throw new ArgumentException($"Target wallet '{model.ToWalletId}' doesn't exist."); } if (!toWallet.IsEnabled) { throw new ArgumentException($"Target wallet '{model.FromWalletId}' is disabled."); } if (fromWallet.AccountId != toWallet.AccountId) { throw new ArgumentException($"Target and source wallets must have the same account id."); } var request = new CashTransferOperation { Id = Guid.NewGuid().ToString(), BrokerId = brokerId, AssetId = model.Asset, Volume = model.Volume.ToString(CultureInfo.InvariantCulture), AccountId = model.AccountId, FromWalletId = model.FromWalletId, ToWalletId = model.ToWalletId, Description = model.Description }; var fee = await GetFeeAsync(brokerId, model.Asset, RequestType.Transfer); request.Fees.Add(fee); var result = await _matchingEngineClient.CashOperations.CashTransferAsync(request); return(new OperationResponse(result)); }
public async Task <IActionResult> CashTransferAsync([FromBody] CashTransferModel model) { var response = await _cashOperations.CashTransferAsync(User.GetTenantId(), model); return(Ok(response)); }