外汇交易算法无法正常工作

时间:2019-04-27 07:56:39

标签: python algorithm trading forex

您好,我正在尝试使用OANDA API实现外汇交易算法。我在OANDA中创建了一个帐户,并生成了密钥。

在执行以下代码时,我没有发现任何错误,但是似乎未获取数据。

"""
The main file that will evolve into our trading library
"""
from datetime import datetime, timedelta
import v20


OANDA_ACCESS_TOKEN = ""
OANDA_ACCOUNT_ID = '' #put your access id here 

def main():
    print("------ System online -------", datetime.now())
    latest_price_time = (datetime.utcnow() - timedelta(seconds=15)).isoformat('T')+'Z'

    api = v20.Context(
            'api-fxpractice.oanda.com',
            '443',
            token=OANDA_ACCESS_TOKEN)

    response = api.pricing.get(
                    OANDA_ACCOUNT_ID,
                    instruments='EUR_USD',
                    since=latest_price_time,
                    includeUnitsAvailable=False)

    print(response)

    prices = response.get("prices", 200)
    print (prices)
    if len(prices):
        buy_price = prices[0].bids[0].price 

        print("Buy at " + str(buy_price))

        response = api.order.market(
            OANDA_ACCOUNT_ID,
            instrument='EUR_USD',
            units=5000)

        print("Trading id: " + str(response.get('orderFillTransaction').id))
        print("Account Balance: " + str(response.get('orderFillTransaction').accountBalance))
        print("Price: " + str(response.get('orderFillTransaction').price))

    else:
        print(response.reason)

if __name__ == "__main__":
    main()

这是我收到的输出。

  

------系统在线------- 2019-04-27 13:08:32.531057方法=获取路径=   https://api-fxpractice.oanda.com:443/v3/accounts/101-011-11099167-001/pricing?instruments=EUR_USD&since=2019-04-27T07%3A38%3A17.531057Z&includeUnitsAvailable=False状态= 200原因=确定内容类型= application / json

     

[]好

但是当访问上述路径时,我收到以下错误。

enter image description here

0 个答案:

没有答案