Skip to content

Run a backtest

POST https://rest.haasapi.com/v1/partner/users/{user_id}/backtests

Simulates a strategy for an end-user against historical data, using the user’s live exchange settings and account. config carries the strategy’s settings by their snake_case keys (see GET /v1/partner/strategies), including symbol (the market). Answers 202 with a backtest id; poll GET /v1/partner/backtests/{backtest_id}/status until it is completed, then read the results. The backtest belongs to you - the reads take only its id.

Requires the partner scope.

{
"strategy": "spot_grid",
"config": {
"symbol": "BTC_USDT",
"lower_limit": 25000,
"upper_limit": 35000,
"grid_count": 20,
"investment_asset": "USDT",
"investment_amount": 500
},
"start_at": "2026-08-28T20:30:00Z",
"end_at": "2026-08-29T20:30:00Z"
}
Field Type Description
strategy WhiteLabelScriptType The strategy template to simulate (from GET /v1/partner/strategies).
config object The strategy’s settings by their snake_case keys, including symbol (the market).
start_at string Start of the simulation window, an RFC 3339 timestamp (e.g. 2026-08-28T20:30:00Z).
end_at string End of the simulation window, an RFC 3339 timestamp. Must be after start_at.
Terminal window
curl "https://rest.haasapi.com/v1/partner/users/{user_id}/backtests" \
-X POST \
-H "Authorization: Bearer hk_live_YOUR_KEY" \
-H "Content-Type: application/json" \
-d '{"strategy":"spot_grid","config":{"symbol":"BTC_USDT","lower_limit":25000,"upper_limit":35000,"grid_count":20,"investment_asset":"USDT","investment_amount":500},"start_at":"2026-08-28T20:30:00Z","end_at":"2026-08-29T20:30:00Z"}'

202 Accepted - the job was queued; poll its status. Returns a PartnerBacktestJob.

{
"backtest_id": "6f19dc7db5904c27a87c5d684ff8a889",
"status": "queued",
"service_id": "se-1f2c9a"
}
Field Type Description
backtest_id string The backtest id - use it for every status/results/logs/positions/cancel call.
status string Always queued on acceptance.
service_id string The internal execution id (opaque).

All errors are RFC 9457 problem documents.

Status Description
400 The request is malformed (invalid limit, unusable cursor, …). (code: invalid_request)
401 Missing, malformed, disabled, or revoked API key. (code: invalid_api_key)
404 No accessible end-user with that id. (code: user_not_found)
409 A request with this Idempotency-Key is still being processed. (code: idempotency_in_progress)
422 The strategy is not valid for this end-user’s market. (code: strategy_not_allowed) The strategy configuration or window was rejected - see the message. (code: invalid_config) The Idempotency-Key was already used with a different request. (code: idempotency_key_reuse)
500 An unexpected error inside the API. Nothing about the request caused it; retry, and quote the instance value if it persists. (code: internal_error)
502 An internal service answered in a way the API could not serve. Retry. (code: upstream_error)
503 The request could not be served right now. Retry with the same key - do not discard it. (code: temporarily_unavailable) The account’s margin settings could not be read; retry. (code: price_unavailable)
504 An internal service did not answer within the deadline. Retry with backoff. (code: upstream_timeout)
{
"type": "https://docs.haasapi.com/errors/invalid_request",
"title": "Invalid request",
"status": 400,
"detail": "The request is malformed (invalid limit, unusable cursor, …).",
"code": "invalid_request"
}