> For the complete documentation index, see [llms.txt](https://docs.sigrex.io/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.sigrex.io/api-reference/reference/strategies/code-strategies.md).

# Code Strategies

## GET /api/v2/strategy/code

> Get all code strategies

```json
{"openapi":"3.0.0","info":{"title":"Sigrex API","version":"2.1.0"},"tags":[{"name":"code"}],"servers":[{"url":"https://api.sigrex.io"}],"security":[{"ApiKey":[],"Signature":[],"Timestamp":[]}],"components":{"securitySchemes":{"ApiKey":{"type":"apiKey","in":"header","name":"api-key","description":"Your public API key"}},"schemas":{}},"paths":{"/api/v2/strategy/code":{"get":{"summary":"Get all code strategies","tags":["code"],"responses":{"200":{"description":"List of user's code strategies","content":{"application/json":{"schema":{"type":"array","items":{"$ref":"#/components/schemas/CodeStrategy"}}}}}}}}}}
```

## POST /api/v2/strategy/code

> Create a new code strategy

```json
{"openapi":"3.0.0","info":{"title":"Sigrex API","version":"2.1.0"},"tags":[{"name":"code"}],"servers":[{"url":"https://api.sigrex.io"}],"security":[{"ApiKey":[],"Signature":[],"Timestamp":[]}],"components":{"securitySchemes":{"ApiKey":{"type":"apiKey","in":"header","name":"api-key","description":"Your public API key"}},"schemas":{"CreateCodeStrategyRequest":{"type":"object","required":["code"],"properties":{"name":{"type":"string","description":"The name of the strategy max 255 characters"},"folder_id":{"type":"number","description":"The folder id of the strategy"},"send_signal":{"type":"boolean","description":"Set true to enable signal generation"},"webhook_id":{"type":"number","description":"The id of the bot hook where signal will be sent (required if send_signal is true)"},"symbol":{"type":"string","description":"The signal symbol or symbols of the strategy separated by comma (required if send_signal is true)"},"code":{"type":"string","description":"The JavaScript code of the strategy"},"use_price":{"type":"boolean","description":"Set true if you want to use price ($.Price) in code"},"exchange_id":{"type":"number","description":"The id of the exchange where the price is fetched (required exchange with hasExchangeRate set to true)"},"price_symbol":{"type":"string","description":"The symbol of the price (required if use_price is true)"}}},"ErrorResponse":{"type":"object","properties":{"error":{"type":"string"}}}}},"paths":{"/api/v2/strategy/code":{"post":{"summary":"Create a new code strategy","tags":["code"],"requestBody":{"required":true,"content":{"application/json":{"schema":{"$ref":"#/components/schemas/CreateCodeStrategyRequest"}}}},"responses":{"201":{"description":"Code strategy created successfully","content":{"application/json":{"schema":{"$ref":"#/components/schemas/CodeStrategy"}}}},"400":{"description":"Missing required fields, invalid code, or strategy limit reached","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ErrorResponse"}}}},"404":{"description":"Exchange or webhook not found","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ErrorResponse"}}}}}}}}}
```

## GET /api/v2/strategy/code/{id}

> Get code strategy by ID

```json
{"openapi":"3.0.0","info":{"title":"Sigrex API","version":"2.1.0"},"tags":[{"name":"code"}],"servers":[{"url":"https://api.sigrex.io"}],"security":[{"ApiKey":[],"Signature":[],"Timestamp":[]}],"components":{"securitySchemes":{"ApiKey":{"type":"apiKey","in":"header","name":"api-key","description":"Your public API key"}},"schemas":{"ErrorResponse":{"type":"object","properties":{"error":{"type":"string"}}}}},"paths":{"/api/v2/strategy/code/{id}":{"get":{"summary":"Get code strategy by ID","tags":["code"],"parameters":[{"in":"path","name":"id","required":true,"schema":{"type":"string"}}],"responses":{"200":{"description":"Code strategy details with storage","content":{"application/json":{"schema":{"$ref":"#/components/schemas/CodeStrategyWithStorage"}}}},"400":{"description":"Missing id","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ErrorResponse"}}}},"404":{"description":"Strategy not found","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ErrorResponse"}}}}}}}}}
```

## PUT /api/v2/strategy/code/{id}

> Update code strategy

```json
{"openapi":"3.0.0","info":{"title":"Sigrex API","version":"2.1.0"},"tags":[{"name":"code"}],"servers":[{"url":"https://api.sigrex.io"}],"security":[{"ApiKey":[],"Signature":[],"Timestamp":[]}],"components":{"securitySchemes":{"ApiKey":{"type":"apiKey","in":"header","name":"api-key","description":"Your public API key"}},"schemas":{"UpdateCodeStrategyRequest":{"type":"object","required":["code"],"properties":{"name":{"type":"string","description":"The name of the strategy max 255 characters"},"folder_id":{"type":"number","description":"The folder id of the strategy"},"send_signal":{"type":"boolean","description":"Set true to enable signal generation"},"webhook_id":{"type":"number","description":"The id of the bot hook where signal will be sent (required if send_signal is true)"},"symbol":{"type":"string","description":"The signal symbol or symbols of the strategy separated by comma (required if send_signal is true)"},"code":{"type":"string","description":"The JavaScript code of the strategy"},"use_price":{"type":"boolean","description":"Set true if you want to use price ($.Price) in code"},"exchange_id":{"type":"number","description":"The id of the exchange where the price is fetched (required exchange with hasExchangeRate set to true)"},"price_symbol":{"type":"string","description":"The symbol of the price (required if use_price is true)"}}},"SuccessResponse":{"type":"object","properties":{"message":{"type":"string"}}},"ErrorResponse":{"type":"object","properties":{"error":{"type":"string"}}}}},"paths":{"/api/v2/strategy/code/{id}":{"put":{"summary":"Update code strategy","tags":["code"],"parameters":[{"in":"path","name":"id","required":true,"schema":{"type":"string"}}],"requestBody":{"required":true,"content":{"application/json":{"schema":{"$ref":"#/components/schemas/UpdateCodeStrategyRequest"}}}},"responses":{"200":{"description":"Code strategy updated successfully","content":{"application/json":{"schema":{"$ref":"#/components/schemas/SuccessResponse"}}}},"400":{"description":"Missing id, invalid code, or validation errors","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ErrorResponse"}}}},"404":{"description":"Strategy, exchange, or webhook not found","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ErrorResponse"}}}}}}}}}
```

## DELETE /api/v2/strategy/code/{id}

> Delete code strategy

```json
{"openapi":"3.0.0","info":{"title":"Sigrex API","version":"2.1.0"},"tags":[{"name":"code"}],"servers":[{"url":"https://api.sigrex.io"}],"security":[{"ApiKey":[],"Signature":[],"Timestamp":[]}],"components":{"securitySchemes":{"ApiKey":{"type":"apiKey","in":"header","name":"api-key","description":"Your public API key"}},"schemas":{"SuccessResponse":{"type":"object","properties":{"message":{"type":"string"}}},"ErrorResponse":{"type":"object","properties":{"error":{"type":"string"}}}}},"paths":{"/api/v2/strategy/code/{id}":{"delete":{"summary":"Delete code strategy","tags":["code"],"parameters":[{"in":"path","name":"id","required":true,"schema":{"type":"string"}}],"responses":{"200":{"description":"Code strategy deleted successfully","content":{"application/json":{"schema":{"$ref":"#/components/schemas/SuccessResponse"}}}},"400":{"description":"Missing id","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ErrorResponse"}}}},"404":{"description":"Strategy not found","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ErrorResponse"}}}}}}}}}
```

## POST /api/v2/strategy/code/duplicate

> Duplicate a code strategy

```json
{"openapi":"3.0.0","info":{"title":"Sigrex API","version":"2.1.0"},"tags":[{"name":"code"}],"servers":[{"url":"https://api.sigrex.io"}],"security":[{"ApiKey":[],"Signature":[],"Timestamp":[]}],"components":{"securitySchemes":{"ApiKey":{"type":"apiKey","in":"header","name":"api-key","description":"Your public API key"}},"schemas":{"ErrorResponse":{"type":"object","properties":{"error":{"type":"string"}}}}},"paths":{"/api/v2/strategy/code/duplicate":{"post":{"summary":"Duplicate a code strategy","tags":["code"],"requestBody":{"required":true,"content":{"application/json":{"schema":{"type":"object","required":["id"],"properties":{"id":{"type":"string","description":"Strategy ID to duplicate"}}}}}},"responses":{"201":{"description":"Code strategy duplicated successfully","content":{"application/json":{"schema":{"$ref":"#/components/schemas/CodeStrategy"}}}},"400":{"description":"Missing id or strategy limit reached","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ErrorResponse"}}}}}}}}}
```

## PUT /api/v2/strategy/code/{id}/reset

> Reset code strategy triggers and/or storage

```json
{"openapi":"3.0.0","info":{"title":"Sigrex API","version":"2.1.0"},"tags":[{"name":"code"}],"servers":[{"url":"https://api.sigrex.io"}],"security":[{"ApiKey":[],"Signature":[],"Timestamp":[]}],"components":{"securitySchemes":{"ApiKey":{"type":"apiKey","in":"header","name":"api-key","description":"Your public API key"}},"schemas":{"ResetCodeTriggersRequest":{"type":"object","required":["resetTriggers","resetStore"],"properties":{"resetTriggers":{"type":"boolean","description":"Set true to reset triggers"},"resetStore":{"type":"boolean","description":"Set true to reset store"}}},"SuccessResponse":{"type":"object","properties":{"message":{"type":"string"}}},"ErrorResponse":{"type":"object","properties":{"error":{"type":"string"}}}}},"paths":{"/api/v2/strategy/code/{id}/reset":{"put":{"summary":"Reset code strategy triggers and/or storage","tags":["code"],"parameters":[{"in":"path","name":"id","required":true,"schema":{"type":"string"}}],"requestBody":{"required":true,"content":{"application/json":{"schema":{"$ref":"#/components/schemas/ResetCodeTriggersRequest"}}}},"responses":{"200":{"description":"Triggers and/or storage reset successfully","content":{"application/json":{"schema":{"$ref":"#/components/schemas/SuccessResponse"}}}},"400":{"description":"Missing id, invalid options, or nothing to reset","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ErrorResponse"}}}},"404":{"description":"Strategy not found","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ErrorResponse"}}}}}}}}}
```

## PUT /api/v2/strategy/code/{id}/status

> Update code strategy status

```json
{"openapi":"3.0.0","info":{"title":"Sigrex API","version":"2.1.0"},"tags":[{"name":"code"}],"servers":[{"url":"https://api.sigrex.io"}],"security":[{"ApiKey":[],"Signature":[],"Timestamp":[]}],"components":{"securitySchemes":{"ApiKey":{"type":"apiKey","in":"header","name":"api-key","description":"Your public API key"}},"schemas":{"UpdateStatusRequest":{"type":"object","required":["status"],"properties":{"status":{"type":"string","enum":["ACTIVE","INACTIVE"]}}},"SuccessResponse":{"type":"object","properties":{"message":{"type":"string"}}},"ErrorResponse":{"type":"object","properties":{"error":{"type":"string"}}}}},"paths":{"/api/v2/strategy/code/{id}/status":{"put":{"summary":"Update code strategy status","tags":["code"],"parameters":[{"in":"path","name":"id","required":true,"schema":{"type":"string"}}],"requestBody":{"required":true,"content":{"application/json":{"schema":{"$ref":"#/components/schemas/UpdateStatusRequest"}}}},"responses":{"200":{"description":"Status updated successfully","content":{"application/json":{"schema":{"$ref":"#/components/schemas/SuccessResponse"}}}},"400":{"description":"Missing id, invalid status, status already set, or strategy limit reached","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ErrorResponse"}}}},"404":{"description":"Strategy not found","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ErrorResponse"}}}}}}}}}
```

## PUT /api/v2/strategy/code/{id}/public

> Update code strategy public visibility

```json
{"openapi":"3.0.0","info":{"title":"Sigrex API","version":"2.1.0"},"tags":[{"name":"code"}],"servers":[{"url":"https://api.sigrex.io"}],"security":[{"ApiKey":[],"Signature":[],"Timestamp":[]}],"components":{"securitySchemes":{"ApiKey":{"type":"apiKey","in":"header","name":"api-key","description":"Your public API key"}},"schemas":{"UpdatePublicRequest":{"type":"object","required":["isPublic"],"properties":{"isPublic":{"type":"boolean","description":"Set true to make the strategy public"}}},"SuccessResponse":{"type":"object","properties":{"message":{"type":"string"}}},"ErrorResponse":{"type":"object","properties":{"error":{"type":"string"}}}}},"paths":{"/api/v2/strategy/code/{id}/public":{"put":{"summary":"Update code strategy public visibility","tags":["code"],"parameters":[{"in":"path","name":"id","required":true,"schema":{"type":"string"}}],"requestBody":{"required":true,"content":{"application/json":{"schema":{"$ref":"#/components/schemas/UpdatePublicRequest"}}}},"responses":{"200":{"description":"Public visibility updated successfully","content":{"application/json":{"schema":{"$ref":"#/components/schemas/SuccessResponse"}}}},"400":{"description":"Missing id or invalid public flag","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ErrorResponse"}}}},"404":{"description":"Strategy not found","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ErrorResponse"}}}}}}}}}
```

## DELETE /api/v2/strategy/code/{id}/store

> Delete code strategy storage

```json
{"openapi":"3.0.0","info":{"title":"Sigrex API","version":"2.1.0"},"tags":[{"name":"code"}],"servers":[{"url":"https://api.sigrex.io"}],"security":[{"ApiKey":[],"Signature":[],"Timestamp":[]}],"components":{"securitySchemes":{"ApiKey":{"type":"apiKey","in":"header","name":"api-key","description":"Your public API key"}},"schemas":{"SuccessResponse":{"type":"object","properties":{"message":{"type":"string"}}},"ErrorResponse":{"type":"object","properties":{"error":{"type":"string"}}}}},"paths":{"/api/v2/strategy/code/{id}/store":{"delete":{"summary":"Delete code strategy storage","tags":["code"],"parameters":[{"in":"path","name":"id","required":true,"schema":{"type":"string"}}],"responses":{"200":{"description":"Storage deleted successfully","content":{"application/json":{"schema":{"$ref":"#/components/schemas/SuccessResponse"}}}},"400":{"description":"Missing id","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ErrorResponse"}}}},"404":{"description":"Strategy not found","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ErrorResponse"}}}}}}}}}
```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.sigrex.io/api-reference/reference/strategies/code-strategies.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
