从json API获取值

2024-04-28 23:27:39 发布

您现在位置:Python中文网/ 问答频道 /正文

所以我用python建立了一个API连接,一切正常。 我的问题是如何获得“avgEntryPrice”的价值?你知道吗

[{'account': 231584,'simpleCost': 0.0, 'simpleValue': 0.0, 'avgEntryPrice': 0.0, ...}]

返回方式:

client.Position.Position_get(filter=json.dumps({'symbol': 'XBTUSD'})).result()

这里是swagger.json文件对于API https://github.com/BitMEX/api-connectors/blob/master/swagger.json?source=post_page---------------------------

提前谢谢!你知道吗


Tags: clientapijsongetswagger方式positionaccount
1条回答
网友
1楼 · 发布于 2024-04-28 23:27:39
positions = json.loads(result)  # result is an array so you will either loop over it or select first item

avg_entry_price = positions[0]['avgEntryPrice']  # first record solution

或者

for position in positions:  # iterative solution
    print(position['avgEntryPrice'])

更多答案和细节convert string to json

相关问题 更多 >