Skip to content

Fix BtcConverter by migrating from decommissioned CoinDesk API to Coinbase#161

Open
LIGHTUNCHARGED wants to merge 1 commit into
MicroPyramid:masterfrom
LIGHTUNCHARGED:fix
Open

Fix BtcConverter by migrating from decommissioned CoinDesk API to Coinbase#161
LIGHTUNCHARGED wants to merge 1 commit into
MicroPyramid:masterfrom
LIGHTUNCHARGED:fix

Conversation

@LIGHTUNCHARGED

Copy link
Copy Markdown

The CoinDesk Bitcoin Price Index (BPI) API domain (api.coindesk.com) has been completely decommissioned. As a result, every method inside the BtcConverter class currently fails, throwing urllib3.exceptions.NameResolutionError / DNS resolution failures.
This PR restores full functionality to BtcConverter by replacing the dead CoinDesk endpoints in forex_python/bitcoin.py with Coinbase's stable, public, and keyless API endpoints:

Real-time spot price endpoint: /v2/prices/BTC-{currency}/spot

Historical price endpoint (by date): /v2/prices/BTC-{currency}/spot?date={YYYY-MM-DD}
All internal class methods, historical queries, and conversions (supporting both float and Decimal response formats) have been thoroughly updated and are now fully functional.

Changes Checklist
[x] Swapped dead api.coindesk.com URLs with active api.coinbase.com endpoints.

[x] Parsed the updated JSON response schema structure from the Coinbase API.

[x] Verified compatibility with both standard float and exact Decimal data returns.

[x] Tested all historical date parsing methods locally.

You can verify the fix by running the following end-to-end test script against the modified branch. It exercises every core method available in the BtcConverter class:

from datetime import datetime, timedelta
from forex_python.bitcoin import BtcConverter

b = BtcConverter()

print("--- Testing Live & Historical Price Fetching ---")
# Test get_latest_price
print("get_latest_price (EUR):", b.get_latest_price('EUR'))

# Test get_previous_price
date_obj = datetime.now() - timedelta(days=5)
print("get_previous_price (EUR, 5 days ago):", b.get_previous_price('EUR', date_obj))

# Test get_previous_price_list
start_date = datetime.now() - timedelta(days=3)
end_date = datetime.now() - timedelta(days=1)
print("get_previous_price_list (EUR):", b.get_previous_price_list('EUR', start_date, end_date))

print("\n--- Testing Currency Conversion Calculations ---")
# Test convert_to_btc
print("convert_to_btc (1000 EUR):", b.convert_to_btc(1000, 'EUR'))

# Test convert_btc_to_cur
print("convert_btc_to_cur (0.02 BTC to EUR):", b.convert_btc_to_cur(0.02, 'EUR'))

# Test convert_to_btc_on
print("convert_to_btc_on (1000 EUR, 5 days ago):", b.convert_to_btc_on(1000, 'EUR', date_obj))

# Test convert_btc_to_cur_on
print("convert_btc_to_cur_on (0.02 BTC to EUR, 5 days ago):", b.convert_btc_to_cur_on(0.02, 'EUR', date_obj))

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant