Skip to main content

MesoSim Backtest API

The MesoSim Backtest API provides programmatic access to create, manage, and analyze backtests. This API allows you to integrate MesoSim's powerful options backtesting capabilities into your own workflows and applications.

Authentication

All API endpoints require authentication using JWT Bearer token. You must include your API key in the Authorization header of all requests.

You can create an API key in the MesoSim web interface under the API Keys section.

Authorization: Bearer {your_api_key}

API access is available to users using a paid seat from the cluster.

API Endpoints

Create a New Backtest

Creates a new backtest job based on your strategy definition.

PUT /api/v1/backtest/new

Request Body

{
"StrategyDefinition": {
"StrategyName": "ShortPut",
"Backtest": {
"Name": "string", // Optional - a random name will be generated if set to "generate"
"Start": "YYYY-MM-DDT00:00:00",
"End": "YYYY-MM-DDT23:59:59",
"Cash": "125000"
},
"Symbol": "SPX",
"Structure": { /* legs, expirations, selectors */ },
"Entry": { /* schedule, conditions, vars */ },
"Adjustment": null,
"Exit": { /* schedule, conditions, targets */ },
"ExternalData": null,
"Settings": { "Sim": { /* fill, commission */ }, "Core": { /* margin, constraints */ } }
},
"Shared": false
}

Responses

Status CodeDescription
201Backtest created successfully
401Unauthorized - Invalid or missing API key
429Too many requests - Rate limit exceeded
500Internal server error
503Backend service unavailable

Response Body (201)

{
"BacktestId": "string",
"Name": "string"
}

List Backtests

Retrieves a list of your backtests filtered by date range and status.

GET /api/v1/backtests

Query Parameters

ParameterTypeRequiredDescription
startDateTimeYesStart date for filtering backtests
endDateTimeYesEnd date for filtering backtests
pageintegerYesPage number (zero-based)
pageSizeintegerNoNumber of results per page (max: 1000, default: 1000)
includeAnalyticsbooleanNoInclude performance metrics in response (default: false)
statusstringNoFilter by backtest status ('All', 'Created', 'Started', 'Finished', 'Failed'; default: 'All')

Responses

Status CodeDescription
200Success
400Bad request - Invalid parameters
401Unauthorized - Invalid or missing API key
429Too many requests - Rate limit exceeded
500Internal server error

Response Body (200)

[
{
"Id": "string",
"Name": "string",
"StrategyName": "string",
"Shared": true,
"State": "Finished",
"CreatedAt": "string",
"StartedAt": "string",
"FinishedAt": "string",
"/* additional fields if includeAnalytics=true */"
}
]

Get Backtest Analytics

Retrieves performance metrics for a specific backtest.

GET /api/v1/backtest/{id}/analytics

Path Parameters

ParameterTypeDescription
idstringBacktest ID

Responses

Status CodeDescription
200Success
401Unauthorized - Invalid or missing API key
403Forbidden - Access denied to this backtest
404Not found - Backtest ID doesn't exist
405Method not allowed - Backtest failed
425Too early - Backtest is still running
429Too many requests - Rate limit exceeded
500Internal server error

Response Body (200)

Detailed analytics object containing performance metrics for the backtest.

{
"StartPeriod": "2021-01-04T00:00:00",
"EndPeriod": "2025-03-24T00:00:00",
"StratTradeCnt": 210,
"StratWinCnt": 135,
"StratLossCnt": 75,
"StratAdjustmentCnt": 0,
"StratPtHitCnt": 0,
"StratSlHitCnt": 0,
"StratMaxDitReachedCnt": 0,
"StratSettlementCnt": 0,
"StratAvgDaysInTrade": 3.5667,
"StratAlpha": 0.4,
"StratBeta": -0.06,
"StratCagrPct": 46.66,
"StratCumRet": 403.22,
"StratMaxDd": -13.4,
"StratAvgDd": -0.47,
"StratAvgDdDays": 2,
"StratAvgUpMonth": 3.89,
"StratAvgDownMonth": -5.4,
"StratLongestDdDays": 160,
"StratInformRatio": 0.01,
"StratSharpe": 2.56,
"StratProbSharpe": 100,
"StratSmartSharpe": 2.45,
"StratSortino": 4.49,
"StratSmartSortino": 4.3,
"StratTreynor": -7269.28,
"StratCalmar": 3.48,
"StratOmega": 1.22,
"StratRSquared": 0,
"StratProfitFactor": 1.22,
"StratKellyCriterion": 9.22,
"StratAnnVolatility": 15.43,
"BmCagrPct": 10.7,
"BmCumRet": 53.55,
"BmMaxDd": -27.37,
"BmAvgDd": -0.33,
"BmAvgDdDays": 2,
"BmAvgUpMonth": 3.42,
"BmAvgDownMonth": -1.8,
"BmLongestDdDays": 745,
"BmInformRatio": 0.01,
"BmSharpe": 0.72,
"BmProbSharpe": 93.09,
"BmSmartSharpe": 0.69,
"BmSortino": 1.01,
"BmSmartSortino": 0.97,
"BmTreynor": null,
"BmCalmar": 0.39,
"BmOmega": 1.22,
"BmRSquared": 0,
"BmProfitFactor": 1.02,
"BmKellyCriterion": -1.73,
"BmAnnVolatility": 15.78
}

Get Strategy Definition

Retrieves the original strategy definition (v3) for a specific backtest.

GET /api/v1/backtest/{id}/strategy-definition

Path Parameters

ParameterTypeDescription
idstringBacktest ID

Responses

Status CodeDescription
200Success
401Unauthorized - Invalid or missing API key
403Forbidden - Access denied to this backtest
404Not found - Backtest ID doesn't exist
429Too many requests - Rate limit exceeded
500Internal server error

Response Body (200)

The original v3 strategy definition object.

{
"StrategyName": "ShortPut",
"Backtest": {
"Name": "api-test",
"Start": "2022-01-01T00:00:00",
"End": "2023-12-31T23:59:59",
"Cash": "100000"
},
"Description": "",
"Symbol": "SPX",
"Structure": { /* ... */ },
"Entry": { /* ... */ },
"Adjustment": null,
"Exit": { /* ... */ },
"ExternalData": null,
"Settings": { "Sim": { /* ... */ }, "Core": { /* ... */ } }
}

Get Backtest Events

Retrieves the events (fills, orders, etc.) for a specific backtest.

GET /api/v1/backtest/{id}/events

Path Parameters

ParameterTypeDescription
idstringBacktest ID

Query Parameters

ParameterTypeRequiredDescription
startDateTimeNoFilter events after this simulation time
endDateTimeNoFilter events before this simulation time
eventTypestringNoFilter by event type

Responses

Status CodeDescription
200Success
401Unauthorized - Invalid or missing API key
403Forbidden - Access denied to this backtest
404Not found - Backtest ID doesn't exist
429Too many requests - Rate limit exceeded
500Internal server error

Response Body (200)

List of blotter event objects matching the specified criteria.

Get Backtest NAVs

Retrieves NAV (Net Asset Value) data in CSV format for a specific backtest.

GET /api/v1/backtest/{id}/navs

Path Parameters

ParameterTypeDescription
idstringBacktest ID

Responses

Status CodeDescription
200Success - Returns CSV content
401Unauthorized - Invalid or missing API key
403Forbidden - Access denied to this backtest
404Not found - Backtest ID doesn't exist
429Too many requests - Rate limit exceeded
500Internal server error

Response Body (200)

CSV data containing backtest NAV values.

Get External Data

Retrieves the external data used in a specific backtest (if any).

GET /api/v1/backtest/{id}/external-data

Path Parameters

ParameterTypeDescription
idstringBacktest ID

Responses

Status CodeDescription
200Success - Returns zip file
401Unauthorized - Invalid or missing API key
403Forbidden - Access denied to this backtest
404Not found - Backtest ID or external data doesn't exist
429Too many requests - Rate limit exceeded
500Internal server error

Response Body (200)

ZIP file containing the external data used in the backtest.

Get Sharing Status

Retrieves the sharing status for a specific backtest.

GET /api/v1/backtest/{id}/sharing

Path Parameters

ParameterTypeDescription
idstringBacktest ID

Responses

Status CodeDescription
200Success
401Unauthorized - Invalid or missing API key
403Forbidden - Access denied to this backtest
404Not found - Backtest ID doesn't exist
429Too many requests - Rate limit exceeded
500Internal server error

Response Body (200)

{
"SharingEnabled": boolean
}

Update Sharing Status

Updates the sharing status for a specific backtest.

POST /api/v1/backtest/{id}/sharing

Path Parameters

ParameterTypeDescription
idstringBacktest ID

Query Parameters

ParameterTypeRequiredDescription
sharingEnabledbooleanYesNew sharing status

Responses

Status CodeDescription
200Success
401Unauthorized - Invalid or missing API key
403Forbidden - Access denied to this backtest
404Not found - Backtest ID doesn't exist
429Too many requests - Rate limit exceeded
500Internal server error

Delete Backtest

Deletes a specific backtest.

DELETE /api/v1/backtest/{id}

Path Parameters

ParameterTypeDescription
idstringBacktest ID

Query Parameters

ParameterTypeRequiredDescription
deleteModestringYesDeletion mode: 'Full', 'Details', or 'Soft'

Responses

Status CodeDescription
200Success
401Unauthorized - Invalid or missing API key
403Forbidden - Access denied to this backtest
404Not found - Backtest ID doesn't exist
429Too many requests - Rate limit exceeded
500Internal server error

Error Handling

All errors are returned with an appropriate HTTP status code. Common status codes:

  • 401 Unauthorized: Invalid or missing API key
  • 403 Forbidden: Access denied to the requested resource
  • 404 Not Found: Resource not found
  • 429 Too Many Requests: Rate limit exceeded
  • 500 Internal Server Error: Unexpected server error

Rate Limiting

The API implements rate limiting to ensure fair usage. If you exceed the rate limit, requests will fail with a 429 (Too Many Requests) status code. Back off and retry your request after a delay.

Using from Python

Merlin provides helper functions to conveniently access MesoSim APIs from Python. The functions handle parallel execution so that the cluster can be used efficiently.