Forex-python“货币汇率未准备就绪”

时间:2017-08-22 11:18:56

标签: python pandas currency

我想使用Forex-python模块根据特定日期(根据数据框中的日期,上个月的最后一天)将各种货币的金额转换为特定货币(“DKK”)

这是我的代码的结构:

Console.WriteLine("Your branch is ahead of '{0}' by {1} commits and behind by {2} commits.",
    branch.TrackingBranch.CanonicalName,
    branch.TrackingDetails.AheadBy,
    branch.TrackingDetails.BehindBy);

和换算量的新列:

pd.DataFrame(data={'Date':['2017-4-15','2017-6-12','2017-2-25'],'Amount':[5,10,15],'Currency':['USD','SEK','EUR']})

def convert_rates(amount,currency,PstngDate):
    PstngDate = datetime.strptime(PstngDate, '%Y-%m-%d')
    if currency != 'DKK':
        return c.convert(base_cur=currency,dest_cur='DKK',amount=amount \
                     ,date_obj=PstngDate - timedelta(PstngDate.day))
    else:
        return amount

我收到RatesNotAvailableError“货币汇率未准备好” 知道是什么原因引起的吗?它之前曾处理过少量数据,但我的真实df中有很多行...

1 个答案:

答案 0 :(得分:0)

来自:https://github.com/MicroPyramid/forex-python/blob/80290a2b9150515e15139e1a069f74d220c6b67e/forex_python/converter.py#L73

您的错误表示图书馆收到了您的请求的非200响应代码。这可能意味着该网站已关闭,或者它暂时阻止了您,因为您正在通过请求进行锤击。

尝试将调用替换为c.convert,例如:

from time import sleep
def try_convert(amount, currency, PstngDate):
    success = False
    while success == False:
        try:
            res = c.convert(base_cur=currency,dest_cur='DKK',amount=amount \
                     ,date_obj=PstngDate - timedelta(PstngDate.day))
        except:
            #wait a while
            sleep(10)
    return res

甚至更好,使用像退避这样的库来为你重试:

https://pypi.python.org/pypi/backoff/1.3.1