Skip to main content
Skip to main content
Version: 1.0 (Current)

Update Algorithm

Update an existing trading algorithm configuration.

Endpoint

PATCH /api/trading/algorithms/:id

Authentication

Requires authentication via Bearer token.

Authorization: Bearer <access_token>

Request

Path Parameters

ParameterTypeRequiredDescription
idstringYesAlgorithm ID

Headers

Content-Type: application/json
Authorization: Bearer <access_token>

Body

Send only the fields you want to update:

{
"name": "Updated Strategy Name",
"timeframe": "30m",
"symbols": ["NSE:RELIANCE", "NSE:HDFC"],
"riskParameters": {
"maxDailyLoss": 3
}
}

Response

Success (200 OK)

{
"id": "507f1f77bcf86cd799439011",
"name": "Updated Strategy Name",
"timeframe": "30m",
"symbols": ["NSE:RELIANCE", "NSE:HDFC"],
"riskParameters": {
"maxPositionSize": 10,
"stopLoss": 2,
"takeProfit": 4,
"maxDailyLoss": 3,
"maxOpenPositions": 3,
"riskRewardRatio": 2
},
"updatedAt": "2024-01-15T11:00:00Z"
}

Errors

StatusCodeMessage
400VALIDATION_ERRORInvalid input data
401UNAUTHORIZEDAuthentication required
403FORBIDDENCannot update active algorithm
404NOT_FOUNDAlgorithm not found
422UNPROCESSABLE_ENTITYInvalid configuration

Examples

Update Risk Parameters

cURL:

curl -X PATCH https://api.x3algo.com/api/trading/algorithms/507f1f77bcf86cd799439011 \
-H "Authorization: Bearer YOUR_ACCESS_TOKEN" \
-H "Content-Type: application/json" \
-d '{
"riskParameters": {
"maxDailyLoss": 3,
"maxOpenPositions": 5
}
}'

Update Entry Conditions

JavaScript:

const updates = {
entryConditions: {
positionType: 'both',
logicalOperator: 'OR',
conditions: [
{
type: 'indicator_value',
indicator: 'RSI',
period: 14,
comparison: 'below',
value: 30
},
{
type: 'indicator_value',
indicator: 'RSI',
period: 14,
comparison: 'above',
value: 70
}
]
}
}

const response = await fetch(`https://api.x3algo.com/api/trading/algorithms/${algorithmId}`, {
method: 'PATCH',
headers: {
'Authorization': `Bearer ${accessToken}`,
'Content-Type': 'application/json'
},
body: JSON.stringify(updates)
})

Notes

  • You can only update algorithms in draft or stopped status
  • Active algorithms must be stopped before updating
  • Partial updates are supported - only send fields you want to change
  • Nested objects are merged, not replaced entirely