我正在尝试访问api并从所有订单中提取唯一ID和价格
{'message': '', 'success': True, 'result': [{'Limit': 5.76e-06, 'PricePerUnit': 5.76e-06, 'Closed': '2018-04-05T06:44:11.63', 'Quantity': 910.0, 'Price': 0.0052416, 'Condition': 'NONE', 'IsConditional': False, 'ImmediateOrCancel': False, 'ConditionTarget': None, 'OrderType': 'LIMIT_SELL', 'TimeStamp': '2018-04-05T06:44:11.38', 'Exchange': 'BTC-TRX', 'Commission': 1.31e-05, 'OrderUuid': '139858b6-d47a-4734-bb1f-a5d11b3fd203', 'QuantityRemaining': 0.0}, {'Limit': 4.9e-06, 'PricePerUnit': 4.9e-06, 'Closed': '2018-03-31T17:29:04.68', 'Quantity': 120.0, 'Price': 0.000588, 'Condition': 'NONE', 'IsConditional': False, 'ImmediateOrCancel': False, 'ConditionTarget': None, 'OrderType': 'LIMIT_BUY', 'TimeStamp': '2018-03-31T17:18:02.18', 'Exchange': 'BTC-TRX', 'Commission': 1.47e-06, 'OrderUuid': '560e42dc-9ec2-415c-b75d-bcd76df47e71', 'QuantityRemaining': 0.0}, {'Limit': 5e-06, 'PricePerUnit': 5e-06, 'Closed': '2018-03-31T15:45:28.833', 'Quantity': 100.0, 'Price': 0.0005, 'Condition': 'NONE', 'IsConditional': False, 'ImmediateOrCancel': False, 'ConditionTarget': None, 'OrderType': 'LIMIT_BUY', 'TimeStamp': '2018-03-31T15:44:21.703', 'Exchange': 'BTC-TRX', 'Commission': 1.25e-06, 'OrderUuid': '93cddc30-7bc9-4954-8892-9965336aeadb', 'QuantityRemaining': 0.0}, {'Limit': 5.29e-06, 'PricePerUnit': 5.29e-06, 'Closed': '2018-03-31T04:20:17.077', 'Quantity': 100.0, 'Price': 0.000529, 'Condition': 'NONE', 'IsConditional': False, 'ImmediateOrCancel': False, 'ConditionTarget': None, 'OrderType': 'LIMIT_BUY', 'TimeStamp': '2018-03-31T04:18:56.667', 'Exchange': 'BTC-TRX', 'Commission': 1.32e-06, 'OrderUuid': '9acf0765-0129-44f6-98f2-adc2c09b81a1', 'QuantityRemaining': 0.0}, {'Limit': 5.55e-06, 'PricePerUnit': 5.55e-06, 'Closed': '2018-03-31T02:52:42.537', 'Quantity': 100.0, 'Price': 0.000555, 'Condition': 'NONE', 'IsConditional': False, 'ImmediateOrCancel': False, 'ConditionTarget': None, 'OrderType': 'LIMIT_BUY', 'TimeStamp': '2018-03-30T05:57:24.217', 'Exchange': 'BTC-TRX', 'Commission': 1.38e-06, 'OrderUuid': '8a7859e8-9915-4b70-a169-b843dbdbdadd', 'QuantityRemaining': 0.0}, {'Limit': 5.7e-06, 'PricePerUnit': 5.69e-06, 'Closed': '2018-03-30T00:37:25.357', 'Quantity': 90.0, 'Price': 0.0005121, 'Condition': 'NONE', 'IsConditional': False, 'ImmediateOrCancel': False, 'ConditionTarget': None, 'OrderType': 'LIMIT_BUY', 'TimeStamp': '2018-03-30T00:37:25.213', 'Exchange': 'BTC-TRX', 'Commission': 1.28e-06, 'OrderUuid': 'e9b35432-7a96-4cf2-ae47-f0e2facb5f0a', 'QuantityRemaining': 0.0}, {'Limit': 6.35e-06, 'PricePerUnit': 6.35e-06, 'Closed': '2018-03-29T22:26:20.613', 'Quantity': 100.0, 'Price': 0.000635, 'Condition': 'NONE', 'IsConditional': False, 'ImmediateOrCancel': False, 'ConditionTarget': None, 'OrderType': 'LIMIT_BUY', 'TimeStamp': '2018-03-29T22:24:33.537', 'Exchange': 'BTC-TRX', 'Commission': 1.58e-06, 'OrderUuid': '0ac6de37-1444-4e60-880e-974dc493fb33', 'QuantityRemaining': 0.0}, {'Limit': 6.57e-06, 'PricePerUnit': 6.57e-06, 'Closed': '2018-03-29T16:43:30.343', 'Quantity': 100.0, 'Price': 0.000657, 'Condition': 'NONE', 'IsConditional': False, 'ImmediateOrCancel': False, 'ConditionTarget': None, 'OrderType': 'LIMIT_BUY', 'TimeStamp': '2018-03-29T16:12:32.667', 'Exchange': 'BTC-TRX', 'Commission': 1.64e-06, 'OrderUuid': 'b1d32de1-3907-40b4-b43b-60f2bca38e70', 'QuantityRemaining': 0.0}, {'Limit': 5.52e-06, 'PricePerUnit': 5.52e-06, 'Closed': '2018-03-28T14:46:39.237', 'Quantity': 100.0, 'Price': 0.000552, 'Condition': 'NONE', 'IsConditional': False, 'ImmediateOrCancel': False, 'ConditionTarget': None, 'OrderType': 'LIMIT_BUY', 'TimeStamp': '2018-03-28T02:00:49.75', 'Exchange': 'BTC-TRX', 'Commission': 1.38e-06, 'OrderUuid': 'a96d8eaa-f42c-431e-a8a7-85782bd09459', 'QuantityRemaining': 0.0}, {'Limit': 5.5e-06, 'PricePerUnit': 5.5e-06, 'Closed': '2018-03-28T00:33:54.53', 'Quantity': 100.0, 'Price': 0.00055, 'Condition': 'NONE', 'IsConditional': False, 'ImmediateOrCancel': False, 'ConditionTarget': None, 'OrderType': 'LIMIT_BUY', 'TimeStamp': '2018-03-28T00:19:58.47', 'Exchange': 'BTC-TRX', 'Commission': 1.37e-06, 'OrderUuid': 'fea0e94c-cbc0-41fb-88e8-fbec23c7fe5b', 'QuantityRemaining': 0.0}, {'Limit': 5.52e-06, 'PricePerUnit': 5.52e-06, 'Closed': '2018-03-26T23:44:21.78', 'Quantity': 100.0, 'Price': 0.000552, 'Condition': 'NONE', 'IsConditional': False, 'ImmediateOrCancel': False, 'ConditionTarget': None, 'OrderType': 'LIMIT_SELL', 'TimeStamp': '2018-03-26T23:44:16.97', 'Exchange': 'BTC-TRX', 'Commission': 1.38e-06, 'OrderUuid': '09f691b4-6db9-4071-b469-27b79b1fb62f', 'QuantityRemaining': 0.0}, {'Limit': 5.44e-06, 'PricePerUnit': 5.44e-06, 'Closed': '2018-03-26T23:20:02.403', 'Quantity': 100.0, 'Price': 0.000544, 'Condition': 'NONE', 'IsConditional': False, 'ImmediateOrCancel': False, 'ConditionTarget': None, 'OrderType': 'LIMIT_BUY', 'TimeStamp': '2018-03-26T23:20:02.357', 'Exchange': 'BTC-TRX', 'Commission': 1.36e-06, 'OrderUuid': 'c1417f71-37e9-4719-8acd-4561adc4b085', 'QuantityRemaining': 0.0}]}
代码:
from bittrex.bittrex import API_V2_0, Bittrex
import json
my_bittrex = Bittrex("fart", "fart", api_version=API_V2_0)
j = (my_bittrex.get_order_history('BTC-TRX'))
#k = json.JSONEncoder().encode(j)
count = 0
for x in j:
print (json.dumps(x))
count = count +1
'最好的'输出:
"success"
"result"
"message"
预期产出:
'OrderUuid': '139858b6-d47a-4734-bb1f-a5d11b3fd203' 'Price': 0.0052416
....
我试过了:
print(x['result'])
json.dumps(x['result'])
json.dumps(x[count])
json.loads....
答案 0 :(得分:0)
您想要的数据位于result
键内。
需要使用str
json.loads()
转换为JSON数组
j = (my_bittrex.get_order_history('BTC-TRX'))
data = json.loads(j)
for x in data['result']:
print(x['OrderUuid'])
print(x['Price'])
如果j
已经是JSON数组,则无需调用json.loads()
直接循环。
j = (my_bittrex.get_order_history('BTC-TRX'))
for x in j['result']:
print(x['OrderUuid'])
print(x['Price'])