Ich versuche, oanda historische Preise für EURUSD zu bekommen. Ich versuche, die letzten 5000. zu bekommen, aber ich empfange nur 180.Kann Oanda historische Preise nicht erhalten
Dies ist mein Code:
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)
Aber df_data hat nur 180 Zeilen, nicht 5000.
[180 rows x 7 columns]
Wie kann ich das beheben?
können Sie versuchen, die Anforderung zu machen Ich habe auf Oanda API? Ich habe bereits eine E-Mail an sie gesendet, aber sie antworten mir nicht –
Buchen Sie einfach die Anfrage selbst und das Ergebnis in Ihrer Frage. Nicht all dieser zusätzliche Code, der nicht relevant ist. –