Quickstart
From an API key to the equity curve of your first backtest, in six requests.
A strategy, a stretch of historical data and a result: six requests, in this order. Pick a step in the diagram to see what it sends, what it returns and which step uses that.
Every request goes to https://api.qtsurfer.net/v1. The examples read your API key from the environment, so set it once:
export QTSURFER_APIKEY=<your-api-key> The key needs these scopes: strategies : write, and backtests : read, write and execute. Scopes lists
what each operation requires.
Get a token
Exchange the API key for a short-lived token. Every other request sends it as Authorization: Bearer <token>.
curl -X POST https://api.qtsurfer.net/v1/auth/token
-H "X-API-Key: $QTSURFER_APIKEY" {
"access_token": "eyJhbGciOiJIUzI1NiJ9...",
"token_type": "Bearer",
"expires_in": 3600,
"scopes": { "backtests": ["read", "write", "execute"], "strategies": ["read", "write"] },
"tier": "free"
} Keep access_token in TOKEN; the next steps use it.
export TOKEN=<access_token> Compile a strategy
Save this strategy as rsi-reversion.qts: it buys when the 14-period RSI of a one-minute window falls below rsiLow and sells when it
rises above rsiHigh.
strategy "RSI reversion"
param rsiLow = 30 "Oversold"
param rsiHigh = 70 "Overbought"
instruments */usdt
setup:
rsi(14) window m1 {
if (actual < rsiLow) emitBuy(price);
if (actual > rsiHigh) emitSell(price);
} Send the source as it is, with Content-Type: text/plain. The platform compiles it and gives back an id.
curl -X POST https://api.qtsurfer.net/v1/strategy
-H "Authorization: Bearer $TOKEN"
-H "Content-Type: text/plain"
--data-binary @rsi-reversion.qts {
"strategyId": "2tlusl6zjgr1no3folhvqi",
"name": "RSI reversion",
"language": "qtscript",
"declaredProperties": [ ... ],
"requires": []
} A Java class goes the same way, from a .java file: see Strategies and Java strategy coding.
export STRATEGY_ID=<strategyId> Prepare the data
A backtest runs over data the platform has prepared for it: an instrument, a time range and, optionally, a cadence. The request returns
a jobId at once. Asking again with the same parameters returns the same job.
curl -X POST https://api.qtsurfer.net/v1/backtest/binance/ticker/prepare
-H "Authorization: Bearer $TOKEN"
-H "Content-Type: application/json"
-d '{"instrument":"BTC/USDT","from":"2026-11-25T10:00:00Z","to":"2026-11-25T16:00:00Z"}'
# → 202 {"jobId": "13sHzYeSKxkkBpV6Ttn0VO", "cadence": "1s"} ticker is the kind of data (ticker, kline or funding) and binance the exchange. Without a cadence the data is prepared at
the finest one your plan includes, see Cadences by plan.
export PREPARE_JOB_ID=<jobId> Check that the data is ready before running anything on it: ask until status is Completed, which is how the prepare of one
instrument always ends. coverageRatio says how much of the range has data.
curl https://api.qtsurfer.net/v1/backtest/binance/ticker/prepare/$PREPARE_JOB_ID
-H "Authorization: Bearer $TOKEN" {
"status": "Completed",
"dataFrom": "2026-11-25T10:00:00Z",
"dataTo": "2026-11-25T16:00:00Z",
"coverageRatio": 1.0,
"totalHours": 6,
"hoursWithData": 6
} Run the backtest
Run the strategy over the prepared data. The request names both, and returns the jobId of the run.
curl -X POST https://api.qtsurfer.net/v1/backtest/binance/ticker/execute
-H "Authorization: Bearer $TOKEN"
-H "Content-Type: application/json"
-d "{"prepareJobId":"$PREPARE_JOB_ID","strategyId":"$STRATEGY_ID"}"
# → 202 {"jobId": "22SNBvRoRb2XyZu9LSaBFn"} export EXECUTE_JOB_ID=<jobId> Poll for the result
Ask for the run until it has finished. While it runs, state.status is Started; a 202 with an empty body also means the result
cannot be read yet. Stop when state.status is Completed (Failed and Aborted end it too).
curl https://api.qtsurfer.net/v1/backtest/binance/ticker/execute/$EXECUTE_JOB_ID
-H "Authorization: Bearer $TOKEN" Read the result
The finished run carries the results of the strategy and its equity curve in the same response.
{
"state": { "status": "Completed" },
"results": {
"pnlTotal": -9.91,
"pnlTotalPercent": -9.91,
"totalTrades": 54,
"winRate": 0.0926,
"sharpeRatio": -0.65,
"maxDrawdownPercent": 10.31,
"equityCurve": {
"points": [
{ "timestamp": 1795600800000, "equity": 100.0 },
{ "timestamp": 1795600920017, "equity": 99.87 }
],
"meta": { "inputPointCount": 55, "outputPointCount": 55, "outMode": "ARRAY" }
}
}
} The numbers are those of this strategy over this range: change the strategy or the range and they change. How the points are shaped, resampled or sent in a compact form is in Equity curves.
The same in one call
The SDKs wrap these requests. The TypeScript and Java ones do the whole flow, compile, prepare, run and poll, in a single call; the
Python one gives you each stage and leaves the polling to you. All three read the API key from QTSURFER_APIKEY, and the strategy is
the rsi-reversion.qts file of above.
# pip install qtsurfer-sdk
import time
from qtsurfer_sdk import auth
session = auth() # reads QTSURFER_APIKEY from the environment
with open("rsi-reversion.qts", encoding="utf-8") as f:
compiled = session.compile_strategy(f.read())
prepared = session.prepare(
exchange_id="binance", type_="ticker", instrument="BTC/USDT",
from_="2026-11-25T10:00:00Z", to="2026-11-25T16:00:00Z",
)
while session.get_prepare_status(
exchange_id="binance", type_="ticker", job_id=prepared.job_id
).status != "Completed":
time.sleep(2)
execution = session.execute(
exchange_id="binance", type_="ticker",
prepare_job_id=prepared.job_id, strategy_id=compiled.strategy_id,
)
while True:
response = session.get_backtest_result(
exchange_id="binance", type_="ticker", job_id=execution.job_id
)
if response.status_code == 200 and response.json()["state"]["status"] == "Completed":
break
time.sleep(2)
results = response.json()["results"]
print("PnL:", results["pnlTotal"])
print("Trades:", results["totalTrades"])
print("Equity points:", len(results["equityCurve"]["points"])) // npm install @qtsurfer/sdk
import { authenticate } from '@qtsurfer/sdk';
import { readFileSync } from 'node:fs';
const qts = await authenticate(); // reads QTSURFER_APIKEY from the environment
const result = await qts.executeBacktest({
strategy: readFileSync('rsi-reversion.qts', 'utf8'),
exchangeId: 'binance',
instrument: 'BTC/USDT',
from: '2026-11-25T10:00:00Z',
to: '2026-11-25T16:00:00Z',
});
console.log('PnL:', result.pnlTotal);
console.log('Trades:', result.totalTrades);
console.log('Equity points:', result.equityCurve?.points?.length); // com.qtsurfer:sdk-java, see Clients and SDKs for the dependency
import com.qtsurfer.api.client.model.ResultMap;
import com.qtsurfer.api.sdk.BacktestRequest;
import com.qtsurfer.api.sdk.QTSurfer;
import com.qtsurfer.api.sdk.auth.AuthenticatedClient;
import java.nio.file.Files;
import java.nio.file.Path;
public class Quickstart {
public static void main(String[] args) throws Exception {
AuthenticatedClient qts = QTSurfer.authenticate(); // reads QTSURFER_APIKEY from the environment
ResultMap result = qts.executeBacktest(BacktestRequest.builder()
.strategy(Files.readString(Path.of("rsi-reversion.qts")))
.exchangeId("binance")
.instrument("BTC/USDT")
.from("2026-11-25T10:00:00Z")
.to("2026-11-25T16:00:00Z")
.build()).join();
System.out.println("PnL: " + result.getPnlTotal());
System.out.println("Trades: " + result.getTotalTrades());
System.out.println("Equity points: " + result.getEquityCurve().getPoints().size());
}
}Clients and SDKs says how to install each one and where its reference is.
Where to go next
- Backtests: every field of the requests above, the other kinds of data and how a run is cancelled.
- Parameter sweeps: run the same strategy over a grid of parameter values, instead of once.
- Equity curves: the shapes of the curve and how to ask for each.
- Strategies in QTScript and in Java: write your own.
- Live execution and paper trading: run a strategy on a live feed.
- MCP server: drive the same flow from an assistant.