从Python-Binance获取订单参数



我试图从Python-Binance API获得我的订单的一些参数。在本例中,我只想获得订单的"状态",并将其保存到一个变量中。

我用这个来获取我的上一个订单:

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

我得到这个结果:

[{'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}]

尝试只打印状态:

pprint.pprint(orders['status'])

但是它返回一个错误:

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

试试这个:pprint.pprint(orders[0]['status'])

order变量是一个包含字典的列表。要访问列表的第一个元素,使用[0]。现在你只能从字典中获取值。您可以在本例['status']中使用[dictionary_key]来完成此操作。结合这些,您可以打印状态。

如果您不确定您的变量类型,只需使用print(type(variable_name))

最新更新