Skip to Content
NeurotraderDocs
Getting started

First simulation with the API

A walkthrough from an access token to the results of a first backtest, using curl against the engine on your computer.

You want to run a backtest from a script instead of the app. This tutorial takes you from nothing to a finished run: you check that the engine answers, create a simulation, give it market data and an algorithm, start it, wait for it to finish and read what it did.

The example backtests SMA Crossover on BTCUSDT with hourly candles over 2024, starting with 10,000 USDT. Every request is a curl command you can paste into a terminal. Responses are trimmed to the fields the tutorial uses.

Prerequisites

You need three things:

  • Neurotrader installed and running. The engine runs on your own computer and listens on the loopback address only. The examples use http://127.0.0.1:8080. See Installation.
  • A Neurotrader account, and this computer enrolled as one of its devices. Signing in to the app once does both. See Sign-in and plans.
  • An access token. Every request except the health check carries one. Authentication explains where a script gets it.

Put the token and the address in shell variables, so the commands below work as written:

export ENGINE=http://127.0.0.1:8080
export TOKEN="<your access token>"

Runner: the API's name for a simulation

In the API, the thing the app calls a simulation is a runner, and its routes live under /v1/runner. A run of it is a run, and the id of a run is also called its context id.

Health check

GET /v1/health is the one route that needs no token. Use it to find out whether the engine is running before you look for any other cause.

curl $ENGINE/v1/health
{
  "status": "ok",
  "time": "2026-03-02T09:14:07.512+00:00",
  "version": "0.1.0"
}

Now check the token with a route that needs one:

curl -H "Authorization: Bearer $TOKEN" $ENGINE/v1/info

A JSON object with the engine's name and version means the token is accepted. A 401 means it is not: the details.reason field says why. See Errors.

Instrument and asset ids

The API names instruments and assets by id, not by symbol, because one symbol can mean several things. Look up the BTCUSDT listing on Binance:

curl -H "Authorization: Bearer $TOKEN" \
  "$ENGINE/v1/ticker?symbol=BTCUSDT&market=binance"
[
  {
    "id": "1f8b39a6-6ed8-4557-babe-6fa3b2372e07",
    "symbol": "BTCUSDT",
    "base": "870c13af-d5ed-46c7-a0b1-341efa5d8135",
    "quote": "4e058fc7-4509-4bb4-a276-8f35aa87e5cc",
    "market": "binance",
    "broker": "binance",
    "provider": "binance"
  }
]

You need two of these ids. id is the instrument (the API calls it a ticker). quote is the asset the instrument is priced in, here USDT. The account in this tutorial is funded in USDT and reports its results in USDT.

export TICKER=1f8b39a6-6ed8-4557-babe-6fa3b2372e07
export USDT=4e058fc7-4509-4bb4-a276-8f35aa87e5cc

Runner creation

Create a single-account simulation with 10,000 USDT and a fee of 0.1% on both sides. primary_quote_asset is the currency every result is measured in. It is required, and it must be one of the assets you fund.

curl -X POST $ENGINE/v1/runner \
  -H "Authorization: Bearer $TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "type": "simulation",
    "name": "SMA crossover on BTCUSDT",
    "initial_balances": [{ "asset": "'$USDT'", "amount": 10000 }],
    "primary_quote_asset": "'$USDT'",
    "maker_fee": 0.001,
    "taker_fee": 0.001
  }'

The engine answers 201 with the runner it created:

{
  "type": "simulation",
  "id": "0d6c3f0e-5a55-4b0e-9a57-3f2a1b7c9e11",
  "name": "SMA crossover on BTCUSDT",
  "status": "ready",
  "is_favorite": false,
  "data": {},
  "algorithms": {},
  "config": {
    "type": "simulated",
    "initial_holdings": { "4e058fc7-4509-4bb4-a276-8f35aa87e5cc": 10000.0 },
    "primary_quote_asset": "4e058fc7-4509-4bb4-a276-8f35aa87e5cc",
    "taker_fee": 0.001,
    "maker_fee": 0.001
  }
}
export RUNNER=0d6c3f0e-5a55-4b0e-9a57-3f2a1b7c9e11

The runner has no data and no algorithm, so it cannot run. That is a normal state: you fill it in with the next two requests. You can also send everything in one request, see Simulation creation with the API.

Data source

A data source is one instrument with a candle interval and a date range. Add hourly BTCUSDT candles for 2024. end is exclusive, and both instants are ISO 8601 in UTC.

