> For the complete documentation index, see [llms.txt](https://docs.clickoptions.ai/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.clickoptions.ai/api/take-profit-stop-loss-v1.md).

# Take Profit / Stop Loss V1

Trigger orders that close a long position

## Set take profit / stop loss of a position

> Full desired state: creates or replaces each leg; a null leg cancels the existing leg of that kind. Long positions only.

```json
{"openapi":"3.1.0","info":{"title":"fintp-public-api","version":"0.0.1"},"tags":[{"name":"Take profit / stop loss v1","description":"Trigger orders that close a long position"}],"servers":[{"url":"https://api.clickoptions.ai/api","description":"Generated server url"}],"paths":{"/v1/positions/{positionId}/tpsl":{"put":{"tags":["Take profit / stop loss v1"],"summary":"Set take profit / stop loss of a position","description":"Full desired state: creates or replaces each leg; a null leg cancels the existing leg of that kind. Long positions only.","operationId":"setPositionTpSl","parameters":[{"name":"positionId","in":"path","required":true,"schema":{"type":"string"}}],"requestBody":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/PositionTpSlRequestV1"}}},"required":true},"responses":{"200":{"description":"Legs set","content":{"*/*":{"schema":{"$ref":"#/components/schemas/PositionTpSlResponseV1"}}}},"400":{"description":"Invalid input data","content":{"*/*":{"schema":{"$ref":"#/components/schemas/ApiErrorV1"}}}},"401":{"description":"Authentication required","content":{"*/*":{"schema":{"type":"object"}}}},"404":{"description":"Position not found","content":{"*/*":{"schema":{"$ref":"#/components/schemas/ApiErrorV1"}}}},"422":{"description":"Business validation failed, e.g. the leg would trigger at once","content":{"*/*":{"schema":{"$ref":"#/components/schemas/ApiErrorV1"}}}},"429":{"description":"Rate limit exceeded","content":{"*/*":{"schema":{"type":"object"}}}}}}}},"components":{"schemas":{"PositionTpSlRequestV1":{"type":"object","description":"Full desired take profit / stop loss state of a position; a null leg cancels that leg","properties":{"takeProfit":{"$ref":"#/components/schemas/TriggerLegRequestV1","description":"Take profit leg, or null to cancel it"},"stopLoss":{"$ref":"#/components/schemas/TriggerLegRequestV1","description":"Stop loss leg, or null to cancel it"}}},"TriggerLegRequestV1":{"type":"object","description":"Take profit or stop loss leg","properties":{"triggerBy":{"type":"string","description":"Price source: index price or the best real option bid","enum":["INDEX","OPTION_PRICE"],"minLength":1,"pattern":"^(INDEX|OPTION_PRICE)$"},"triggerPrice":{"type":"string","description":"Trigger price as a decimal string","minLength":1,"pattern":"^\\d+(\\.\\d+)?$"},"orderType":{"type":"string","description":"Order placed when the leg fires","enum":["MARKET","LIMIT"],"minLength":1,"pattern":"^(MARKET|LIMIT)$"},"limitPrice":{"type":"string","description":"Limit price as a decimal string; required for LIMIT, not allowed for MARKET","pattern":"^\\d+(\\.\\d+)?$"}},"required":["orderType","triggerBy","triggerPrice"]},"PositionTpSlResponseV1":{"type":"object","description":"Take profit / stop loss legs of a position after the change","properties":{"takeProfit":{"$ref":"#/components/schemas/TriggerOrderDto","description":"Take profit leg, null when none"},"stopLoss":{"$ref":"#/components/schemas/TriggerOrderDto","description":"Stop loss leg, null when none"}}},"TriggerOrderDto":{"type":"object","description":"Take profit or stop loss trigger order","properties":{"id":{"type":"string","description":"Trigger order ID"},"positionId":{"type":"string","description":"Position the leg protects; null while WAITING for the parent BUY to fill"},"parentOrderId":{"type":"string","description":"BUY order the leg was attached to, if any"},"symbol":{"type":"string","description":"Option symbol"},"kind":{"type":"string","description":"Leg kind","enum":["TAKE_PROFIT","STOP_LOSS"]},"triggerBy":{"type":"string","description":"Price source: index price or the best real option bid","enum":["INDEX","OPTION_PRICE"]},"direction":{"type":"string","description":"Fires when the price is at or above (ABOVE) or at or below (BELOW) the trigger price","enum":["ABOVE","BELOW"]},"triggerPrice":{"type":"string","description":"Trigger price as a decimal string"},"orderType":{"type":"string","description":"Order placed when the leg fires","enum":["MARKET","LIMIT"]},"limitPrice":{"type":"string","description":"Limit price for a LIMIT leg, decimal string"},"status":{"type":"string","description":"Leg status","enum":["WAITING","ACTIVE","TRIGGERED","CANCELED","REJECTED"]},"childOrderId":{"type":"string","description":"SELL order placed by the leg, if any"},"reason":{"type":"string","description":"Readable reason of the last change"},"stale":{"type":"boolean","description":"True when an ACTIVE leg has had no usable price for 60 s"},"createTime":{"type":"integer","format":"int64","description":"Creation time, epoch ms"},"updateTime":{"type":"integer","format":"int64","description":"Last change time, epoch ms"},"triggeredTime":{"type":"integer","format":"int64","description":"Fire time, epoch ms"}}},"ApiErrorV1":{"type":"object","properties":{"error":{"type":"string"},"message":{"type":"string"},"requestId":{"type":"string"},"details":{"type":"object","additionalProperties":{}}}}}}}
```

## Get trigger orders

> OPEN = WAITING and ACTIVE legs, HISTORY = triggered, canceled and rejected legs; newest first.

```json
{"openapi":"3.1.0","info":{"title":"fintp-public-api","version":"0.0.1"},"tags":[{"name":"Take profit / stop loss v1","description":"Trigger orders that close a long position"}],"servers":[{"url":"https://api.clickoptions.ai/api","description":"Generated server url"}],"paths":{"/v1/trigger-orders":{"get":{"tags":["Take profit / stop loss v1"],"summary":"Get trigger orders","description":"OPEN = WAITING and ACTIVE legs, HISTORY = triggered, canceled and rejected legs; newest first.","operationId":"getTriggerOrders","parameters":[{"name":"status","in":"query","description":"OPEN or HISTORY","required":false,"schema":{"type":"string","default":"OPEN"}},{"name":"positionId","in":"query","description":"Only legs of this position","required":false,"schema":{"type":"string"}},{"name":"page","in":"query","description":"Page number (1-based)","required":false,"schema":{"type":"integer","format":"int32","default":1}},{"name":"pageSize","in":"query","description":"Number of items per page (max 100)","required":false,"schema":{"type":"integer","format":"int32","default":20}}],"responses":{"200":{"description":"Trigger orders retrieved","content":{"*/*":{"schema":{"$ref":"#/components/schemas/PagedResponseV1TriggerOrderDto"}}}},"400":{"description":"Invalid request parameters","content":{"*/*":{"schema":{"$ref":"#/components/schemas/ApiErrorV1"}}}},"401":{"description":"Authentication required","content":{"*/*":{"schema":{"type":"object"}}}}}}}},"components":{"schemas":{"PagedResponseV1TriggerOrderDto":{"type":"object","properties":{"total":{"type":"integer","format":"int32","description":"Total number of items"},"page":{"type":"integer","format":"int32","description":"Current page number"},"pageSize":{"type":"integer","format":"int32","description":"Number of items per page"},"items":{"type":"array","description":"List of items for the current page","items":{"$ref":"#/components/schemas/TriggerOrderDto"}}}},"TriggerOrderDto":{"type":"object","description":"Take profit or stop loss trigger order","properties":{"id":{"type":"string","description":"Trigger order ID"},"positionId":{"type":"string","description":"Position the leg protects; null while WAITING for the parent BUY to fill"},"parentOrderId":{"type":"string","description":"BUY order the leg was attached to, if any"},"symbol":{"type":"string","description":"Option symbol"},"kind":{"type":"string","description":"Leg kind","enum":["TAKE_PROFIT","STOP_LOSS"]},"triggerBy":{"type":"string","description":"Price source: index price or the best real option bid","enum":["INDEX","OPTION_PRICE"]},"direction":{"type":"string","description":"Fires when the price is at or above (ABOVE) or at or below (BELOW) the trigger price","enum":["ABOVE","BELOW"]},"triggerPrice":{"type":"string","description":"Trigger price as a decimal string"},"orderType":{"type":"string","description":"Order placed when the leg fires","enum":["MARKET","LIMIT"]},"limitPrice":{"type":"string","description":"Limit price for a LIMIT leg, decimal string"},"status":{"type":"string","description":"Leg status","enum":["WAITING","ACTIVE","TRIGGERED","CANCELED","REJECTED"]},"childOrderId":{"type":"string","description":"SELL order placed by the leg, if any"},"reason":{"type":"string","description":"Readable reason of the last change"},"stale":{"type":"boolean","description":"True when an ACTIVE leg has had no usable price for 60 s"},"createTime":{"type":"integer","format":"int64","description":"Creation time, epoch ms"},"updateTime":{"type":"integer","format":"int64","description":"Last change time, epoch ms"},"triggeredTime":{"type":"integer","format":"int64","description":"Fire time, epoch ms"}}},"ApiErrorV1":{"type":"object","properties":{"error":{"type":"string"},"message":{"type":"string"},"requestId":{"type":"string"},"details":{"type":"object","additionalProperties":{}}}}}}}
```

## Cancel trigger order

> Cancels a WAITING or ACTIVE take profit / stop loss leg

```json
{"openapi":"3.1.0","info":{"title":"fintp-public-api","version":"0.0.1"},"tags":[{"name":"Take profit / stop loss v1","description":"Trigger orders that close a long position"}],"servers":[{"url":"https://api.clickoptions.ai/api","description":"Generated server url"}],"paths":{"/v1/trigger-orders/{id}":{"delete":{"tags":["Take profit / stop loss v1"],"summary":"Cancel trigger order","description":"Cancels a WAITING or ACTIVE take profit / stop loss leg","operationId":"cancelTriggerOrder","parameters":[{"name":"id","in":"path","required":true,"schema":{"type":"string"}}],"responses":{"200":{"description":"Trigger order canceled","content":{"*/*":{"schema":{"$ref":"#/components/schemas/TriggerOrderDto"}}}},"404":{"description":"Trigger order not found","content":{"*/*":{"schema":{"$ref":"#/components/schemas/ApiErrorV1"}}}},"409":{"description":"Trigger order already in a final state","content":{"*/*":{"schema":{"$ref":"#/components/schemas/ApiErrorV1"}}}}}}}},"components":{"schemas":{"TriggerOrderDto":{"type":"object","description":"Take profit or stop loss trigger order","properties":{"id":{"type":"string","description":"Trigger order ID"},"positionId":{"type":"string","description":"Position the leg protects; null while WAITING for the parent BUY to fill"},"parentOrderId":{"type":"string","description":"BUY order the leg was attached to, if any"},"symbol":{"type":"string","description":"Option symbol"},"kind":{"type":"string","description":"Leg kind","enum":["TAKE_PROFIT","STOP_LOSS"]},"triggerBy":{"type":"string","description":"Price source: index price or the best real option bid","enum":["INDEX","OPTION_PRICE"]},"direction":{"type":"string","description":"Fires when the price is at or above (ABOVE) or at or below (BELOW) the trigger price","enum":["ABOVE","BELOW"]},"triggerPrice":{"type":"string","description":"Trigger price as a decimal string"},"orderType":{"type":"string","description":"Order placed when the leg fires","enum":["MARKET","LIMIT"]},"limitPrice":{"type":"string","description":"Limit price for a LIMIT leg, decimal string"},"status":{"type":"string","description":"Leg status","enum":["WAITING","ACTIVE","TRIGGERED","CANCELED","REJECTED"]},"childOrderId":{"type":"string","description":"SELL order placed by the leg, if any"},"reason":{"type":"string","description":"Readable reason of the last change"},"stale":{"type":"boolean","description":"True when an ACTIVE leg has had no usable price for 60 s"},"createTime":{"type":"integer","format":"int64","description":"Creation time, epoch ms"},"updateTime":{"type":"integer","format":"int64","description":"Last change time, epoch ms"},"triggeredTime":{"type":"integer","format":"int64","description":"Fire time, epoch ms"}}},"ApiErrorV1":{"type":"object","properties":{"error":{"type":"string"},"message":{"type":"string"},"requestId":{"type":"string"},"details":{"type":"object","additionalProperties":{}}}}}}}
```
