python
1from oandapyV20 import API 2from oandapyV20.exceptions import V20Error 3from oandapyV20.endpoints.pricing import PricingStream 4import oandapyV20.endpoints.orders as orders 5import oandapyV20.endpoints.instruments as instruments 6 7import json 8import datetime 9import pandas as pd 10from dateutil.relativedelta import relativedelta 11 12 13 14accountID = "xxxxxxxxx" 15access_token = 'xxxxxxxxxxxxxxxx' 16api = API(access_token=access_token, environment="practice") 17year_months =[ 18 [2016, 1], [2016, 2], [2016, 3], [2016, 4], [2016, 5], [2016, 6], [2016, 7], [2016, 8], [2016, 9], [2016, 10], [2016, 11], [2016, 12], 19 [2017, 1], [2017, 2], [2017, 3], [2017, 4], [2017, 5], [2017, 6], [2017, 7], [2017, 8], [2017, 9], [2017, 10], [2017, 11], [2017, 12], 20 [2018, 1], [2018, 2], [2018, 3], [2018, 4], [2018, 5], [2018, 6], [2018, 7], [2018, 8], [2018, 9], [2018, 10], [2018, 11], [2018, 12], 21 [2019, 1], [2019, 2], [2019, 3], [2019, 4], [2019, 5], [2019, 6], [2019, 7], 22] 23def getCandleDataFromOanda(instrument, api, date_from, date_to, granularity): 24 params = { 25 "from": date_from.isoformat(), 26 "to": date_to.isoformat(), 27 "granularity": granularity, 28 } 29 r = instruments.InstrumentsCandles(instrument=instrument, params=params) 30 return api.request(r) 31def oandaJsonToPythonList(JSONRes): 32 data = [] 33 for res in JSONRes['candles']: 34 data.append( [ 35 datetime.datetime.fromisoformat(res['time'][:19]), 36 res['volume'], 37 res['mid']['o'], 38 res['mid']['h'], 39 res['mid']['l'], 40 res['mid']['c'], 41 ]) 42 return data 43 44all_data = [] 45# year, monthでループ 46for year, month in year_months: 47 date_from = datetime.datetime(year, month, 1) 48 date_to = date_from + relativedelta(months=+1, day=1) 49 50 ret = getCandleDataFromOanda("USD_JPY", api, date_from, date_to, "M10") 51 month_data = oandaJsonToPythonList(ret) 52 53 all_data.extend(month_data)
AttributeError Traceback (most recent call last) <ipython-input-14-9bc35c928779> in <module>() 7 8 ret = getCandleDataFromOanda("USD_JPY", api, date_from, date_to, "M10") ----> 9 month_data = oandaJsonToPythonList(ret) 10 11 all_data.extend(month_data) <ipython-input-13-1597f262619e> in oandaJsonToPythonList(JSONRes) 3 for res in JSONRes['candles']: 4 data.append( [ ----> 5 datetime.datetime.fromisoformat(res['time'][:19]), 6 res['volume'], 7 res['mid']['o'], AttributeError: type object 'datetime.datetime' has no attribute 'fromisoformat'
すいません、結局原因がわからなかったので回答お願いします。
アカウントIDやトークンなどは念の為、消しています。
google colabを使用しています。
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2021/01/08 14:26