curl -X POST $ENGINE/v1/runner/$RUNNER/data \
  -H "Authorization: Bearer $TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "type": "historical",
    "ticker": "'$TICKER'",
    "interval": "1h",
    "start": "2024-01-01T00:00:00Z",
    "end": "2025-01-01T00:00:00Z"
  }'

The answer is 201 with the id of the new data source, as a JSON string:

"b7e4c1a2-93f0-4c58-8a1d-6e2f0c9d4b35"
export DATA=b7e4c1a2-93f0-4c58-8a1d-6e2f0c9d4b35

You do not download anything here. The engine fetches the candles it is missing when the run starts.

Algorithm

List the algorithms the engine knows, and find the one you want:

curl -H "Authorization: Bearer $TOKEN" $ENGINE/v1/algorithms
[
  {
    "id": "3f2b6d1e-9b0a-4d5c-8f7e-1a2c4b6d8e05",
    "name": "SMA Crossover",
    "description": "Buys when a fast simple moving average crosses above a slow one, and sells when it crosses back below.",
    "parameter_schema": {
      "type": "object",
      "properties": {
        "fast_period": { "type": "integer", "minimum": 1, "default": 9 },
        "slow_period": { "type": "integer", "minimum": 2, "default": 21 }
      }
    },
    "available": true
  }
]

parameter_schema is a JSON Schema for the algorithm's parameters. available says whether the algorithm can run now. The built-in ones are described in Built-in algorithms.

Add the algorithm to the runner, with its parameters and the data source it reads:

curl -X POST $ENGINE/v1/runner/$RUNNER/algorithm \
  -H "Authorization: Bearer $TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "id": "3f2b6d1e-9b0a-4d5c-8f7e-1a2c4b6d8e05",
    "label": "SMA 9/21",
    "parameters": { "fast_period": 9, "slow_period": 21 },
    "data_sources": ["'$DATA'"]
  }'
{
  "result": "Success",
  "message": "Algorithm added to runner.",
  "timestamp": "2026-03-02T09:16:41.108Z"
}

What you added is an algorithm instance: this algorithm, with these parameters, on this runner. The engine gives the instance its own id, and the result routes ask for it. Read it from the runner, where algorithms is a map keyed by instance id:

curl -H "Authorization: Bearer $TOKEN" $ENGINE/v1/runner/$RUNNER
{
  "id": "0d6c3f0e-5a55-4b0e-9a57-3f2a1b7c9e11",
  "status": "ready",
  "algorithms": {
    "5c1d9a7e-2b64-4f03-b8a9-71e0d3c6f482": {
      "id": "3f2b6d1e-9b0a-4d5c-8f7e-1a2c4b6d8e05",
      "label": "SMA 9/21",
      "parameters": { "fast_period": 9, "slow_period": 21 },
      "data_sources": ["b7e4c1a2-93f0-4c58-8a1d-6e2f0c9d4b35"]
    }
  }
}
export INSTANCE=5c1d9a7e-2b64-4f03-b8a9-71e0d3c6f482

Run start

Start, stop, pause, resume and reset all go to one route, POST /v1/runner/{simulation_id}/operate. The body is the operation as a JSON string.

curl -X POST $ENGINE/v1/runner/$RUNNER/operate \
  -H "Authorization: Bearer $TOKEN" \
  -H "Content-Type: application/json" \
  -d '"start"'
{
  "result": "Success",
  "message": "Simulation started",
  "details": { "context": "e2a9f6b4-0c3d-4e7a-9f15-8b6d2a4c7e90" },
  "timestamp": "2026-03-02T09:17:02.330Z"
}

details.context is the id of the run that just started. Keep it:

export RUN=e2a9f6b4-0c3d-4e7a-9f15-8b6d2a4c7e90

If the runner cannot run as it is set up, the engine answers 409 with details.reason set to not_runnable and a sentence in details.message that names what is missing, for example that no data source is quoted in the primary quote asset. Fix the setup and start again.

Progress

The run works in the background. The first time you use a date range, the engine first downloads the candles, which takes longer than the backtest itself.

The simplest way to wait is to read the runner until its status is no longer running:

curl -s -H "Authorization: Bearer $TOKEN" $ENGINE/v1/runner/$RUNNER
{ "id": "0d6c3f0e-5a55-4b0e-9a57-3f2a1b7c9e11", "status": "running" }
status after the runMeaning
readyThe run ended. It finished, or you stopped it.
errorThe run failed. The run record says why.
pausedYou paused the run. Resume it to continue.

