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
How to get historical currency pair data from a start date to end date? #70
Comments
Hi! I don't know if this can be done automatically, but you could write a loop where the day will be set automatically and the currency will be calculated. |
Hi, is this issue still open ? |
As an attempt off the top of my head (and with a bit of help from Stackoverflow): from datetime import datetime
from datetime import timedelta, date
from forex_python.converter import CurrencyRates
def daterange(start_date, end_date):
for n in range(int((end_date - start_date).days)):
yield start_date + timedelta(n)
c = CurrencyRates()
start_date = date(2018, 5, 1)
end_date = date(2019, 5, 5)
for single_date in daterange(start_date, end_date):
date_obj = datetime.combine(single_date, datetime.min.time())
value = c.get_rate('USD', 'INR', date_obj)
print(single_date.strftime('%Y-%m-%d:'), value) Please note that this will not be kind on API rates, so either:
|
I was thinking along those lines, and the solution I was thinking to the API calls is after every say 5 or10 iterations (just throwing numbers out there) rest for about 2 seconds: `from datetime import datetime, date def get_rate_history(self, base_cur, dest_cur, date_start, date_end):
|
This would be a great feature! |
I want historical data from 2018-05-01 to 2019-05-05 of USD/INR pair. How can I do it with forex-python?
The text was updated successfully, but these errors were encountered: