简体   繁体   中英

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

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))

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM