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

Add CoinbaseRateProvider implementation to address issue #3 #42

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

Conversation

sernamar
Copy link

@sernamar sernamar commented Sep 6, 2024

This PR introduces the CoinbaseRateProvider class, addressing the issue raised in issue #3, which highlights the need for new ExchangeRateProvider implementations following the discontinuation of MtGox.


This change is Reviewable


private void loadSupportedCurrencies() {
try {
HttpClient httpClient = HttpClient.newHttpClient();
Copy link
Member

Choose a reason for hiding this comment

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

We should probably check if the httpClient is an instance of AutoCloseable and if so #close() it.See JDK-8304165

Copy link
Author

@sernamar sernamar Sep 9, 2024

Choose a reason for hiding this comment

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

Thank you for the feedback! After your suggestion, I considered using a try-with-resources construct to close the connection. However, while reviewing this issue, I realized that java.net.http.HttpClient is not supported in JDK 8, which is the version we’re using for this project.

Rather than upgrading the JDK version, we can switch to Apache HttpClient, which is compatible with JDK 8 and provides similar functionality. CloseableHttpClient in Apache HttpClient implements AutoCloseable, allowing us to use the try-with-resources construct for proper resource management.

I've added a new commit with these changes.

JsonNode dataNode = jsonNode.get("data");
dataNode.forEach(node -> supportedCurrencies.add(node.get("id").asText()));
} catch (IOException | InterruptedException e) {
log.severe("Failed to load supported currencies from Coinbase API: " + e.getMessage());
Copy link
Member

Choose a reason for hiding this comment

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

The current code throws a MonetaryException, it may be worth considering keeping this behavior.

Copy link
Author

Choose a reason for hiding this comment

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

Sure! I've kept the MonetaryException behavior as suggested.

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.

2 participants