rcryptocurrency

crypto2 throws status '404 Not Found'


I am getting the following error from the crypto2-package,

# load coins
coins <- crypto2::crypto_list(
  only_active   = FALSE,
  add_untracked = FALSE
)
#> Warning in open.connection(con, "rb"): cannot open URL
#> 'https://web-api.coinmarketcap.com/v1/cryptocurrency/map': HTTP status was '404
#> Not Found'
#> Error in open.connection(con, "rb"): cannot open the connection to 'https://web-api.coinmarketcap.com/v1/cryptocurrency/map'

Created on 2024-06-04 with reprex v2.1.0

Until recently this has been working as expected. I have tried with and without a VPN connection - is this issue on API or client side?

I was expecting an object with cryptocurrencies.


Solution

  • There has been a major change in the Coinmarketcap API, and the base url in {crypto2} is now obsolete. The author is working on a fix it seems. See latest commit.

    In the mean time you can use {cryptoQuotes} as an alternative, if you need cryptocurrency data. Below is a MWE,

    # load library
    library(cryptoQuotes)
    

    Hourly Bitcoin (BTC)

    # get hourly
    # Bitcoin
    tail(
      BTC <- get_quote(
        ticker   = "BTCUSDT",
        interval = "1h"
      )
    )
    

    Output

    #>                        open    high     low   close    volume
    #> 2024-06-11 03:00:00 69454.6 69566.5 68479.4 68741.4 17137.138
    #> 2024-06-11 04:00:00 68741.4 68996.9 67881.9 68285.8 33301.328
    #> 2024-06-11 05:00:00 68285.9 68515.4 68189.0 68472.3  9231.694
    #> 2024-06-11 06:00:00 68472.2 68472.2 67606.2 68040.0 21653.075
    #> 2024-06-11 07:00:00 68040.1 68080.3 67670.1 67930.4  9094.521
    #> 2024-06-11 08:00:00 67930.3 68007.4 67814.4 67833.6  2145.541
    

    Charting (Example)

    # chart
    chart(
      ticker   = BTC,
      main     = kline(),
      indicato = list(
        bollinger_bands()
      ),
      sub      = list(
        volume()
      )
    )
    

    Created on 2024-06-11 with reprex v2.1.0