Take profit/Close position with percentage quantity

I’ve signal that look right this (Margin)
LONG1 -> TP1 -> LONG2 -> TP2 -> LONG3 -> …

I’d like to take profit (TP1) from LONG1 order by 50% of its quantity. when LONG2 is FILLED and TP2 get called, I’d like to take profit from LONG1 only (50% remain quantity) basically close LONG1 position in this moment. If I understand correctly, My active order should now contain only with LONG2 order and then repeat the process when LONG3 get called. Can anyone guide me on how to implement this please, I still confused on how to close the position correctly.