To follow a run as it happens, without polling, open the websocket at /v1/events and subscribe to the runner's id. You then receive update messages (such as the download's progress), progress events with a percentage, and a state_change when the run ends. See Realtime updates.

No record for a run in progress

The run routes below answer 404 until the run has ended. Wait for the status to leave running before you read results.

Results

Run record

GET /v1/runner/{id}/run/{run_id} returns how the run ended and its summary figures, per algorithm instance:

curl -H "Authorization: Bearer $TOKEN" \
  $ENGINE/v1/runner/$RUNNER/run/$RUN
{
  "id": "e2a9f6b4-0c3d-4e7a-9f15-8b6d2a4c7e90",
  "outcome": { "type": "completed" },
  "started_at": 1772443022330,
  "finished_at": 1772443031874,
  "steps_completed": 8784,
  "steps_total": 8784,
  "label": null,
  "tags": [],
  "results": {
    "algorithms": {
      "5c1d9a7e-2b64-4f03-b8a9-71e0d3c6f482": {
        "net_worth": {
          "starting_equity": 10000.0,
          "ending_equity": 11932.4,
          "peak": 13105.7,
          "return_absolute": 1932.4,
          "return_percent": 19.324,
          "max_drawdown_percent": 17.81
        },
        "activity": {
          "decisions": 212,
          "orders_submitted": 212,
          "orders_filled": 212,
          "orders_canceled": 0,
          "orders_rejected": 0,
          "orders_expired": 0,
          "fills": 212
        }
      }
    }
  }
}

The figures in this example are illustrative. Yours depend on the data.

  • outcome.type is completed when the run reached the end of its date range, cancelled when you stopped it, and failed (with a message) when something went wrong.
  • Everything under net_worth is measured in the primary quote asset. return_percent and max_drawdown_percent are percentages.
  • Times are milliseconds since the Unix epoch.

The record also holds a copy of the runner as it was when the run started, under runner, so you can always see which setup produced which result. Results explains each figure.

Equity curve

GET /v1/runner/{id}/run/{run_id}/performance returns the account's value over time. Ask for one point per day, with both the percentage change and the value:

curl -H "Authorization: Bearer $TOKEN" \
  "$ENGINE/v1/runner/$RUNNER/run/$RUN/performance?algorithm=$INSTANCE&resolution=1d&type=both"
{
  "resolution": "1d",
  "algorithm_id": "5c1d9a7e-2b64-4f03-b8a9-71e0d3c6f482",
  "asset_id": "4e058fc7-4509-4bb4-a276-8f35aa87e5cc",
  "type": "both",
  "reductions": { "percent": "last", "total": "last" },
  "from": 1704067200000,
  "to": 1735603200000,
  "points": [
    [1704067200000, 0.0, 10000.0],
    [1704153600000, 1.92, 10192.0],
    [1704240000000, -0.41, 9959.0]
  ],
  "next_cursor": null,
  "prev_cursor": null
}

Each point is an array: the time first, then the figures in the order you asked for them in type. With both, that is the percentage change since the start and then the account's value. A page holds 1,000 points unless you set limit (up to 5,000). When next_cursor is not null, pass it as from, as an ISO 8601 instant ending in Z, to read the next page.

Orders and candles

Two more routes give you the detail behind the curve. Both take the instance id as algorithm and the instrument id as ticker:

# Every order the algorithm issued on the instrument
curl -H "Authorization: Bearer $TOKEN" \
  "$ENGINE/v1/runner/$RUNNER/run/$RUN/actions?algorithm=$INSTANCE&ticker=$TICKER"

# The candles it saw, with its indicator values, folded to one per day
curl -H "Authorization: Bearer $TOKEN" \
  "$ENGINE/v1/runner/$RUNNER/run/$RUN/data?algorithm=$INSTANCE&ticker=$TICKER&interval=1d"

Next steps

Every time you start the runner again, the engine records a new run, and GET /v1/runner/{id}/run lists them all. Change a parameter with PATCH /v1/runner/{simulation_id}/algorithm/{algorithm_id}, start again, and compare the two runs.

When you are done with the example, delete the runner and everything it recorded:

curl -X DELETE -H "Authorization: Bearer $TOKEN" $ENGINE/v1/runner/$RUNNER

On this page