But when I asked about the available balance right after (by using client.get_asset_balance(asset=‘ADA’) from python-binance library), I got the following: Current balance for asset ADA: {'asset': 'ADA', 'free': '0.03800000', 'locked': '421.90000000'} WARNING: Non-zero locked balance 421.90000000 for asset ADA.
The order cancelation does not seem to block until the assets are released (i.e. there is some asynchronicity and the assets are only released later after the cancellation call is finished). What is the best way to tackle this problem? I need the assets to be free after the order is canceled.
The assets are available immediately after you get a response to DELETE /api/v3/order request.
GET /api/v3/account response with account balance can be more delayed than the actual state in the matching engine. This endpoint it’s documented to be updated from memory and database.
If you want account balance updates with lower delay, please try WebSocket user data stream, specifically the "outboundAccountPosition" events.
Thanks! If I don’t want to switch to websockets right now, I think my best option is to try the /api/v3/account multiple times after order cancelation or market order, is that right?
Yes. In that case you can only retry /api/v3/account, the balance should update soon. (But do note that this endpoint has rather high weight, so don’t spam it too much.)
You can compare "updateTime" in the /api/v3/account response with "transactTime" in the order cancellation response. Once updateTime >= transactTime, the balance will reflect the cancellation.