I'm trying to get the status of order, quantity, and side; however, I get following error:
list indices must be integers or slices, not str
Data:
[{'orderId': 123xxx, 'symbol': 'BTCUSDT', 'status': 'NEW', 'clientOrderId': 'xxx', 'price': '32000', 'avgPrice': '0', 'origQty': '0.001', 'executedQty': '0', 'cumQuote': '0', 'timeInForce': 'GTC', 'type': 'LIMIT', 'reduceOnly': False, 'closePosition': False, 'side': 'BUY', 'positionSide': 'BOTH', 'stopPrice': '0', 'workingType': 'CONTRACT_PRICE', 'priceProtect': False, 'origType': 'LIMIT', 'time': xxx, 'updateTime': xxx}, {'orderId': 123xxx, 'symbol': 'BTCUSDT', 'status': 'NEW', 'clientOrderId': 'xxx', 'price': '32000', 'avgPrice': '0', 'origQty': '0.001', 'executedQty': '0', 'cumQuote': '0', 'timeInForce': 'GTC', 'type': 'LIMIT', 'reduceOnly': False, 'closePosition': False, 'side': 'BUY', 'positionSide': 'BOTH', 'stopPrice': '0', 'workingType': 'CONTRACT_PRICE', 'priceProtect': False, 'origType': 'LIMIT', 'time': xxx, 'updateTime': xxx}]
Code:
get_open_order = client.futures_get_open_orders(symbol=config.SYMBOL, orderID=123xxx)
get_status = get_open_order['status']
get_qty = get_open_order['origQty']
get_side = get_open_order['side']
print(f"STATUS: {get_status} | QUANTITY: {get_qty} | SIDE: {get_side}")
What's the mistake here?
CodePudding user response:
It looks like get_open_order
is a list
with two dict
items, each an order.
This is how you can access the orders within the list
(which I have renamed get_open_orders
to indicate that it contains multiple orders, not just one).
#get_open_order = client.futures_get_open_orders(symbol=config.SYMBOL, orderID=123xxx)
get_open_orders = [
{'orderId': 123001, 'symbol': 'BTCUSDT', 'status': 'NEW', 'clientOrderId': 'xxx', 'price': '32000', 'avgPrice': '0', 'origQty': '0.001', 'executedQty': '0', 'cumQuote': '0', 'timeInForce': 'GTC', 'type': 'LIMIT', 'reduceOnly': False, 'closePosition': False, 'side': 'BUY', 'positionSide': 'BOTH', 'stopPrice': '0', 'workingType': 'CONTRACT_PRICE', 'priceProtect': False, 'origType': 'LIMIT', 'time': 777, 'updateTime': 777},
{'orderId': 123002, 'symbol': 'BTCUSDT', 'status': 'NEW', 'clientOrderId': 'xxx', 'price': '32000', 'avgPrice': '0', 'origQty': '0.001', 'executedQty': '0', 'cumQuote': '0', 'timeInForce': 'GTC', 'type': 'LIMIT', 'reduceOnly': False, 'closePosition': False, 'side': 'BUY', 'positionSide': 'BOTH', 'stopPrice': '0', 'workingType': 'CONTRACT_PRICE', 'priceProtect': False, 'origType': 'LIMIT', 'time': 777, 'updateTime': 777}
]
for get_open_order in get_open_orders:
get_status = get_open_order['status']
get_qty = get_open_order['origQty']
get_side = get_open_order['side']
print(f"STATUS: {get_status} | QUANTITY: {get_qty} | SIDE: {get_side}")
The output is:
STATUS: NEW | QUANTITY: 0.001 | SIDE: BUY
STATUS: NEW | QUANTITY: 0.001 | SIDE: BUY