I’m trying to read the TradesHistory from krakenn but it doesn’t work with the index. It only works if I enter the right trade. How can I step through each individual trade individually?
With the following command I get all the trades. It works.
print(resp.json()['result']['trades'])
If I wanted to access the first index now, it doesn’t work.
print(resp.json()['result']['trades'][0]['ordertxid'])
Only after entering the correct trade id can I access the following index.
print(resp.json()['result']['trades']['12345-abcde-ZYXWE']['ordertxid'])
What am I doing wrong? How can I access the correct index without first knowing the ID?
{
"error":[
],
"result":{
"count":2,
"trades":{
"12345-abcde-ZYXWE":{},
"ZYXWE-12345-abcde":{
"ordertxid":"xyz",
}
}
}
}
various Python index commands with different JSON formats
2
Answers
In order to go over all the trades, you can loop over the trades that were made and extract their information.
You can use a
for
loop like this:I tried with this code below it is working.
And looking at your code it looks like you are referring to wrong index here [‘12345-abcde-ZYXWE’]