Authentication and scopes
Exchange your API key for a token, and see what the scopes of your key allow.
Every route except POST /auth/token and the public catalogue GET /live/public expects a bearer
JWT (Authorization: Bearer <token>). The JWT is short-lived and comes from exchanging your API
key, issued in the web app, at POST /auth/token. The key itself is accepted on that one route
only.
Getting a token
curl -X POST https://api.qtsurfer.net/v1/auth/token
-H "X-API-Key: <your-api-key>" {
"access_token": "eyJhbGciOiJIUzI1NiJ9...",
"token_type": "Bearer",
"expires_in": 3600,
"scopes": { "backtests": ["read", "write", "execute"], "exchanges": ["read"] },
"tier": "free",
"key_exp": 1796465100
} | Field | Notes |
|---|---|
access_token | send it as Authorization: Bearer <token> on every other call |
token_type | always Bearer |
expires_in | seconds until the token expires. Ask for a new one before then, or on a 401 |
scopes | what your key may do, below |
tier | the subscription tier the token was issued for; it sets your limits, see Account |
key_exp | when your API key stops working, in seconds since epoch. Absent for a key that never expires. It is the key’s expiry, not the token’s, see When your key expires |
Send a User-Agent of your own. A request that carries the default of some HTTP libraries, Python’s urllib among them, is turned away at the network edge before it reaches the API, with a 403 whose body is the plain text error code: 1010 and not the JSON the API answers with. That is not a problem with your key: set a User-Agent header, the name of your tool is enough, and send the request again. curl and browsers send one already.
A key that is missing, unknown, revoked or expired is answered 401 with {"error": "invalid_credentials"} (AuthTokenRejected in the API reference). The answer is the same for all four: it does not say which, so
read the expiry of your key ahead of time, below, rather than from this answer.
A key that carries no scopes is answered 403 with the code apikey_without_scopes and no token (AuthTokenError): create a key with at least one scope in the web app.
When your key expires
An API key can have an expiry of its own. It is readable in three places, all the same moment, so a client can
rotate the key ahead of time instead of learning of it from a 401:
| Where | Field | Form |
|---|---|---|
the answer of POST /auth/token | key_exp | seconds since epoch, like the exp of the token |
| the token itself | the key_exp claim | the same number |
GET /account | apiKeyExpiresAt | ISO-8601 in UTC, or null |
key_expis absent from the answer for a key that never expires, andapiKeyExpiresAtis thennull.nullalso comes back for a token issued before the field existed (ask for a new one) and for a credential that is not an API key: it means that no key expiry applies, not that it is unknown.- It is the key’s expiry, not the token’s.
expires_inandexpare the token’s own hour. A token issued just before the key lapses keeps working until its ownexp; after the key’s expiry, asking for a new token with it is answered401. - Rotation: create the new key in the web app before
key_exp, switch your client to it, and the old key can lapse. A client that stores the key can readkey_expfrom any token answer and warn, say, a week before it.
Scopes
A key carries scopes: a map from a resource to the actions it may take on it, in lower case.
{ "backtests": ["read", "write", "execute"], "exchanges": ["read"] } - A scope is a resource and an action: a resource is listed only with at least one action. A key either may do something or it may not; a key with no scope is
{}. - You see them in two places, as the same map: the
scopesof the token answer above, and thescopesofGET /account, which needs no new token. - The token carries the scopes your key had when it was issued. Change the key’s scopes and the
change shows from the next token on, at most
expires_inseconds later. - An operation that needs a scope your key does not carry is refused with
403and the codeinsufficient_scope(below). The tables below say which scope each operation requires.
Resources and actions
| Resource | Actions | Covers |
|---|---|---|
exchanges | read | the list of exchanges, their instruments and pools |
market_data | read | the hourly ticker and kline downloads |
strategies | read, write | list, inspect and read the source of a strategy; compile, validate and delete one |
backtests | read, write, execute | prepare, run, sweep and cancel backtests; read their status and results |
datasets | read, write | list and read your datasets and collections; create, upload, import, move and delete datasets; create, rename and delete collections |
live | read, write, execute | read live runs, their signals and paper accounts; change a run; start, stop and command one, and manage its stream |
signals | read, write | read your signal channels, their notices, offers and codes, your subscriptions and what they received; create, change and delete a channel, publish a notice, create offers, mint and revoke codes, redeem a code, renew or cancel a subscription and feed runs from it |
read lists and gets. write creates, changes, cancels or deletes without running anything. execute starts a run: a backtest, a sweep, a live run.
The scope each operation requires
Exchanges and market data — Market data
| Operation | Scope |
|---|---|
GET /exchanges, GET /exchange/{exchangeId}/instruments, GET /exchange/{exchangeId}/{segment}/instruments | exchanges : read |
GET /exchange/{exchangeId}/tickers/{base}/{quote}, GET /exchange/{exchangeId}/klines/{base}/{quote} | market_data : read |
Strategies — Strategies
| Operation | Scope |
|---|---|
GET /strategies, GET /strategy/{strategyId}, GET /strategy/{strategyId}/code | strategies : read |
POST /strategy, POST /strategy/{strategyId}/validate, DELETE /strategy/{strategyId} | strategies : write |
Backtests and sweeps — Backtests, Parameter sweeps
| Operation | Scope |
|---|---|
POST …/prepare, DELETE …/execute/{jobId}, DELETE …/executeSweep/{requestId}/{sweepId} | backtests : write |
POST …/execute, POST …/executeSweep/{requestId} | backtests : execute |
GET …/prepare/{jobId}, GET …/execute/{jobId}, GET …/executeSweep/… (result, sensitivity, equity curve) | backtests : read |
Datasets — Datasets
| Operation | Scope |
|---|---|
GET /datasets, GET /datasets/{datasetId}, GET /datasets/{datasetId}/uploads/{uploadId}, GET /datasets/{datasetId}/imports/{importId}, GET /collections, GET /collections/{collectionId} | datasets : read |
POST /datasets, PATCH /datasets/{datasetId}, DELETE /datasets/{datasetId}, POST /datasets/{datasetId}/uploads, POST /datasets/{datasetId}/uploads/{uploadId}/finalize, POST /datasets/imports, POST /collections, PATCH /collections/{collectionId}, DELETE /collections/{collectionId} | datasets : write |
Live runs — Live execution, Paper trading
| Operation | Scope |
|---|---|
GET /live, GET /live/{runId}, GET /strategy/{strategyId}/live, GET /live/{runId}/signals, GET /live/{runId}/deliveries, GET /live/{runId}/trades, GET /live/{runId}/instruments, GET /live/{runId}/paper, GET /live/{runId}/paper/equity, POST /live/token | live : read |
PATCH /live/{runId}, PUT /live/{runId}/params | live : write |
POST /strategy/{strategyId}/live, DELETE /strategy/{strategyId}/live, POST /live/{runId}/commands, POST /live/{runId}/stream, DELETE /live/{runId}/stream | live : execute |
Signal channels — Signal channels
| Operation | Scope |
|---|---|
GET /signals/channels, GET /signals/channels/{channelId}, GET /signals/channels/{channelId}/notices, GET /signals/channels/{channelId}/offers, GET /signals/offers/{offerId}/codes, GET /signals/subscriptions, GET /signals/subscriptions/{subscriptionId}, GET /signals/subscriptions/{subscriptionId}/deliveries | signals : read |
POST /signals/channels, PATCH /signals/channels/{channelId}, DELETE /signals/channels/{channelId}, POST /signals/channels/{channelId}/notices, POST /signals/channels/{channelId}/offers, POST /signals/offers/{offerId}/codes, DELETE /signals/codes/{codeId}, POST /signals/subscriptions, DELETE /signals/subscriptions/{subscriptionId}, POST /signals/subscriptions/{subscriptionId}/renew, POST /signals/subscriptions/{subscriptionId}/runs, DELETE /signals/subscriptions/{subscriptionId}/runs/{runId} | signals : write |
No scope: GET /account and GET /account/usage need a valid token and nothing more; GET /live/public and GET /signals/channels/public need no token at all, and POST /signals/hook/{hookKey} takes the channel’s secret address as its credential instead.
When a scope is missing
{
"code": "insufficient_scope",
"message": "This API key does not have the scope datasets:write.",
"required": "datasets:write"
} The answer is 403 and required names the scope the operation needs, as resource:action. Give
the key that scope in the web app, then ask for a new token: the scopes of a token are the ones the
key had when it was issued, so a token you already hold keeps the old ones until it expires.