我正在尝试理解如何使用从de Kraken API获得的json返回。
这是我的代码:
resp = kraken_request("/0/private/TradeBalance", {
"nonce": str(int(10000*time.time())),
"asset": "USD"
}, api_key, api_sec)
print("TradeBalance: " + str(resp.json()))
resp = kraken_request("/0/private/OpenOrders", {
"nonce": str(int(10000*time.time())),
"asset": "USD"
}, api_key, api_sec)
print()
print("OpenOrders: " + str(resp.json())
这是我的json返回(编辑过,所以它不是真实的数据):
{"error":[],"result":{"open":{"ABCDE-AWSCG-ABCDE":{"refid":null,"userref":0,"status":"open","opentm":1666683580.8848298,"starttm":0,"expiretm":0,"descr":{"pair":"LINKEUR","type":"sell","ordertype":"limit","price":"8.70000","price2":"0","leverage":"none","order":"sell 1.00000000 LINKEUR @ limit 8.70000","close":""},"vol":"1.00000000","vol_exec":"0.00000000","cost":"0.000000","fee":"0.000000","price":"0.000000","stopprice":"0.000000","limitprice":"0.000000","misc":"","oflags":"fcib"},"ABCDE-AHKEK-ABCDE":{"refid":null,"userref":0,"status":"open","opentm":1666683548.8137474,"starttm":0,"expiretm":0,"descr":{"pair":"LINKEUR","type":"sell","ordertype":"limit","price":"8.60000","price2":"0","leverage":"none","order":"sell 1.00000000 LINKEUR @ limit 8.60000","close":""},"vol":"1.00000000","vol_exec":"0.00000000","cost":"0.000000","fee":"0.000000","price":"0.000000","stopprice":"0.000000","limitprice":"0.000000","misc":"","oflags":"fcib"},"ABCDE-POQX7-ABCDE":{"refid":null,"userref":0,"status":"open","opentm":1666683517.207053,"starttm":0,"expiretm":0,"descr":{"pair":"LINKEUR","type":"sell","ordertype":"limit","price":"8.50000","price2":"0","leverage":"none","order":"sell 1.00000000 LINKEUR @ limit 8.50000","close":""},"vol":"1.00000000","vol_exec":"0.00000000","cost":"0.000000","fee":"0.000000","price":"0.000000","stopprice":"0.000000","limitprice":"0.000000","misc":"","oflags":"fcib"},"ABCDE-UADOV-ABCDE":{"refid":null,"userref":0,"status":"open","opentm":1666683490.4299977,"starttm":0,"expiretm":0,"descr":{"pair":"LINKEUR","type":"sell","ordertype":"limit","price":"8.40000","price2":"0","leverage":"none","order":"sell 1.00000000 LINKEUR @ limit 8.40000","close":""},"vol":"1.00000000","vol_exec":"0.00000000","cost":"0.000000","fee":"0.000000","price":"0.000000","stopprice":"0.000000","limitprice":"0.000000","misc":"","oflags":"fcib"},"ABCDE-ABCDE-2JGH3M":{"refid":null,"userref":0,"status":"open","opentm":1666646615.668582,"starttm":0,"expiretm":0,"descr":{"pair":"LINKEUR","type":"sell","ordertype":"limit","price":"8.30000","price2":"0","leverage":"none","order":"sell 1.00000000 LINKEUR @ limit 8.30000","close":""},"vol":"1.00000000","vol_exec":"0.00000000","cost":"0.000000","fee":"0.000000","price":"0.000000","stopprice":"0.000000","limitprice":"0.000000","misc":"","oflags":"fciq"},"ABCDE-623OO-ABCDE":{"refid":null,"userref":0,"status":"open","opentm":1666646572.9639573,"starttm":0,"expiretm":0,"descr":{"pair":"LINKEUR","type":"sell","ordertype":"limit","price":"8.20000","price2":"0","leverage":"none","order":"sell 1.00000000 LINKEUR @ limit 8.20000","close":""},"vol":"1.00000000","vol_exec":"0.00000000","cost":"0.000000","fee":"0.000000","price":"0.000000","stopprice":"0.000000","limitprice":"0.000000","misc":"","oflags":"fciq"},"ABCDE-4EHBG-ABCDE":{"refid":null,"userref":0,"status":"open","opentm":1666646537.55891,"starttm":0,"expiretm":0,"descr":{"pair":"LINKEUR","type":"sell","ordertype":"limit","price":"8.10000","price2":"0","leverage":"none","order":"sell 1.00000000 LINKEUR @ limit 8.10000","close":""},"vol":"1.00000000","vol_exec":"0.00000000","cost":"0.000000","fee":"0.000000","price":"0.000000","stopprice":"0.000000","limitprice":"0.000000","misc":"","oflags":"fciq"},"ABCDE-SPHMF-ABCDE":{"refid":null,"link_id":"ABCDE-YWJVW-ABCDE","userref":0,"status":"open","opentm":1666646453.770994,"starttm":0,"expiretm":0,"descr":{"pair":"LINKEUR","type":"sell","ordertype":"limit","price":"7.99900","price2":"0","leverage":"none","order":"sell 1.00000000 LINKEUR @ limit 7.99900","close":""},"vol":"1.00000000","vol_exec":"0.00000000","cost":"0.000000","fee":"0.000000","price":"0.000000","stopprice":"0.000000","limitprice":"0.000000","misc":"","oflags":"fcib"},"ABCDE-RVWQO-ABCDE":{"refid":null,"userref":0,"status":"open","opentm":1663311467.0131989,"starttm":0,"expiretm":0,"descr":{"pair":"ETHWUSD","type":"sell","ordertype":"limit","price":"1000.000","price2":"0","leverage":"none","order":"sell 357.00000000 ETHWUSD @ limit 1000.000","close":""},"vol":"357.00000000","vol_exec":"0.00000000","cost":"0.0000000","fee":"0.0000000","price":"0.0000000","stopprice":"0.0000000","limitprice":"0.0000000","misc":"","oflags":"fcib"}}}}
现在我还不知道如何使用这个json,我想仔细检查一下,并处理每个项目,如“ABCDE-AWSCG-ABCDE”和“ABCDE-POQX 7-ABCDE”等,对于每个项目的所有底层信息,我不知道如何操作。请注意,我事先不知道项目名称,如“ABCDE-AWSCG-ABCDE”。
1条答案
按热度按时间rjjhvcjd1#
你应该使用pandas。你可以在一个表中看到所有的数据。这比用json工作要容易得多。