Alpha Vantage: Invalid API call when querying 'DIGITAL_CURRENCY_DAILY' BTC to USD/EUR

My Problem:

I am trying to retrieve the daily prices in € or $ (EUR or USD) of Bitcoin (BTC) from the alpha vantage API in python, however it appears to return the following Error Message: Invalid API call. Please retry or visit the documentation (https://www.alphavantage.co/documentation/) for DIGITAL_CURRENCY_DAILY.

I have used the API extensively in the past and I can guarantee that this has works just fine over the last years.

Any help is greatly appreciated!

What I’ve tried:

I have boiled down the problem to a minimal working example to highlight that the API in general appears to work as expected, but this specific pairing of currencies appears to be broken:

import requests
import time

API_FUNCTION = "DIGITAL_CURRENCY_DAILY"

for CRY in ["LTC","BTC","WBTC"]:
    print(f"--- {CRY} ---")
    for CUR in ["EUR","USD","AUD","CNY"]:
        #--- Query API ---
        url       = f"https://www.alphavantage.co/query?function={API_FUNCTION}&symbol={CRY}&market={CUR}&apikey={API_KEY}&datatype=json"
        response  = requests.get(url)
        data      = response.json()
        is_failure = "Error Message" in data
        #--- Print Result ---
        print(CUR,response,"FAILURE!" if is_failure else "SUCCESS!")
        print("\t",data["Error Message" if is_failure else "Meta Data"])

        time.sleep(12.0) # Wait to not exceed 5 calls/minute free API restriction

I try to query the prices on a daily basis for all combinations of 3 Cryptocurrencies [“Litecoin”,“Bitcoin”,“Wrapped Bitcoin”] and 4 physical currencies [“Euro”,“US Dollar”,“Australian Dollar”,“Renminbi”].

The following observations can be made:

  • LTC: As expected, all calls succeed for Litecoin
  • BTC: For Bitcoin all calls succeed, except for EUR and USD
  • WBTC: The attempt to retrieve the price of bitcoin through another cryptocurrency pegged to Bitcoin fails on all calls, even though ‘WBTC’ is listed as a a supported digital currency on the Alpha Vantage documentation page Digital currency list.

The full output of the code example above is as follows: I tried to provide the full output log, but for some unfortunate reason my post was flagged with Your question appears to be spam.. :frowning:

PS:

I know that one solution would be to query the price in another currency and then apply the exchange rate between be desired and the queried physical currency, but that seems like a hack I’d rather avoid if at all possible.

It looks like you’re encountering an issue specifically with the Alpha Vantage API when trying to retrieve Bitcoin prices in EUR and USD. Here are a few suggestions to help troubleshoot and possibly resolve the issue:

  1. Check API Key Limits: Make sure that your API key has not exceeded the limit for the number of requests. Alpha Vantage has a limit of 5 calls per minute and 500 calls per day for free users. You might consider checking the API key status or waiting a bit before trying again.
  2. Confirm API Functionality: Since you’re getting an “Invalid API call” error specifically for Bitcoin in EUR and USD, it might be worth checking if Alpha Vantage has temporarily disabled support for those combinations or if there are issues on their end. Check their status page or community forums for any updates.
  3. Review Currency Pairing: Sometimes, specific currency pairs might have different availability or historical data issues. While LTC seems to work, it’s possible that BTC’s data in EUR and USD might have some temporary issues.
  4. Testing Other APIs: If you’re open to alternatives, consider testing other cryptocurrency price APIs like CoinGecko or CoinMarketCap. This can help confirm if the issue is specific to Alpha Vantage.
  5. Debugging Output: Enhance your output for debugging. Instead of printing just the error message, you can log the entire response when an error occurs to get more context:
if is_failure:
    print("\tFull Response:", data)
  1. Rate Limiting: You might be hitting the rate limit inadvertently due to the loop. To avoid this, you could reduce the number of calls or increase the sleep time between requests.
  2. Try Alternate Symbols: For WBTC and others, ensure that the symbols you’re using match exactly what Alpha Vantage expects. Sometimes small discrepancies can lead to failures.

Here’s a slightly modified version of your code to enhance error handling:

import requests
import time

API_KEY = "YOUR_API_KEY"  # Replace with your actual API key
API_FUNCTION = "DIGITAL_CURRENCY_DAILY"

for CRY in ["LTC", "BTC", "WBTC"]:
    print(f"--- {CRY} ---")
    for CUR in ["EUR", "USD", "AUD", "CNY"]:
        #--- Query API ---
        url = f"https://www.alphavantage.co/query?function={API_FUNCTION}&symbol={CRY}&market={CUR}&apikey={API_KEY}&datatype=json"
        response = requests.get(url)
        data = response.json()
        is_failure = "Error Message" in data
        
        #--- Print Result ---
        print(CUR, response.status_code, "FAILURE!" if is_failure else "SUCCESS!")
        if is_failure:
            print("\tError Message:", data["Error Message"])
            print("\tFull Response:", data)
        else:
            print("\tMeta Data:", data["Meta Data"])
        
        time.sleep(12.0)  # Wait to not exceed 5 calls/minute

This way, you’ll have a clearer view of what’s being returned by the API. If the issue persists after trying these steps, reaching out to Alpha Vantage support might also provide insights or confirmation of any issues on their end.