Skip to content
Back to App

Playground API

The Playground API powers the Algo Playground experience. It provides endpoints for browsing strategy templates, running backtests, controlling playback speed, and managing saved strategies with full CRUD operations.

Base path

https://api.test-max.com/api/playground/

Authentication

The Playground API uses cookie-based JWT authentication — the same session cookie set when you log into the TestMax web app. No API key is needed.

Access requirements

EndpointAccess
GET /templatesPublic (no auth required)
All other endpointsPro plan required

Templates

GET /api/playground/templates

List all available strategy templates. This endpoint is public and does not require authentication.

URL: GET /api/playground/templates

Authentication: None required.

Response

{
"success": true,
"errorCode": 0,
"errorMessage": null,
"templates": [
{
"id": "sma-crossover",
"name": "SMA Crossover",
"description": "A moving average crossover strategy that goes long when the fast SMA crosses above the slow SMA.",
"category": "trend-following",
"difficulty": "beginner",
"params": [
{
"name": "fast_period",
"label": "Fast SMA Period",
"type": "number",
"default": 10,
"min": 2,
"max": 100
},
{
"name": "slow_period",
"label": "Slow SMA Period",
"type": "number",
"default": 20,
"min": 5,
"max": 200
}
]
},
{
"id": "rsi-scalper",
"name": "RSI Scalper",
"description": "A mean-reversion scalping strategy using RSI oversold/overbought signals.",
"category": "mean-reversion",
"difficulty": "beginner",
"params": [
{
"name": "rsi_period",
"label": "RSI Period",
"type": "number",
"default": 14,
"min": 2,
"max": 50
},
{
"name": "oversold",
"label": "Oversold Level",
"type": "number",
"default": 30,
"min": 5,
"max": 50
},
{
"name": "overbought",
"label": "Overbought Level",
"type": "number",
"default": 70,
"min": 50,
"max": 95
}
]
}
]
}

Template fields

FieldTypeDescription
idstringUnique template identifier. Pass this as templateId when running a backtest.
namestringHuman-readable template name
descriptionstringWhat the strategy does
categorystringStrategy category (e.g., "trend-following", "mean-reversion", "breakout")
difficultystringDifficulty level: "beginner", "intermediate", or "advanced"
paramsarrayConfigurable parameters for the template

Parameter fields

FieldTypeDescription
namestringParameter key used in the strategy code
labelstringDisplay label for the UI
typestringData type: "number", "string", or "boolean"
defaultanyDefault value
minnumber or nullMinimum value (for number params)
maxnumber or nullMaximum value (for number params)

Example

Terminal window
curl https://api.test-max.com/api/playground/templates

Execution

POST /api/playground/run

Run a backtest. You can run a template with custom parameters or provide custom Python code.

URL: POST /api/playground/run

Authentication: Cookie-based JWT. Pro plan required.

Request body

{
"templateId": "sma-crossover",
"code": null,
"instrument": "NQ",
"startDate": "2025-01-15",
"endDate": "2025-01-15",
"timeframe": "5m",
"params": {
"fast_period": 10,
"slow_period": 25
},
"contextTimeframes": ["15m", "1h"]
}
FieldTypeRequiredDescription
templateIdstring or nullConditionalTemplate to run. Required if code is not provided.
codestring or nullConditionalCustom Python strategy code. Required if templateId is not provided.
instrumentstringYesInstrument symbol (e.g., "NQ", "ES", "GC")
startDatestringYesStart date in YYYY-MM-DD format
endDatestring or nullNoEnd date. Defaults to end of the start date session.
timeframestringYesBar timeframe (e.g., "1m", "5m", "15m")
paramsobject or nullNoParameter overrides for the template. Keys must match template param names.
contextTimeframesarray or nullNoAdditional timeframes for multi-timeframe analysis (e.g., ["15m", "1h"])

Response

{
"success": true,
"errorCode": 0,
"errorMessage": null,
"executionId": "exec_abc123",
"status": "running"
}
FieldTypeDescription
executionIdstringUnique identifier for this execution. Use to track status.
statusstringInitial status: "running"

Example

const response = await fetch("https://api.test-max.com/api/playground/run", {
method: "POST",
headers: { "Content-Type": "application/json" },
credentials: "include", // Include session cookie
body: JSON.stringify({
templateId: "sma-crossover",
instrument: "NQ",
startDate: "2025-01-15",
timeframe: "5m",
params: { fast_period: 8, slow_period: 21 },
}),
});
const data = await response.json();
console.log(`Execution started: ${data.executionId}`);

Limits

LimitValue
Max concurrent executions per user1
Execution timeout10 minutes
Max script size200 KB

POST /api/playground/stop

Stop a running backtest execution.

URL: POST /api/playground/stop

Authentication: Cookie-based JWT. Pro plan required.

Request body

{}

No body fields are required. The server stops the current user’s active execution.

Response

{
"success": true,
"errorCode": 0,
"errorMessage": null
}

