def get_exchange_rates(self, obj): rates = {} for to_token in self.context.get('exchange_pairs', []): if to_token != obj: try: rate = Exchange.get_exchange_rate(obj, to_token) rates[to_token.symbol] = rate except SubexchangeNotFound: pass return rates
def get_exchange_rate(user: User, from_token: Token): to_token = user.get_reserve_token() if from_token == to_token: return None exchange = Exchange() return exchange.get_exchange_rate(from_token, to_token)