def _get_credit(self, manager, context): """ Obtains credit costs. """ try: cur = string2currency(input('currency: '), protocol='ice') amount = float(input('amount: ')) duration = int(input('months duration: ')) result = manager.getCreditCosts(cur, amount, duration, context) print('home currency costs: {}'.format(result.homeCurrency)) if result.foreignCurrency: print('foreign currency costs: {}'.format( result.foreignCurrency)) return True except AttributeError as e: print('error: ', str(e)) print('your account probably does not support this functionality') except Exception as e: print('error: ', str(e)) return False
def getAccountDetails(self, current=None): log('obtaining client {} account balance'.format(self._PESEL)) balance = {string2currency(key, protocol='ice') : value for key, value in self._balance.items()} return Accounts.AccountDetails( declaredMonthlyIncome=self._monthly_income, balance=balance)
def update(): rates_server_address = '{}:{}'.format( self._config['ratesProviderAddress'], self._config['ratesProviderPort']) with grpc.insecure_channel(rates_server_address) as channel: stub = exchange_rate_pb2_grpc.ExchangeRatesProviderStub(channel) msg = exchange_rate_pb2.Subscription() msg.homeCurrency = string2currency( self._home_currency, protocol='grpc') f_cur = [string2currency(c, protocol='grpc') for c in self._foreign_currencies] msg.foreignCurrencies[:] = f_cur updates = stub.subscribe(msg) try: for u in updates: self._update_exchange_rates(u) except grpc._channel._Rendezvous as e: print(e)
def _take_money(self, manager, context): """ Withdrawing money from account. """ try: cur = string2currency(input('currency: '), protocol='ice') amount = float(input('amount: ')) manager.withdrawFromAccount(cur, amount, context) return True except Exception as e: print('error: ', str(e)) return False
def _put_money(self, manager, context): """ Transferring money into account. """ try: cur = string2currency(input('currency: '), protocol='ice') amount = float(input('amount: ')) manager.transferToAccount(cur, amount, context) return True except Exception as e: print('error: ', str(e)) return False