-
Notifications
You must be signed in to change notification settings - Fork 197
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
Added new forex provider to fix "Currency Rates Source Not Ready" #127
base: master
Are you sure you want to change the base?
Conversation
fixes #126 |
forex_python/converter.py
Outdated
|
||
def _get_date_string(self, date_obj): | ||
if date_obj is None: | ||
return 'latest' | ||
date_str = date_obj.strftime('%Y-%m-%d') | ||
return date_str | ||
|
||
def _decode_rates(self, response, use_decimal=False, date_str=None): | ||
def _decode_rates(self, response, use_decimal=False, date_str=None,base_cur=None): |
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.
Missing sapce before ,
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.
fixed
forex_python/converter.py
Outdated
@@ -57,7 +59,7 @@ def get_rates(self, base_cur, date_obj=None): | |||
source_url = self._source_url() + date_str | |||
response = requests.get(source_url, params=payload) | |||
if response.status_code == 200: | |||
rates = self._decode_rates(response, date_str=date_str) | |||
rates = self._decode_rates(response,date_str=date_str,base_cur=base_cur) |
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.
Missing sapce before ,
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.
fixed
@@ -25,21 +25,23 @@ def __init__(self, force_decimal=False): | |||
self._force_decimal = force_decimal | |||
|
|||
def _source_url(self): | |||
return "https://theforexapi.com/api/" | |||
return "https://api.exchangerate.host/" |
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.
why not allow specying source url as parameter?
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.
Most apis are not going to be this similar in terms of api surface. This one is 95% there so still requires minor changes. I don't think having the provider url as a parameter makes sense unless theforexapi.com comes back online again.
If supporting multiple apis is required there needs to be some refactoring to abstract the api provider from the currency class.
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.
It makes sense, you can host your own api since theforexapi is open source, there should be an option to override the url...
Added forex provider (exchangerate.host) which is almost a 1to1 replacement for the old theforexapi.com.
Added a check to throw if a currency is not available since new provider always returns 200
All unit tests for converter.py are working a part from test_with_valid_currency_code which looks to be broken because the included json file doesn't contain the expected symbol.