When i let my bot place an order, it gives me something like the following output:
[{
"symbol": "BNBBTC",
"orderId": 3301945,
"clientOrderId": "6gCrw2kRUAF9CvJDGP16IP",
"transactTime": 1507725176595,
"price": "0.00000000",
"origQty": "10.00000000",
"executedQty": "10.00000000",
"status": "FILLED",
"timeInForce": "GTC",
"type": "LIMIT",
"side": "SELL"
}]
I want my bot to automatically be able to fetch the orderId so that it is able to continue working with that by itself without me manually typing in the Id.
For example, if i want to cancel that order:
result = client.cancel_order(
symbol='BNBBTC',
orderId='orderId')
I'd need to ask for the Id first, replace that 'orderId' and run again to be able to cancel the order. There has to be a way to automate this, right?
I suggest looking at some basic tutorials on dictionaries
. Getting values of keys is and should be the first thing you learn.
In your case with a dictionary as provided, the structure is very plain. So to get the value of orderId
you can just use your_dictionary.get("orderId")
.
Note I use .get
instead of dict[key]
, this way if there is no orderId
in your dictionary the console will only output None
. Whereas if I use dict[key]
and there is no such key, we will get a KeyError
.