Is it possible to create automatic stop loss or take profit orders in margin trades?

If not, should I create two orders after the first one is filled?
So: filled -> send stop lost order and send take profit order

Though I’m not so sure what you mean by ‘automatic’ stop loss or take profit. The API POST /sapi/v1/margin/order only handles the action to place an order. If there is any logic that depends on another order, you have to tackle it from your end.