How to get corresponding order history (e.g. with orderId) of original order?

Hi all :slight_smile:

I am building a software placing trades via Futures API together with SL and TP orders. Now I want to track, when the order was closed, for what reason it was closed (manual, SL, TP) and at which price (also need the time and PNL).

The “problem” (for me) is, that every closing order gets its own orderID from Binance. I want to build a loop where I am going through all my open orders (in my DB) and check if one of them was closed and if so, get all the data and write it into my DB.

Websocket isn’t really an option, as the software is not running 24/7 and so could miss a lot of notifications.

Any idea how to achieve that?

So far, my only idea was to use GET /fapi/v1/allOrders. But first of all, that could give me thousands of orders in a heavily used account, and second, I would need to identify the correct order using symbol and quantity, but that could also be wrong (maybe there is more than one order with the same specs). Also, the performance wouldn’t be great I guess, and I want to run it continuously.

I would need a possibility to check what happened to a specific orderId, if it’s still open, or closed and if so, why and how. Any chance to realize that?

Any hints are greatly appreciated, stuck here right now…

Thank you!

After the order is placed, there should be an orderId returned from Binance. So you can always to check the order status from the endpoint GET /fapi/v1/order.

Thank you dino, but that’s not what I’m looking for.

When a position is closed, there will be a new order number. The initial orderId is only for the opening of the position (until it’s filled). I need to get the corresponding orderId, when a position is closed (manually), by an SL or TP order.

The question is: How can I find all related orders to my initial order? Everything handling the same position.

I have implemented a solution, but it’s not that elegant in my point of view and there is a risk it will get the wrong order and assign it, although I am trying to compare as many details as possible, it’s still not the professional way to do it I guess. There should be a secure and official method achieving this (I hope so at least).