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:
- size: Position size (positive for long, negative for short)
- If size is non-zero, you have an active position
- 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:
- The order will only reduce (close) an existing position
- It will never open a new position or increase an existing one
- If the position is already closed, the order won’t be executed
For your specific scenario:
- Main Order: This is your entry order, so it should NOT have reduce_only set
- Stop-Loss Order: This should have reduce_only set to “true”
- 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:
- They will only close your existing position
- They won’t open new positions in the opposite direction.
- 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:
- Monitoring position updates via WebSocket
- 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
}’