Please help me understand python api usage , documentation isn't clear

I will place a main order, status from open to closed, Now I will place stoploss order and target orders. (If any of them cancelled I will close main position) similarly if main position closes I will close the SL/target if they are open.

I don’t want to open any new positons. How I can find whether main postion is active ad I am unable to use order id. Is there any need to use reduce_only for any of these orders?

Checking if Your Main Position is Active
To check if your main position is active, you can use the /positions endpoint. This will tell you if you have an open position for a specific product:

curl -X GET “https://api.india.delta.exchange/v2/positions?product_id=YOUR_PRODUCT_ID
-H “api-key: your_api_key”
-H “timestamp: your_timestamp”
-H “signature: your_signature”

The response will include:

  1. size: Position size (positive for long, negative for short)
  2. If size is non-zero, you have an active position
  3. If size is zero, you don’t have an active position

You can also use the WebSocket API to subscribe to position updates in real-time, which is more efficient than polling:
{
“type”: “subscribe”,
“payload”: {
“channels”: [
{
“name”: “positions”,
“symbols”: [“YOUR_SYMBOL”]
}
]
}
}

Using reduce_only Parameter
The reduce_only parameter is exactly what you need for your scenario. When set to “true”, it ensures that:

  1. The order will only reduce (close) an existing position
  2. It will never open a new position or increase an existing one
  3. If the position is already closed, the order won’t be executed

For your specific scenario:

  1. Main Order: This is your entry order, so it should NOT have reduce_only set
  2. Stop-Loss Order: This should have reduce_only set to “true”
  3. Take-Profit Order: This should have reduce_only set to “true”

By setting reduce_only to “true” for your SL and TP orders, you ensure that:

  1. They will only close your existing position
  2. They won’t open new positions in the opposite direction.
  3. If your main position gets closed by other means, these orders won’t execute

Placing Stop-Loss and Take-Profit Orders with reduce_only

When placing your stop-loss and take-profit orders, include the reduce_only parameter:

curl -X POST “https://api.india.delta.exchange/v2/orders
-H “api-key: your_api_key”
-H “timestamp: your_timestamp”
-H “signature: your_signature”
-H “Content-Type: application/json”
-d ‘{
“product_id”: YOUR_PRODUCT_ID,
“size”: YOUR_POSITION_SIZE,
“side”: “sell”, // opposite of your position side
“order_type”: “limit_order”,
“limit_price”: “PRICE”,
“stop_order_type”: “stop_loss_order”, // or “take_profit_order”
“stop_price”: “TRIGGER_PRICE”,
“reduce_only”: “true”
}’

Managing Orders When Position Changes
When your main position closes (either manually or through one of your orders), you should cancel the remaining SL/TP orders. You can do this by:

  1. Monitoring position updates via WebSocket
  2. When position size becomes zero, cancel all remaining orders for that product

curl -X DELETE “https://api.india.delta.exchange/v2/orders/all
-H “api-key: your_api_key”
-H “timestamp: your_timestamp”
-H “signature: your_signature”
-H “Content-Type: application/json”
-d ‘{
“product_id”: YOUR_PRODUCT_ID
}’