簡體   English   中英

從 Python-Binance 獲取訂單參數

[英]Get order parameters from 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))

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM