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

Implement Cryptocompare API to fetch exchange rates #658

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

eloyesp
Copy link

@eloyesp eloyesp commented Dec 22, 2020

This should close #627 and might also help to close #613, because cryptocompare does not use cloudflare.

This implementation requires hard-coding the fiat currencies (the api cannot send you all the fiat rates) and it does require all the rates every time to keep the compatibility with CoinGecko implementation.

Also, the second commit does replace the implementation without adding any selector for the user, but I'm not sure how to implement that. This is my first commit on java, so there might be a lot of things to fix, so comments and improvements are welcome.

That said, I've tested it for a while, and I'm very happy with it. And the exchange rate for ARS is fixed (no more the ridiculous rate provided by coingecko).

An option could be added for the user to select the preference, but
cryptocompare does work better for most users.
@eloyesp
Copy link
Author

eloyesp commented Jan 12, 2021

@schildbach Any feedback about this? This change is very important for us to promote bitcoin (and crypto in general) in Argentina (and I suppose that also in other countries without free access to USD).

@eloyesp
Copy link
Author

eloyesp commented Jan 23, 2021

@schildbach any feedback about this would be appreciated. I know the code is not great, but I've just learned Java to write this. :)

@kzu
Copy link

kzu commented Mar 3, 2021

This looks like a good addition, I'd like to see it merged (being from Argentina too) :)

@eloyesp
Copy link
Author

eloyesp commented Sep 5, 2021

Any feedback on this?

Copy link
Collaborator

@schildbach schildbach left a comment

Choose a reason for hiding this comment

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

Generally the parsing code looks good. However we're missing some kind of source selection, or merging of result data. I don't want to forcibly disable CoinGecko for everyone.

* @author Eloy Espinaco
*/
public final class CryptoCompare {
private static final HttpUrl URL = HttpUrl.parse("https://min-api.cryptocompare.com/data/price?fsym=BTC&tsyms=usd,aed,ars,aud,bdt,bhd,bmd,brl,cad,chf,clp,cny,czk,dkk,eur,gbp,hkd,huf,idr,ils,inr,jpy,krw,kwd,lkr,mmk,mxn,myr,ngn,nok,nzd,php,pkr,pln,rub,sar,sek,sgd,thb,try,twd,uah,vef,vnd,zar,xdr&extraParams=bitcoinwallet");
Copy link
Collaborator

Choose a reason for hiding this comment

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

What's the meaning of the extraParams=bitcoinwallet?

Copy link
Author

Choose a reason for hiding this comment

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

It's just an optional param to let cryptocompare make stats.

for (Map.Entry<String, String> entry : rates.entrySet()) {
final String symbol = entry.getKey().toUpperCase(Locale.US);
try {
final Fiat rate = Fiat.parseFiatInexact(symbol, entry.getValue());
Copy link
Collaborator

Choose a reason for hiding this comment

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

The formatting is off a bit here. Please use 4 spaces per indent level.

import static org.junit.Assert.assertEquals;

/**
* @author Andreas Schildbach
Copy link
Collaborator

Choose a reason for hiding this comment

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

I assume you want to use yourself as the author here, rather than me?

Copy link
Author

Choose a reason for hiding this comment

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

Most of this code is actually yours, as I've used a removed version as the source and modified it... but I can add myself if you think so.

@schildbach
Copy link
Collaborator

Seems like they want to phase out their public API (without API key): https://cryptocompare.zendesk.com/hc/en-gb/articles/360013348454-What-will-happen-to-the-existing-free-public-API-

@eloyesp
Copy link
Author

eloyesp commented Sep 6, 2021

No, they already made clear that they will not drop support, just IP rate limit it, that will have no impact on the wallet, as the wallet make requests from different IPs for each user.

We will continue to support our existing public API, with IP rate limits. However, its support and limits will be reviewed and reduced over time as we slowly get people to switch to using API keys. Open source and free products will always have a generous IP rate-limited service as well — but the limits will be lower than using a free key. As such we recommend our public API users to switch to a free or commercial API plan for a more secure and scalable service. source POST

Do I need to pay for the API or can I use it for free?
We offer our API-service under a Creative Commons - Attribution Non-Commercial license.
This means that it’s free as long as you attribute it to us and you are not making money from the data. If you are selling a product that uses our data we charge a fee.
The idea is that if you start making a lot of money using our data, we would like something in return. If you are just providing a free service, you can use our data freely.
Please make sure you credit us with a link if you use our data on your website or app. There is a paid service which grants higher rate limits, more data and different usage rights. source FAQ

So it seems that cryptocompare API can be used without issues.

@eloyesp
Copy link
Author

eloyesp commented Sep 6, 2021

Generally the parsing code looks good. However we're missing some kind of source selection, or merging of result data. I don't want to forcibly disable CoinGecko for everyone.

It would be great to have a selector, but I'm not able to implement that myself.

@bitcoin-wallet bitcoin-wallet deleted a comment from RolandTMJ Jan 26, 2022
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.

Use cryptocompare as exchange rate source Bitcoin wallet doesn't fetch exchange rates
5 participants