Need guidence for order placement using api

i am developing a strategy and suppose i send a buy order using the api, and the trade is activated, my platform where i am running the code does the calculation for the stop loss and the target, so suppose when the target is reached or the stoploss is reached can we send a sell order based on either target price or stop loss price to close the trade for that particular order id we got when we placed the buy order?

can someone place some light on my thought whether I am wrong and what can be the code to implement this please help me