1

So I have an API conection established in python, everything is alright. My question is how to get to the value of 'avgEntryPrice'?

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

this is returned by:

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

and here is swagger.json for API https://github.com/BitMEX/api-connectors/blob/master/swagger.json?source=post_page---------------------------

Thanks in advance!

1 Answers1

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

or

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

More answers and details convert string to json

Ramy M. Mousa
  • 5,727
  • 3
  • 34
  • 45