Esempio n. 1
0
def get_asset_info(asset, at_dt=None):
    mongo_db = config.mongo_db
    asset_info = mongo_db.tracked_assets.find_one({'asset': asset})
    
    if asset not in (config.XCP, config.BTC) and at_dt and asset_info['_at_block_time'] > at_dt:
        #get the asset info at or before the given at_dt datetime
        for e in reversed(asset_info['_history']): #newest to oldest
            if e['_at_block_time'] <= at_dt:
                asset_info = e
                break
        else: #asset was created AFTER at_dt
            asset_info = None
        if asset_info is None: return None
        assert asset_info['_at_block_time'] <= at_dt
      
    #modify some of the properties of the returned asset_info for BTC and XCP
    if asset == config.BTC:
        if at_dt:
            start_block_index, end_block_index = util.get_block_indexes_for_dates(end_dt=at_dt)
            asset_info['total_issued'] = util_bitcoin.get_btc_supply(normalize=False, at_block_index=end_block_index)
            asset_info['total_issued_normalized'] = util_bitcoin.normalize_quantity(asset_info['total_issued'])
        else:
            asset_info['total_issued'] = util_bitcoin.get_btc_supply(normalize=False)
            asset_info['total_issued_normalized'] = util_bitcoin.normalize_quantity(asset_info['total_issued'])
    elif asset == config.XCP:
        #BUG: this does not take end_dt (if specified) into account. however, the deviation won't be too big
        # as XCP doesn't deflate quickly at all, and shouldn't matter that much since there weren't any/much trades
        # before the end of the burn period (which is what is involved with how we use at_dt with currently)
        asset_info['total_issued'] = util.call_jsonrpc_api("get_xcp_supply", abort_on_error=True)['result']
        asset_info['total_issued_normalized'] = util_bitcoin.normalize_quantity(asset_info['total_issued'])
    if not asset_info:
        raise Exception("Invalid asset: %s" % asset)
    return asset_info
Esempio n. 2
0
def get_asset_info(asset, at_dt=None):
    mongo_db = config.mongo_db
    asset_info = mongo_db.tracked_assets.find_one({'asset': asset})

    if asset not in (config.XCP, config.BTC
                     ) and at_dt and asset_info['_at_block_time'] > at_dt:
        #get the asset info at or before the given at_dt datetime
        for e in reversed(asset_info['_history']):  #newest to oldest
            if e['_at_block_time'] <= at_dt:
                asset_info = e
                break
        else:  #asset was created AFTER at_dt
            asset_info = None
        if asset_info is None: return None
        assert asset_info['_at_block_time'] <= at_dt

    #modify some of the properties of the returned asset_info for DOGE and XDP
    if asset == config.BTC:
        if at_dt:
            start_block_index, end_block_index = util.get_block_indexes_for_dates(
                end_dt=at_dt)
            asset_info['total_issued'] = util_bitcoin.get_btc_supply(
                normalize=False, at_block_index=end_block_index)
            asset_info[
                'total_issued_normalized'] = util_bitcoin.normalize_quantity(
                    asset_info['total_issued'])
        else:
            asset_info['total_issued'] = util_bitcoin.get_btc_supply(
                normalize=False)
            asset_info[
                'total_issued_normalized'] = util_bitcoin.normalize_quantity(
                    asset_info['total_issued'])
    elif asset == config.XCP:
        #BUG: this does not take end_dt (if specified) into account. however, the deviation won't be too big
        # as XDP doesn't deflate quickly at all, and shouldn't matter that much since there weren't any/much trades
        # before the end of the burn period (which is what is involved with how we use at_dt with currently)
        asset_info['total_issued'] = util.call_jsonrpc_api(
            "get_xcp_supply", abort_on_error=True)['result']
        asset_info[
            'total_issued_normalized'] = util_bitcoin.normalize_quantity(
                asset_info['total_issued'])
    if not asset_info:
        raise Exception("Invalid asset: %s" % asset)
    return asset_info
Esempio n. 3
0
def get_asset_info(asset, at_dt=None):
    mongo_db = config.mongo_db
    asset_info = mongo_db.tracked_assets.find_one({'asset': asset})

    if asset not in (config.XCP, config.BTC
                     ) and at_dt and asset_info['_at_block_time'] > at_dt:
        #get the asset info at or before the given at_dt datetime
        for e in reversed(asset_info['_history']):  #newest to oldest
            if e['_at_block_time'] <= at_dt:
                asset_info = e
                break
        else:  #asset was created AFTER at_dt
            asset_info = None
        if asset_info is None: return None
        assert asset_info['_at_block_time'] <= at_dt

    if asset == config.BTC:
        if at_dt:
            start_block_index, end_block_index = util.get_block_indexes_for_dates(
                end_dt=at_dt)
            asset_info['total_issued'] = util_bitcoin.get_btc_supply(
                normalize=False, at_block_index=end_block_index)
            asset_info[
                'total_issued_normalized'] = util_bitcoin.normalize_quantity(
                    asset_info['total_issued'])
        else:
            asset_info['total_issued'] = util_bitcoin.get_btc_supply(
                normalize=False)
            asset_info[
                'total_issued_normalized'] = util_bitcoin.normalize_quantity(
                    asset_info['total_issued'])
    elif asset == config.XCP:
        asset_info['total_issued'] = util.call_jsonrpc_api(
            "get_xcp_supply", abort_on_error=True)['result']
        asset_info[
            'total_issued_normalized'] = util_bitcoin.normalize_quantity(
                asset_info['total_issued'])
    if not asset_info:
        raise Exception("Invalid asset: %s" % asset)
    return asset_info