Esempio n. 1
0
def name_check(
    asset_symbol: str,
    our_asset: Dict[str, Any],
    our_data: Dict[str, Any],
    paprika_data: Dict[str, Any],
    cmc_data: Dict[str, Any],
) -> Dict[str, Any]:
    """Process the name from coin paprika and coinmarketcap

    Then compare to our data and provide choices to clean up the data.
    """

    our_name = our_asset.get('name', None)
    if our_name:
        # If we already got a name from manual input then keep it
        return our_data

    if asset_symbol in MANUALLY_CHECKED_NAMES:
        our_data[asset_symbol]['name'] = MANUALLY_CHECKED_NAMES[asset_symbol]
        return our_data

    paprika_name = None
    if paprika_data:
        paprika_name = paprika_data['name']
    cmc_name = None
    if cmc_data:
        cmc_name = cmc_data['name']

    if not paprika_name and not cmc_name and asset_symbol:
        print(f'No name in any external api for asset {asset_symbol}')
        sys.exit(1)

    if paprika_name == cmc_name:
        # If both external APIs agree just use their name
        our_data[asset_symbol]['name'] = paprika_name
        return our_data

    msg = (f'For asset {asset_symbol} the possible names are: \n'
           f'(1) Coinpaprika: {paprika_name}\n'
           f'(2) Coinmarketcap: {cmc_name}\n'
           f'Choose a number (1)-(2) to choose which name to use: ')
    choice = choose_multiple(msg, (1, 2))
    if choice == 1:
        name = paprika_name
    elif choice == 2:
        if not cmc_name:
            print("Chose coinmarketcap's name but it's empty. Bailing ...")
            sys.exit(1)
        name = cmc_name

    our_data[asset_symbol]['name'] = name
    return our_data
Esempio n. 2
0
def timerange_check(
        asset_symbol: str,
        our_asset: Dict[str, Any],
        our_data: Dict[str, Any],
        paprika_data: Dict[str, Any],
        cmc_data: Dict[str, Any],
        always_keep_our_time: bool,
        token_address: EthAddress = None,
) -> Dict[str, Any]:
    """Process the started timestamps from coin paprika and coinmarketcap.

    Then compare to our data and provide choices to clean up the data.
    """
    if Asset(asset_symbol).is_fiat():
        # Fiat does not have started date (or we don't care about it)
        return our_data

    paprika_started = None
    if paprika_data:
        paprika_started = paprika_data['started_at']
    cmc_started = None
    if cmc_data:
        cmc_started = cmc_data['first_historical_data']

    if not cmc_started and not paprika_started and not token_address:
        print(f'Did not find a started date for asset {asset_symbol} in any of the external APIs')
        return our_data

    paprika_started_ts = None
    if paprika_started:
        paprika_started_ts = create_timestamp(paprika_started, formatstr='%Y-%m-%dT%H:%M:%SZ')
    cmc_started_ts = None
    if cmc_data:
        cmc_started_ts = iso8601ts_to_timestamp(cmc_started)

    if asset_symbol in PREFER_OUR_STARTED:
        assert 'started' in our_asset
        # Already manually checked
        return our_data

    our_started = our_asset.get('started', None)

    # if it's an eth token entry, get the contract creation time too
    if token_address:
        contract_creation_ts = get_token_contract_creation_time(token_address)

    if not our_started:
        # If we don't have any data and CMC and paprika agree just use their timestamp
        if cmc_started == paprika_started and cmc_started is not None:
            our_data[asset_symbol]['started'] = cmc_started
            return our_data

    if our_started and always_keep_our_time:
        return our_data

    if our_started is None or our_started != cmc_started or our_started != paprika_started:
        choices = (1, 2, 3)
        msg = (
            f'For asset {asset_symbol} the started times are: \n'
            f'(1) Our data: {our_started} -- {timestamp_to_date(our_started) if our_started else ""}\n'
            f'(2) Coinpaprika: {paprika_started_ts} -- '
            f'{timestamp_to_date(paprika_started_ts) if paprika_started_ts else ""}\n'
            f'(3) Coinmarketcap: {cmc_started_ts} -- '
            f'{timestamp_to_date(cmc_started_ts) if cmc_started_ts else ""} \n'
        )
        if token_address:
            msg += (
                f'(4) Contract creation: {contract_creation_ts} -- '
                f'{timestamp_to_date(contract_creation_ts) if contract_creation_ts else ""}\n'
            )
            choices = (1, 2, 3, 4)

        msg += f'Choose a number (1)-({choices[-1]}) to choose which timestamp to use: '
        choice = choose_multiple(msg, choices)
        if choice == 1:
            if not our_started:
                print('Chose our timestamp but we got no timestamp. Bailing ...')
                sys.exit(1)
            timestamp = our_started

        elif choice == 2:
            if not paprika_started_ts:
                print("Chose coin paprika's timestamp but it's empty. Bailing ...")
                sys.exit(1)
            timestamp = paprika_started_ts

        elif choice == 3:
            if not cmc_started_ts:
                print("Chose coinmarketcap's timestamp but it's empty. Bailing ...")
                sys.exit(1)
            timestamp = cmc_started_ts

        elif choice == 4:
            if not contract_creation_ts:
                print("Chose contract creation timestamp but it's empty. Bailing ...")
                sys.exit(1)
            timestamp = contract_creation_ts

        our_data[asset_symbol]['started'] = timestamp

    return our_data