Stop Algorithm
Stop a running trading algorithm. Existing open positions will remain open.
Endpoint
POST /api/trading/algorithms/:id/stop
Authentication
Requires authentication via Bearer token.
Authorization: Bearer <access_token>
Request
Path Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
| id | string | Yes | Algorithm ID |
Body
No request body required.
Response
Success (200 OK)
{
"id": "507f1f77bcf86cd799439011",
"name": "RSI Momentum Strategy",
"status": "stopped",
"active": false,
"message": "Algorithm stopped successfully"
}
Errors
| Status | Code | Message |
|---|---|---|
| 401 | UNAUTHORIZED | Authentication required |
| 404 | NOT_FOUND | Algorithm not found |
| 422 | UNPROCESSABLE_ENTITY | Algorithm not active |
Examples
Stop Algorithm
cURL:
curl -X POST https://api.x3algo.com/api/trading/algorithms/507f1f77bcf86cd799439011/stop \
-H "Authorization: Bearer YOUR_ACCESS_TOKEN"
JavaScript:
const algorithmId = '507f1f77bcf86cd799439011'
const response = await fetch(
`https://api.x3algo.com/api/trading/algorithms/${algorithmId}/stop`,
{
method: 'POST',
headers: {
'Authorization': `Bearer ${accessToken}`
}
}
)
const result = await response.json()
console.log(result.message)
Python:
algorithm_id = '507f1f77bcf86cd799439011'
response = requests.post(
f'https://api.x3algo.com/api/trading/algorithms/{algorithm_id}/stop',
headers={'Authorization': f'Bearer {access_token}'}
)
result = response.json()
print(result['message'])
Behavior
When an algorithm is stopped:
-
Signal Generation Stops
- No new entry signals will be generated
- Algorithm will not open new positions
-
Existing Positions
- Open positions remain open
- Exit conditions continue to be monitored
- Stop loss and take profit orders remain active
-
Status Change
- Status changes from
activetostopped activeflag set tofalse
- Status changes from
State Transitions
active → stopped
paused → stopped
Use Cases
Temporary Stop
Stop algorithm temporarily to:
- Review performance
- Adjust configuration
- Wait for better market conditions
Emergency Stop
Stop algorithm immediately if:
- Unexpected behavior detected
- Market conditions change dramatically
- Risk limits being approached
Scheduled Stop
Stop algorithm at end of trading session:
// Stop all algorithms at market close
const algorithms = await getActiveAlgorithms()
for (const algo of algorithms) {
await stopAlgorithm(algo.id)
}
Notes
- Stopping an algorithm does not close open positions
- To close positions, use the position management endpoints
- Algorithm can be restarted at any time
- Performance metrics are preserved
Related
- Start Algorithm
- Pause Algorithm endpoint (coming soon)
- Get Algorithm
- Update Algorithm