Core: Coinmarketcap integration broken/outdated. It uses new API now.

Created on 7 Mar 2020  Â·  12Comments  Â·  Source: home-assistant/core

The problem

Coinmarketcap sensors are not working anymore. It seems to use new API now.

Environment

  • Home Assistant release with the issue: 0.106.5
  • Last working Home Assistant release (if known): 0.106.5
  • Operating environment (Hass.io/Docker/Windows/etc.):
  • Integration causing this issue: coinmarketcap
  • Link to integration documentation on our website: https://www.home-assistant.io/integrations/coinmarketcap/

Problem-relevant configuration.yaml

sensor:
  - platform: coinmarketcap

Traceback/Error logs

going to https://api.coinmarketcap.com/v2/ticker/ will give out following message: 

{"statusCode": 410,"error": "Gone","message": "WARNING: This API is now offline. Please switch to the new CoinMarketCap API. (https://pro.coinmarketcap.com/migrate/)"}

Additional information

someone has the same problem and reported it here https://community.home-assistant.io/t/coinmarketcap-platform-uses-an-outdated-api/176812

coinmarketcap

Most helpful comment

Hi
For those still wanting to use Coin Market Cap i have included by configuration which uses the Command_Line integration to use a curl command to hit the new Coin Market Cap REST API and extract relevant data.
This solution relies on users subscribing to the new Coin Market Cap API with a Free account which includes 333 API credits.
(https://coinmarketcap.com/api/)

Once you have an API key then this can be used with the following configuration. The configuration extracts BTC, ETH, and ETC values every 10 minutes via a single REST quote request. The individual coin prices are then split out into individual sensor templates for presentation. The API documentation is quite good if you wish to extract other information.

Hopefully the integration gets fixed eventually, even if the user has to insert their own API key.

sensor:

  • platform: command_line
    name: coinmarketcap_curl
    command: '/usr/bin/curl -X GET -H "X-CMC_PRO_API_KEY: INSERT CMC API KEY HERE" -H "Accept: application/json" -d "symbol=ETH,ETC,BTC&convert=AUD" -G "https://pro-api.coinmarketcap.com/v1/cryptocurrency/quotes/latest"'
    value_template: '{{ value_json.value }}'
    scan_interval: 600 #10 mins refresh (144 credits / day used)
    json_attributes:

    • data

  • platform: template
    sensors:
    btc_price:
    friendly_name: 'Bitcoin Price'
    unit_of_measurement: 'AUD'
    value_template: '{{ ((states.sensor.coinmarketcap_curl.attributes.data.BTC.quote.AUD.price) | float) | round(2) }}'

    eth_price:
    friendly_name: 'Ethereum Price'
    unit_of_measurement: 'AUD'
    value_template: '{{ ((states.sensor.coinmarketcap_curl.attributes.data.ETH.quote.AUD.price) | float) | round(2) }}'

    etc_price:
    friendly_name: 'Ethereum Classic Price'
    unit_of_measurement: 'AUD'
    value_template: '{{ ((states.sensor.coinmarketcap_curl.attributes.data.ETC.quote.AUD.price) | float) | round(2) }}'

All 12 comments

I can confirm I’m also having the same issue, the coinmarketcap public api has been decommissioned in favour of their new api.

Same thing over here.

FYI an alternative could be #31114

I can confirm this

May i suggest considering a switch to CoinGecko API? https://www.coingecko.com/en/api
The endpoints are public, open, and freely available to access all 7000+ tokens data from https://www.coingecko.com

It should be an easy integration and drop in.
Let me know what you think, and happy to answer any questions!

Another alternative would be ha-bitstampnet which is a Home-assistant integration which fetches crypto currency exchange rates from bitstamp.net.

Need Coinmarketcap back. I've other coins and use other currency than ha-bitstampnet support.

+1 on switch to CoinGecko

I'm using this as a temp solution, modify as needed

  - platform: scrape
    name: Bitcoin
    resource: "https://www.coingecko.com/en/coins/bitcoin/eur"
    select: ".text-3xl > span[data-target]"
    value_template: '{{ value[1:].replace(",", "") | float | round(2) }}'
    scan_interval: 900 # 15 min
    unit_of_measurement: "€"

Hi
For those still wanting to use Coin Market Cap i have included by configuration which uses the Command_Line integration to use a curl command to hit the new Coin Market Cap REST API and extract relevant data.
This solution relies on users subscribing to the new Coin Market Cap API with a Free account which includes 333 API credits.
(https://coinmarketcap.com/api/)

Once you have an API key then this can be used with the following configuration. The configuration extracts BTC, ETH, and ETC values every 10 minutes via a single REST quote request. The individual coin prices are then split out into individual sensor templates for presentation. The API documentation is quite good if you wish to extract other information.

Hopefully the integration gets fixed eventually, even if the user has to insert their own API key.

sensor:

  • platform: command_line
    name: coinmarketcap_curl
    command: '/usr/bin/curl -X GET -H "X-CMC_PRO_API_KEY: INSERT CMC API KEY HERE" -H "Accept: application/json" -d "symbol=ETH,ETC,BTC&convert=AUD" -G "https://pro-api.coinmarketcap.com/v1/cryptocurrency/quotes/latest"'
    value_template: '{{ value_json.value }}'
    scan_interval: 600 #10 mins refresh (144 credits / day used)
    json_attributes:

    • data

  • platform: template
    sensors:
    btc_price:
    friendly_name: 'Bitcoin Price'
    unit_of_measurement: 'AUD'
    value_template: '{{ ((states.sensor.coinmarketcap_curl.attributes.data.BTC.quote.AUD.price) | float) | round(2) }}'

    eth_price:
    friendly_name: 'Ethereum Price'
    unit_of_measurement: 'AUD'
    value_template: '{{ ((states.sensor.coinmarketcap_curl.attributes.data.ETH.quote.AUD.price) | float) | round(2) }}'

    etc_price:
    friendly_name: 'Ethereum Classic Price'
    unit_of_measurement: 'AUD'
    value_template: '{{ ((states.sensor.coinmarketcap_curl.attributes.data.ETC.quote.AUD.price) | float) | round(2) }}'

Thanks, with the recent deprecation of yaml it's nice to get a reminder that doing stuff the old-fashioned way still works if one still wants yaml.

Too bad one can't use secrets in the curl however, but not like the CMC-apikey actually costs anything.

Another alternative is our own, brand new, cryptocurrency API service, BitFetch.io which supports hundreds of cryptocurrencies with more and more exchanges on the way. We have generous API limits, expect to see our FREE plan expand in features and limits over time.

Our team is full of members that are passionate HA users, in fact our FREE plan was made partly with HA users in mind. I'm currently using it in my own home with HA and Node Red to change an RGB bulb's color and brightness based on price movements while another one of my colleagues is displaying BTC, ETH, and other prices live in lovelace.

We have plans to create an HA custom component, but that didn't make cut before launch. I don't expect many HA users to sign up for our paid plans, so even though it will cost us more we'd love to see more HA users using our free service. If there is demand for a high-performance, reliable, cryptocurrency data source for HA, just let us know and I can get our team to make the HA custom component a priority.

EDIT: Now with a custom component! Due to a lot of demand after we posted this, one of our engineers built a custom component. It is currently available at https://github.com/BitFetch/bitfetch-home-assistant and can be installed via HACS. We would love to see this get supported natively in HA one day.

BitFetch API Documentation: https://docs.bitfetch.io
BitFetch Website & Plan Info: https://bitfetch.io

Was this page helpful?
0 / 5 - 0 ratings

Related issues

missedtheapex picture missedtheapex  Â·  3Comments

ofuangka picture ofuangka  Â·  3Comments

MartinHjelmare picture MartinHjelmare  Â·  3Comments

arangates picture arangates  Â·  3Comments

i-am-shodan picture i-am-shodan  Â·  3Comments