- 
                Notifications
    You must be signed in to change notification settings 
- Fork 5
Add CoinbaseRateProvider implementation to address issue #3 #42
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
base: main
Are you sure you want to change the base?
Conversation
|  | ||
| private void loadSupportedCurrencies() { | ||
| try { | ||
| HttpClient httpClient = HttpClient.newHttpClient(); | 
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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()); | 
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
This PR introduces the
CoinbaseRateProviderclass, addressing the issue raised in issue #3, which highlights the need for newExchangeRateProviderimplementations following the discontinuation of MtGox.This change is