POST /api/playground/speed

Set the playback speed for a running backtest.

URL: POST /api/playground/speed

Authentication: Cookie-based JWT. Pro plan required.

Request body

{
"speed": 25
}
FieldTypeRequiredDescription
speednumberYesSpeed multiplier from 1 (slowest) to 50 (fastest)

Response

{
"success": true,
"errorCode": 0,
"errorMessage": null
}

Strategies

GET /api/playground/strategies

List all saved strategies for the authenticated user.

URL: GET /api/playground/strategies

Authentication: Cookie-based JWT. Pro plan required.

Response

{
"success": true,
"errorCode": 0,
"errorMessage": null,
"strategies": [
{
"id": "strat_abc123",
"name": "My SMA Strategy",
"instrument": "NQ",
"timeframe": "5m",
"createdAt": "2025-01-10T08:30:00Z",
"updatedAt": "2025-01-14T16:45:00Z"
}
]
}
FieldTypeDescription
strategiesarrayList of saved strategy summaries
strategies[].idstringUnique strategy ID
strategies[].namestringStrategy name
strategies[].instrumentstringDefault instrument
strategies[].timeframestringDefault timeframe
strategies[].createdAtstringISO 8601 creation timestamp
strategies[].updatedAtstringISO 8601 last-modified timestamp

POST /api/playground/strategies/save

Save a new strategy or update an existing one.

URL: POST /api/playground/strategies/save

Authentication: Cookie-based JWT. Pro plan required.

Request body

{
"name": "My Custom Strategy",
"code": "# Strategy code here\nfor i in range(MAX_BARS):\n bar = get_next_bar()\n ...",
"instrument": "NQ",
"timeframe": "5m",
"params": {
"fast_period": 10,
"slow_period": 25,
"stop_loss": 20
}
}
FieldTypeRequiredDescription
namestringYesStrategy name
codestringYesFull Python strategy code
instrumentstringYesDefault instrument symbol
timeframestringYesDefault timeframe
paramsobjectYesDefault parameter values

Response

{
"success": true,
"errorCode": 0,
"errorMessage": null,
"id": "strat_abc123"
}
FieldTypeDescription
idstringThe ID of the saved strategy (new or updated)

GET /api/playground/strategies/:id

Get a saved strategy by ID, including the full code and parameters.

URL: GET /api/playground/strategies/:id

Authentication: Cookie-based JWT. Pro plan required.

URL parameters

ParameterTypeDescription
idstringStrategy ID

Response

{
"success": true,
"errorCode": 0,
"errorMessage": null,
"strategy": {
"id": "strat_abc123",
"name": "My Custom Strategy",
"code": "# Strategy code here...",
"instrument": "NQ",
"timeframe": "5m",
"params": {
"fast_period": 10,
"slow_period": 25,
"stop_loss": 20
},
"createdAt": "2025-01-10T08:30:00Z",
"updatedAt": "2025-01-14T16:45:00Z"
}
}

DELETE /api/playground/strategies/:id

Delete a saved strategy.

URL: DELETE /api/playground/strategies/:id

Authentication: Cookie-based JWT. Pro plan required.

URL parameters

ParameterTypeDescription
idstringStrategy ID to delete

Response

{
"success": true,
"errorCode": 0,
"errorMessage": null
}

GET /api/playground/strategies/:id/runs

Get the run history for a saved strategy. Returns past backtest executions with their results.

URL: GET /api/playground/strategies/:id/runs

Authentication: Cookie-based JWT. Pro plan required.

URL parameters

ParameterTypeDescription
idstringStrategy ID

Response

{
"success": true,
"errorCode": 0,
"errorMessage": null,
"runs": [
{
"id": "run_xyz789",
"strategyId": "strat_abc123",
"instrument": "NQ",
"timeframe": "5m",
"startDate": "2025-01-15",
"endDate": "2025-01-15",
"status": "completed",
"totalPnl": 1250.00,
"totalTrades": 8,
"winRate": 62.5,
"params": {
"fast_period": 10,
"slow_period": 25
},
"startedAt": "2025-01-15T10:00:00Z",
"completedAt": "2025-01-15T10:02:34Z"
}
]
}
FieldTypeDescription
runsarrayList of past backtest runs
runs[].idstringUnique run ID
runs[].strategyIdstringParent strategy ID
runs[].instrumentstringInstrument traded
runs[].timeframestringBar timeframe used
runs[].startDatestringBacktest start date
runs[].endDatestringBacktest end date
runs[].statusstringRun status: "completed", "failed", "stopped", or "timeout"
runs[].totalPnlnumberNet P&L in USD
runs[].totalTradesnumberNumber of round-trip trades
runs[].winRatenumberWin percentage (0-100)
runs[].paramsobjectParameters used for this run
runs[].startedAtstringISO 8601 timestamp when the run started
runs[].completedAtstring or nullISO 8601 timestamp when the run completed (null if still running)