Skip to content
Advertisement

Get order parameters from Python-Binance

I’m trying to get some parameters of my orders from Python-Binance API. In this case, I would like to get only the ‘status’ of an order and save it into a variable.

I used this to get my last order :

orders = client.get_all_orders(symbol=symbol, limit=1)

And I get this result:

[{'clientOrderId': 'HzHxjogJf5rXrzD2uFnTyMn',
'cummulativeQuoteQty': '12.06757100',
'executedQty': '0.00030000',
  'icebergQty': '0.00000000',
  'isWorking': True,
  'orderId': 88978639302,
  'orderListId': -1,
  'origQty': '0.00030000',
  'origQuoteOrderQty': '0.00000000',
  'price': '31558.57000000',
  'side': 'BUY',
  'status': 'FILLED',
  'stopPrice': '31592.06000000',
  'symbol': 'BTCUSDT',
  'time': 1612653434918,
  'timeInForce': 'GTC',
  'type': 'STOP_LOSS_LIMIT',
  'updateTime': 1612109872451}]

Tried to print just the status:

pprint.pprint(orders['status'])

But it returns an error:

TypeError: list indices must be integers or slices, not str

Advertisement

Answer

Try this: pprint.pprint(orders[0]['status'])

order variable is a list that contains dictionary. To get access to first element of the list use [0]. Now you only get value from dictionary. You can do this using [dictionary_key] in this example ['status']. Combining this you can print status.

If you are not sure which type is your variable use simply print(type(variable_name))

User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement