Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

use CoinGecko instead of CoinMarketcap for exchange rates #2610

Merged
merged 19 commits into from
Sep 2, 2019

Conversation

ayrat555
Copy link
Contributor

CoinMarketcap deprecated and took offline its v1 API. They have
v2 API which has a free plan and requires API keys. But as part of
#234 we already
implemented fetching from CoinGecko.

Now, coin id should be set for CoinGecko for the required coin.

config :explorer, Explorer.ExchangeRates.Source.CoinGecko,
  coin_id: System.get_env("COIN_GECKO_ID", "poa-network")

Or the COIN_GECKO_ID env var should be set. For example, COIN_GECKO_ID=poa-network

fixes #2579

Changelog

  • use CoinGecko instead of CoinMarketcap for exchange rates

CoinMarketcap deprecated and took offline its v1 API. They have
v2 API which has free plan and requires API keys. But as part of
#234 we alresy
implemented fetching from CoinGecko.

Now, coin id should be set for CoinGecko for the required coin.
```
config :explorer, Explorer.ExchangeRates.Source.CoinGecko,
  coin_id: System.get_env("COIN_GECKO_ID", "poa-network")
```
Or the `COIN_GECKO_ID` env var should be set. For example, COIN_GECKO_ID=poa-network
@coveralls
Copy link

coveralls commented Aug 21, 2019

Pull Request Test Coverage Report for Build f5294a8b-3d7c-43e2-bba0-b1a459720715

  • 12 of 16 (75.0%) changed or added relevant lines in 5 files are covered.
  • 1 unchanged line in 1 file lost coverage.
  • Overall coverage increased (+0.05%) to 78.818%

Changes Missing Coverage Covered Lines Changed/Added Lines %
apps/block_scout_web/lib/block_scout_web/views/chain_view.ex 1 2 50.0%
apps/explorer/lib/explorer/exchange_rates/source/token_bridge.ex 2 3 66.67%
apps/explorer/lib/explorer/exchange_rates/source/coin_gecko.ex 5 7 71.43%
Files with Coverage Reduction New Missed Lines %
apps/block_scout_web/lib/block_scout_web/views/chain_view.ex 1 25.0%
Totals Coverage Status
Change from base Build 980ef580-9796-4557-8088-71e40cd46204: 0.05%
Covered Lines: 5120
Relevant Lines: 6496

💛 - Coveralls

Copy link
Member

@vbaranov vbaranov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ayrat555

did you try with export COIN_GECKO_ID=ethereum ?

Screenshot 2019-08-22 at 00 43 32

@ayrat555
Copy link
Contributor Author

@vbaranov it was json decoding issue. fixed

@vbaranov vbaranov self-requested a review August 22, 2019 17:48
Copy link
Member

@vbaranov vbaranov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ayrat555 it works in case of Ethereum now. However,

  1. If I export COIN_GECKO_ID=poa-network charts are ampty, price and marcet cap are 0
  2. The solution is not compatible with COINMARKETCAP_PAGES ENV var. RSK market cap chart is broken

@ayrat555
Copy link
Contributor Author

@vbaranov

  1. It works for me. Along with COIN_GECKO_ID, COIN env var should be set
  2. correct id can be found here https://api.coingecko.com/api/v3/coins/list

@vbaranov vbaranov self-requested a review August 27, 2019 09:51
Copy link
Member

@vbaranov vbaranov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ayrat555

I see the different values on chart hover and at the bottom:

Screenshot 2019-08-27 at 12 50 26

And also it doesn't correlate with the data from API:

https://api.coingecko.com/api/v3/coins/markets?vs_currency=usd&ids=poa-network&order=market_cap_desc&per_page=100&page=1&sparkline=false

[
  {
    "id": "poa-network",
    "symbol": "poa",
    "name": "POA Network",
    "image": "https://assets.coingecko.com/coins/images/3157/large/poa-network.png?1548331565",
    "current_price": 0.01555225,
    "market_cap": 3424101,
    "market_cap_rank": 470,
    "total_volume": 134238,
    "high_24h": 0.01670786,
    "low_24h": 0.01545265,
    "price_change_24h": -0.00056939,
    "price_change_percentage_24h": -3.53183,
    "market_cap_change_24h": -123209.85896952,
    "market_cap_change_percentage_24h": -3.47333,
    "circulating_supply": 220167621,
    "total_supply": 252193195,
    "ath": 0.935923,
    "ath_change_percentage": -98.33653,
    "ath_date": "2018-05-10T09:45:31.809Z",
    "roi": null,
    "last_updated": "2019-08-27T09:46:28.885Z"
  }
]

correct id can be found here https://api.coingecko.com/api/v3/coins/list

Sure thing, but why do we need that ENV var if we use another api provider now?

@ayrat555
Copy link
Contributor Author

@vbaranov https://api.coingecko.com/api/v3/coins/poa-network is used for exchange data and market cap. Locally, I don't see this issue. How can I reproduce it?

| `TXS_COUNT_CACHE_PERIOD` | | Interval in seconds to restart the task, which calculates the total txs count. | 60 * 60 * 2 | v1.3.9+ | | |
| `ADDRESS_WITH_BALANCES` <br /> `_UPDATE_INTERVAL`| | Interval in seconds to restart the task, which calculates addresses with balances. | 30 * 60 | v1.3.9+ | | |
| `LINK_TO_OTHER_EXPLORERS` | | true/false. If true, links to other explorers are added in the footer | (empty) | v1.3.0+ | | |
| `COINMARKETCAP_PAGES` | | the number of pages on coinmarketcap to list in order to find token's price | 10 | v1.3.10+ | | master |
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ayrat555 let's remove?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added deprecated in version - master.

docs/env-variables.md Outdated Show resolved Hide resolved
@vbaranov
Copy link
Member

vbaranov commented Aug 28, 2019

@ayrat555

Locally, I don't see this issue. How can I reproduce it?

I still see this issue:

Screenshot 2019-08-28 at 20 24 19

Why is the difference? Just start this branch for POA chain instance

@ayrat555
Copy link
Contributor Author

ayrat555 commented Sep 2, 2019

@vbaranov I fixed a market cap calculation

@vbaranov vbaranov self-requested a review September 2, 2019 07:44
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.

CoinMarketCap API is Deprecated
5 participants