docstr: Update the portfolio cash and position balances based on the
  latest ticker prices.
  
  Parameters
  ----------
  positions:
      The positions to synchronize.
  
  check_balances:
      Check balances amounts against the exchange.
docstr_tok: ["Update","the","portfolio","cash","and","position","balances","based","on","the","latest","ticker","prices",".","Parameters","--","--","--","--","--","positions",":","The","positions","to","synchronize",".","check_balances",":","Check","balances","amounts","against","the","exchange","."]
code: def sync_positions(self, positions, cash=None, check_balances=False):
      """
      Update the portfolio cash and position balances based on the
      latest ticker prices.
  
      Parameters
      ----------
      positions:
          The positions to synchronize.
  
      check_balances:
          Check balances amounts against the exchange.
  
      """
      total_cash = 0.0
      if check_balances:
          log.debug("fetching {} balances".format(self.name))
          balances = self.get_balances()
          log.debug(
              "got balances for {} currencies".format(len(balances))
          )
          if cash is not None:
              total_cash, is_lower = self._check_low_balance(
                  currency=self.quote_currency,
                  balances=balances,
                  amount=cash,
              )
              if is_lower:
                  raise NotEnoughCashError(
                      currency=self.quote_currency,
                      exchange=self.name,
                      total=total_cash,
                      cash=cash,
                  )
  
      positions_value = 0.0
      if positions:
          assets = list(set([position.asset for position in positions]))
          tickers = self.tickers(assets)
  
          for position in positions:
              asset = position.asset
              if asset not in tickers:
                  raise TickerNotFoundError(
                      symbol=asset.symbol,
                      exchange=self.name,
                  )
  
              ticker = tickers[asset]
              log.debug(
                  "updating {symbol} position, last traded on {dt} for "
                  "{price}{currency}".format(
                      symbol=asset.symbol,
                      dt=ticker["last_traded"],
                      price=ticker["last_price"],
                      currency=asset.quote_currency,
                  )
              )
              position.last_sale_price = ticker["last_price"]
              position.last_sale_date = ticker["last_traded"]
  
              if check_balances:
                  total, is_lower = self._check_low_balance(
                      currency=asset.base_currency,
                      balances=balances,
                      amount=position.amount,
                  )
  
                  if is_lower:
                      log.warn(
                          "detected lower balance for {} on {}: {} < {}, "
                          "updating position amount".format(
                              asset.symbol,
                              self.name,
                              total,
                              position.amount,
                          )
                      )
                      position.amount = total
  
              positions_value += (
                  position.amount * position.last_sale_price
              )
  
      return total_cash, positions_value
  
imports: import abc
  from abc import ABCMeta, abstractmethod, abstractproperty
  from datetime import timedelta
  from time import sleep
  import numpy
  import pandas
  from catalyst.constants import LOG_LEVEL
  from catalyst.data.data_portal import BASE_FIELDS
  from catalyst.exchange.exchange_bundle import ExchangeBundle
  from catalyst.exchange.exchange_errors import MismatchingQuoteCurrencies, SymbolNotFoundOnExchange, PricingDataNotLoadedError, NoDataAvailableOnExchange, NoValueForField, NoCandlesReceivedFromExchange, TickerNotFoundError, NotEnoughCashError
  from catalyst.exchange.utils.datetime_utils import get_delta, get_periods_range, get_periods, get_start_dt, get_frequency, get_candles_number_from_minutes
  from catalyst.exchange.utils.exchange_utils import get_exchange_symbols, resample_history_df, has_bundle, get_candles_df
  from logbook import Logger
label_desc: Use image node_id 20 for calling the Exchange obj's underlying member method code with example usage: obj.sync_positions(positions, cash, check_balances) and returns: total_cash,  positions_value