简体   繁体   English

从 Python-Binance 获取订单参数

[英]Get order parameters from Python-Binance

I'm trying to get some parameters of my orders from Python-Binance API.我正在尝试从 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'])试试这个: pprint.pprint(orders[0]['status'])

order variable is a list that contains dictionary. order变量是一个包含字典的列表。 To get access to first element of the list use [0] .要访问列表的第一个元素,请使用[0] Now you only get value from dictionary.现在你只能从字典中获得价值。 You can do this using [dictionary_key] in this example ['status'] .您可以在此示例['status']中使用 [dictionary_key] 来执行此操作。 Combining this you can print status.结合这一点,您可以打印状态。

If you are not sure which type is your variable use simply print(type(variable_name))如果您不确定您的变量是哪种类型,只需使用print(type(variable_name))

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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