自动更新GET请求python

自动更新GET请求python,python,refresh,Python,Refresh,我有一个汇率要求,我想每秒钟更新一次。现在我必须重新加载程序以刷新速率。我将如何在Python中执行此操作 如有任何帮助,我们将不胜感激,提前谢谢 脚本: import oandapy oanda = oandapy.API(environment="practice", access_token="xxxxxxxxxxxx") response = oanda.get_prices(instruments="EUR_USD") prices = response.get("prices")

我有一个汇率要求,我想每秒钟更新一次。现在我必须重新加载程序以刷新速率。我将如何在Python中执行此操作

如有任何帮助,我们将不胜感激,提前谢谢

脚本:

import oandapy

oanda = oandapy.API(environment="practice", access_token="xxxxxxxxxxxx")

response = oanda.get_prices(instruments="EUR_USD")
prices = response.get("prices")
asking_price = prices[0].get("ask")

stop = asking_price - .001
根据答复:

while True:
    response = oanda.get_prices(instruments="EUR_USD")
    prices = response.get("prices")
    asking_price = prices[0].get("ask")

    stop = asking_price - .001

time.sleep(1)

一般的方法是将整个内容包装在一个无限循环中,并在请求之间等待:

while True:
    # ... do and print request
    time.sleep(1) # then wait one second
确保API访问令牌允许每秒发送一次请求



然而,在快速搜索之后,我发现您使用的API支持流式传输速率:

我实际上也在使用它,但是,我在解析流时遇到了极大的困难,无法给出一个可以用于可变止损价格的速率。谢谢你的帮助!我现在正在尝试这似乎是可行的,但是,我得到了以下错误:oandapy.OandaError:OANDA API返回错误代码68(违反新建立连接的速率限制。允许速率:每秒2个连接)如何限制请求?谢谢again@user2883183增加请求之间的睡眠时间。无论我将其设置为什么,我仍然会得到相同的错误。。我想这回答了我的问题。谢谢你的帮助!