【问题标题】:Get value from json - API从 json 获取价值 - API
【发布时间】:2019-07-28 15:25:03
【问题描述】:

所以我在 python 中建立了一个 API 连接,一切都很好。 我的问题是如何获得 'avgEntryPrice' 的值?

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

这是由以下人员返回的:

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

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

提前致谢!

【问题讨论】:

  • let a = json.dumps(...) + a[0]['avgEntryPrice']?

标签: python json api bitmex


【解决方案1】:
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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2013-04-11
    • 1970-01-01
    • 2017-02-13
    • 1970-01-01
    • 1970-01-01
    • 2017-11-09
    • 2019-07-20
    • 1970-01-01
    相关资源
    最近更新 更多