def coinbasepro_to_worldpair(product: str) -> Tuple[Asset, Asset]: """Turns a coinbasepro product into our base/quote assets - Can raise UnprocessableTradePair if product is in unexpected format - Case raise UnknownAsset if any of the pair assets are not known to rotki """ parts = product.split('-') if len(parts) != 2: raise UnprocessableTradePair(product) base_asset = asset_from_coinbasepro(parts[0]) quote_asset = asset_from_coinbasepro(parts[1]) return base_asset, quote_asset
def create_or_return_account_to_currency_map(self) -> Dict[str, Asset]: if self.account_to_currency is not None: return self.account_to_currency accounts, _ = self._api_query('accounts') self.account_to_currency = {} for account in accounts: try: asset = asset_from_coinbasepro(account['currency']) self.account_to_currency[account['id']] = asset except UnsupportedAsset as e: self.msg_aggregator.add_warning( f'Found coinbase pro account with unsupported asset ' f'{e.asset_name}. Ignoring it.', ) continue except UnknownAsset as e: self.msg_aggregator.add_warning( f'Found coinbase pro account result with unknown asset ' f'{e.asset_name}. Ignoring it.', ) continue except KeyError as e: self.msg_aggregator.add_warning( f'Found coinbase pro account entry with missing {str(e)} field. ' f'Ignoring it', ) continue return self.account_to_currency
def query_balances(self) -> ExchangeQueryBalances: try: accounts, _ = self._api_query('accounts') except (CoinbaseProPermissionError, RemoteError) as e: msg = f'Coinbase Pro API request failed. {str(e)}' log.error(msg) return None, msg assets_balance: DefaultDict[Asset, Balance] = defaultdict(Balance) for account in accounts: try: amount = deserialize_asset_amount(account['balance']) # ignore empty balances. Coinbase returns zero balances for everything # a user does not own if amount == ZERO: continue asset = asset_from_coinbasepro(account['currency']) try: usd_price = Inquirer().find_usd_price(asset=asset) except RemoteError as e: self.msg_aggregator.add_error( f'Error processing coinbasepro balance result due to inability to ' f'query USD price: {str(e)}. Skipping balance entry', ) continue assets_balance[asset] += Balance( amount=amount, usd_value=amount * usd_price, ) except UnknownAsset as e: self.msg_aggregator.add_warning( f'Found coinbase pro balance result with unknown asset ' f'{e.asset_name}. Ignoring it.', ) continue except UnsupportedAsset as e: self.msg_aggregator.add_warning( f'Found coinbase pro balance result with unsupported asset ' f'{e.asset_name}. Ignoring it.', ) continue except (DeserializationError, KeyError) as e: msg = str(e) if isinstance(e, KeyError): msg = f'Missing key entry for {msg}.' self.msg_aggregator.add_error( 'Error processing a coinbase pro account balance. Check logs ' 'for details. Ignoring it.', ) log.error( 'Error processing a coinbase pro account balance', account_balance=account, error=msg, ) continue return dict(assets_balance), ''