Get the balance of an account for a particular type of token.
    This is its credits minus its debits.
    Returns the current balance on success.
    Aborts on error, or if the balance is somehow negative.
516979
def namedb_get_account_balance(account):
    
    # NOTE: this is only possible because Python does not overflow :P
    balance = account['credit_value'] - account['debit_value']
    if balance < 0:
        log.fatal("Balance of {} is {} (credits = {}, debits = {})".format(account['address'], balance, account['credit_value'], account['debit_value']))
        traceback.print_stack()
        os.abort()

    return balance
749207
def commit_account_credit(self, opcode, account_credit_info, current_block_number, current_vtxindex, current_txid):
        
        account_address = account_credit_info['address']
        account_credit = account_credit_info['amount']
        account_token_type = account_credit_info['type']

        if account_address is not None and account_credit is not None and account_token_type is not None:
            # sanity check 
            try:
                assert account_credit >= 0, 'Non-positive account credit {}'.format(account_credit)
                assert self.is_token_type_supported(account_token_type), 'Unsupported token type {}'.format(account_token_type)
            except Exception as e:
                log.exception(e)
                log.fatal("Sanity check failed")
                os.abort()

            # have to debit this account
            cur = self.db.cursor()
            rc = namedb_account_credit(cur, account_address, account_token_type, account_credit, current_block_number, current_vtxindex, current_txid)
            if not rc:
                traceback.print_stack()
                log.fatal("Failed to debit address {} {} {}".format(account_address, account_credit, account_token_type))
                os.abort()

            log.debug("COMMIT CREDIT ACCOUNT {} for {} units of {}(s) for {}".format(account_address, account_credit, account_token_type, opcode))

        return True
559498
def get_user_balance(self, username):
        
        cmd = ["gbalance", "-u", username, "--raw"]
        results = self._read_output(cmd)

        if len(results) == 0:
            return None

        return results
137833
def account_balance_after(self):
        """"""
        # TODO: Consider moving to annotation, particularly once we can count on Django 1.11's subquery support
        transaction_date = self.transaction.date
        return self.account.balance(
            leg_query=(
                models.Q(transaction__date__lt=transaction_date)
                | (
                    models.Q(transaction__date=transaction_date)
                    & models.Q(transaction_id__lte=self.transaction_id)
                )
            )
        )
476014
def get_balance(self, address, block="latest"):
        
        response = self.make_request("eth_getBalance", [address, block])
        return int(response['result'], 16)
519457
def _get_account_number(self, token, uuid):
        """"""
        # Data
        data = {"accessToken": token,
                "uuid": uuid}
        # Http request
        try:
            raw_res = yield from self._session.post(ACCOUNT_URL,
                                                    data=data,
                                                    headers=self._headers,
                                                    timeout=self._timeout)
        except OSError:
            raise PyFidoError("Can not get account number")
        # Load answer as json
        try:
            json_content = yield from raw_res.json()
            account_number = json_content\
                            .get('getCustomerAccounts', {})\
                            .get('accounts', [{}])[0]\
                            .get('accountNumber')
        except (OSError, ValueError):
            raise PyFidoError("Bad json getting account number")
        # Check collected data
        if account_number is None:
            raise PyFidoError("Can not get account number")

        return account_number
153138
def balance(ctx, accounts):
    
    t = [["Account", "Amount"]]
    for a in accounts:
        account = Account(a, bitshares_instance=ctx.bitshares)
        for b in account.balances:
            t.append([str(a), str(b)])
    print_table(t)
82437
def get_start_balance(self, before: date) -> Decimal:
        
        assert isinstance(before, datetime)

        # create a new date without hours
        datum = Datum()
        datum.from_date(before)
        #date_corrected = datetimeutils.start_of_day(before)
        # now subtract 1 second.
        #date_corrected -= timedelta(seconds=1)
        #log(DEBUG, "getting balance on %s", date_corrected)
        datum.yesterday()
        datum.end_of_day()
        return self.get_balance_on(datum.value)
593696
def get_margin_balance(self, symbol):
        
        params = {}
        path = '/v1/margin/accounts/balance'
        if symbol:
            params['symbol'] = symbol

        def _wrapper(_func):
            @wraps(_func)
            def handle():
                _func(api_key_get(params, path))

            return handle

        return _wrapper
507788
def get_account_delta(self, address, token_type, block_id, vtxindex):
        
        cur = self.db.cursor()
        return namedb_get_account_delta(cur, address, token_type, block_id, vtxindex)
1059039
def get_account(self, account):
        
        selector = account.to_selector()
        resp = self.request_single('GetAccount', {'account': selector})
        return zobjects.Account.from_dict(resp)
121879
def get(account):
        
        account = Account.get(account)
        if not account:
            return None

        acct_type = AccountType.get(account.account_type_id).account_type
        account_class = get_plugin_by_name(PLUGIN_NAMESPACES['accounts'], acct_type)

        return account_class(account)
832780
def get_total_paid_for_remaining_stock(self) -> Decimal:
        
        paid = Decimal(0)

        accounts = self.get_holding_accounts()
        for acc in accounts:
            splits = self.get_available_splits_for_account(acc)
            paid += sum(split.value for split in splits)
        return paid
498955
def credit(self, amount, debit_account, description, debit_memo="", credit_memo="", datetime=None):
        
        assert amount >= 0
        return self.post(-amount, debit_account, description, self_memo=credit_memo, other_memo=debit_memo, datetime=datetime)
55095
def get_aggregate_balance(self, _async=False):
        
        params = {}
        path = '/v1/subuser/aggregate-balance'
        return  api_key_get(params, path, _async=_async)
1265226
def balance(self):
        
        if self._balance is None:
            self._balance = BalanceList(self._version, account_sid=self._solution['sid'], )
        return self._balance
41341
def get_balance(self, address, api_token):
        
        broadcast_url = self.base_url + '?module=account&action=balance'
        broadcast_url += '&address=%s' % address
        broadcast_url += '&tag=latest'
        if api_token:
            '&apikey=%s' % api_token
        response = requests.get(broadcast_url)
        if int(response.status_code) == 200:
            balance = int(response.json().get('result', None))
            logging.info('Balance check succeeded: %s', response.json())
            return balance
        raise BroadcastError(response.text)