Log in

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
}
FieldNotes
access_tokensend it as Authorization: Bearer <token> on every other call
token_typealways Bearer
expires_inseconds until the token expires. Ask for a new one before then, or on a 401
scopeswhat your key may do, below
tierthe subscription tier the token was issued for; it sets your limits, see Account
key_expwhen 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:

WhereFieldForm
the answer of POST /auth/tokenkey_expseconds since epoch, like the exp of the token
the token itselfthe key_exp claimthe same number
GET /accountapiKeyExpiresAtISO-8601 in UTC, or null
  • key_exp is absent from the answer for a key that never expires, and apiKeyExpiresAt is then null. null also 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_in and exp are the token’s own hour. A token issued just before the key lapses keeps working until its own exp; after the key’s expiry, asking for a new token with it is answered 401.
  • 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 read key_exp from 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 scopes of the token answer above, and the scopes of GET /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_in seconds later.
  • An operation that needs a scope your key does not carry is refused with 403 and the code insufficient_scope (below). The tables below say which scope each operation requires.

Resources and actions

ResourceActionsCovers
exchangesreadthe list of exchanges, their instruments and pools
market_datareadthe hourly ticker and kline downloads
strategiesread, writelist, inspect and read the source of a strategy; compile, validate and delete one
backtestsread, write, executeprepare, run, sweep and cancel backtests; read their status and results
datasetsread, writelist and read your datasets and collections; create, upload, import, move and delete datasets; create, rename and delete collections
liveread, write, executeread live runs, their signals and paper accounts; change a run; start, stop and command one, and manage its stream
signalsread, writeread 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

OperationScope
GET /exchanges, GET /exchange/{exchangeId}/instruments, GET /exchange/{exchangeId}/{segment}/instrumentsexchanges : read
GET /exchange/{exchangeId}/tickers/{base}/{quote}, GET /exchange/{exchangeId}/klines/{base}/{quote}market_data : read

Strategies — Strategies

OperationScope
GET /strategies, GET /strategy/{strategyId}, GET /strategy/{strategyId}/codestrategies : read
POST /strategy, POST /strategy/{strategyId}/validate, DELETE /strategy/{strategyId}strategies : write

Backtests and sweeps — Backtests, Parameter sweeps

OperationScope
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

OperationScope
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

OperationScope
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/tokenlive : read
PATCH /live/{runId}, PUT /live/{runId}/paramslive : write
POST /strategy/{strategyId}/live, DELETE /strategy/{strategyId}/live, POST /live/{runId}/commands, POST /live/{runId}/stream, DELETE /live/{runId}/streamlive : execute

Signal channels — Signal channels

OperationScope
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}/deliveriessignals : 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.