I'm trying to understand forex API through python.The code that I am posting below worked for me on friday and I received all the conversion rates for the dates as desired. Strangely when I run the code today for some reason it says
Currency Rates source not ready.
Why is this happening?
from forex_python.converter import CurrencyRates
import pandas as pd
c = CurrencyRates()
from forex_python.converter import CurrencyRates
c = CurrencyRates()
df = pd.DataFrame(pd.date_range(start='8/16/2021 10:00:00', end='8/22/2021 11:00:00', freq='600min'), columns=['DateTime'])
def get_rate(x):
try:
op = c.get_rate('CAD', 'USD', x)
except Exception as re:
print(re)
op=None
return op
df['Rate'] = df['DateTime'].apply(get_rate)
Currency Rates Source Not Ready
Currency Rates Source Not Ready
df
Out[17]:
DateTime Rate
0 2021-08-16 10:00:00 0.796374
1 2021-08-16 20:00:00 0.796374
2 2021-08-17 06:00:00 0.793031
3 2021-08-17 16:00:00 0.793031
4 2021-08-18 02:00:00 0.792469
5 2021-08-18 12:00:00 0.792469
6 2021-08-18 22:00:00 0.792469
7 2021-08-19 08:00:00 0.783967
8 2021-08-19 18:00:00 0.783967
9 2021-08-20 04:00:00 0.774504
10 2021-08-20 14:00:00 0.774504
11 2021-08-21 00:00:00 NaN
12 2021-08-21 10:00:00 NaN
13 2021-08-21 20:00:00 NaN
14 2021-08-22 06:00:00 NaN
How do I fix this issue? Is there a way to ignore NaN while making calls itself? I feel that the API only gives results for Monday to Friday from 10 am to 5pm. So is there a way to just get those results.
from Strange 'Currency Rates source not ready' forex_python error
No comments:
Post a Comment