【问题标题】:Get order parameters from Python-Binance从 Python-Binance 获取订单参数
【发布时间】:2021-05-05 21:15:02
【问题描述】:

我正在尝试从 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

【问题讨论】:

    标签: python algorithmic-trading trading binance


    【解决方案1】:

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

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

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-08-24
      • 2021-06-18
      • 1970-01-01
      • 2021-06-03
      • 2019-01-08
      相关资源
      最近更新 更多