我試圖讓OANDA的歷史價格爲歐元兌美元。我試圖讓過去的5000,但我只收到180無法獲取OANDA歷史價格
這是我的代碼:
def get_data_oanda(num_periods, **keyword_parameters):
"""
Environment Description
fxTrade (Live) The live (real money) environment
fxTrade Practice (Demo) The demo (simulated money) environment
"""
domainDict = { 'live' : 'api-fxtrade.oanda.com','demo' : 'api-fxpractice.oanda.com' }
environment = 'demo'
domain = domainDict[environment]
access_token = 'xxxx'
account_id = 'xxxx'
instruments = 'EUR_USD'
count = num_periods
granularity = "M1"
try:
s = requests.Session()
url = "https://" + domain + "/v1/candles"
headers = {'Authorization' : 'Bearer ' + access_token,
# 'X-Accept-Datetime-Format' : 'unix'
}
params = {'instrument' : instruments, 'accountId' : account_id, 'count' : count, 'granularity' : granularity}
req = requests.Request('GET', url, headers = headers, params = params)
pre = req.prepare()
resp = s.send(pre, stream = True, verify = True)
return resp
except Exception as e:
s.close()
print()
print("Caught exception when connecting to stream\n" + str(e))
num_periods = 5000
my_date = datetime.datetime.now(pytz.timezone('America/Sao_Paulo')).strftime('%Y-%m-%dT%H:%M:%S')
timezone = 'America/Sao_Paulo'
response = get_data_oanda(num_periods)
msg = json.loads(response.text)
candles = msg['candles']
for candle in candles:
df_data = df_data.append({
'date': datetime.datetime.strptime(candle['time'], '%Y-%m-%dT%H:%M:%S.000000Z').replace(tzinfo=pytz.utc).astimezone(local_tz).strftime('%Y-%m-%d %H:%M:%S'),
'instrument': msg['instrument'],
"open": candle['openAsk'],
"high": candle['highAsk'],
"low": candle['lowAsk'],
"close": candle['closeAsk'],
"volume": candle['volume']
},ignore_index=True)
但df_data只有180行,而不是5000
[180 rows x 7 columns]
我該如何解決這個問題?
你可以嘗試讓請求我在Oanda API上做過?我已經發了封郵件給他們,但他們沒有回答我 –
發佈該請求本身,結果在你的問題。不是所有這些不相關的額外代碼。 –