Class AuthenticatedClient
Created by QTSurfer.authenticate(String) (or the
overload that accepts an AuthOptions). Wraps the underlying
api-client, owns a JWT (in memory by default, or in the provided
TokenStore), and transparently re-exchanges the API key for a
fresh JWT when a call returns 401.
Exposes the same workflow surface as QTSurfer: compile,
backtest, exchanges, instruments, tickers,
klines. Method semantics are unchanged — only the bearer token
management differs.
Refresh policy: a 401 from any call routed through the generated
api-client (prepare, execute, result polling, exchanges, instruments,
tickers, klines) triggers exactly one POST /v1/auth/token
exchange, then the original call is retried once; a second 401 is
surfaced to the caller. The one exception is compile, which talks
to its endpoint directly and does not participate in this retry — see
compile(String, BacktestOptions).
-
Method Summary
Modifier and TypeMethodDescriptionstatic AuthenticatedClientEquivalent toauthenticate(String, AuthOptions)with anullapikey (resolved fromQTSURFER_APIKEY) andAuthOptions.defaults().static AuthenticatedClientauthenticate(String apikey) Equivalent toauthenticate(String, AuthOptions)withAuthOptions.defaults().static AuthenticatedClientauthenticate(String apikey, AuthOptions opts) Mint a fresh session from the given API key.CompletableFuture<com.qtsurfer.api.client.model.ResultMap>backtest(BacktestRequest request) Equivalent tobacktest(BacktestRequest, BacktestOptions)withBacktestOptions.defaults().CompletableFuture<com.qtsurfer.api.client.model.ResultMap>backtest(BacktestRequest request, BacktestOptions opts) Run the full compile → prepare → execute pipeline and resolve once the run reaches a terminal state (completed, failed, or canceled).voidclear()Drop the cached token (in memory and in the store).compile(BacktestRequest request) Convenience overload that compilesBacktestRequest.strategy()withBacktestOptions.defaults(), ignoring every other field of the request.compile(BacktestRequest request, BacktestOptions opts) Convenience overload that compilesBacktestRequest.strategy()with the given options, ignoring every other field of the request.Equivalent tocompile(String, BacktestOptions)withBacktestOptions.defaults().compile(String source, BacktestOptions opts) Compile strategy source into a reusableStrategyhandle.com.qtsurfer.api.client.model.AuthTokenResponseReturn the cached token, seeding from theTokenStoreon first use, and minting a new one if neither cache nor store hold one.List<com.qtsurfer.api.client.model.Exchange>List available exchanges on the platform.List<com.qtsurfer.api.client.model.InstrumentDetail>instruments(String exchangeId) List instruments available on the given exchange, including per-data-type coverage and market info.Equivalent toklines(String, String, String, String, DownloadFormat)withDownloadFormat.LASTRA.Download one hour of klines for an instrument as a streamingInputStream.options()Configuration in use by this session.com.qtsurfer.api.client.model.AuthTokenResponserefresh()Force a fresh JWT exchange viaPOST /v1/auth/token.Equivalent totickers(String, String, String, String, DownloadFormat)withDownloadFormat.LASTRA.Download one hour of raw tickers for an instrument as a streamingInputStream.com.qtsurfer.api.client.model.AuthTokenResponsetoken()Most recently minted token, ornullif no exchange has happened yet.
-
Method Details
-
options
Configuration in use by this session. -
token
public com.qtsurfer.api.client.model.AuthTokenResponse token()Most recently minted token, ornullif no exchange has happened yet. -
refresh
public com.qtsurfer.api.client.model.AuthTokenResponse refresh()Force a fresh JWT exchange viaPOST /v1/auth/token. Bypasses the cache; the returned token is also written to the configuredTokenStore. -
ensureToken
public com.qtsurfer.api.client.model.AuthTokenResponse ensureToken()Return the cached token, seeding from theTokenStoreon first use, and minting a new one if neither cache nor store hold one. -
clear
public void clear()Drop the cached token (in memory and in the store). -
compile
Equivalent tocompile(String, BacktestOptions)withBacktestOptions.defaults(). -
compile
Compile strategy source into a reusableStrategyhandle.Issues a single synchronous HTTP request; the compile endpoint returns the
strategyIddirectly, so a failing compile surfaces immediately asQTSStrategyCompileErrorrather than on a later poll. A429means the platform was holding too many compilations and the source was never judged, so it is safe to retry; any other error status reflects a judgment on the submitted code and will not succeed by retrying alone. Onlyopts.onProgress()is used; polling and timeout settings do not apply to this stage.Two behaviors this session normally guarantees do not apply here: a
401from the compile endpoint is not retried after a token refresh (the endpoint is called directly rather than through the generated client, so the failure is never recognized as unauthorized), and token resolution itself happens synchronously before the request is sent — on a session with no cached or stored token, this call blocks to mint one and throwsQTSAuthErrordirectly rather than through the returned future. -
compile
Convenience overload that compilesBacktestRequest.strategy()withBacktestOptions.defaults(), ignoring every other field of the request. Seecompile(String, BacktestOptions). -
compile
Convenience overload that compilesBacktestRequest.strategy()with the given options, ignoring every other field of the request. Seecompile(String, BacktestOptions). -
backtest
Equivalent tobacktest(BacktestRequest, BacktestOptions)withBacktestOptions.defaults(). -
backtest
public CompletableFuture<com.qtsurfer.api.client.model.ResultMap> backtest(BacktestRequest request, BacktestOptions opts) Run the full compile → prepare → execute pipeline and resolve once the run reaches a terminal state (completed, failed, or canceled). The returned future completes exceptionally withQTSStrategyCompileErrorif compilation fails,QTSPreparationErrorif data preparation fails,QTSExecutionErrorif execution fails, orQTSTimeoutErrorif a stage exceeds its configured timeout.A
401during prepare, execute, or result polling triggers one token refresh and then restarts the entire pipeline from compile — not just the stage that failed. A401from the compile stage itself is not retried; seecompile(String, BacktestOptions).This call resolves the session's token synchronously before scheduling any async work: on a session with no cached or stored token, it blocks to mint one and throws
QTSAuthErrordirectly (not through the returned future) if that mint fails.- Parameters:
opts- tuning knobs (poll interval, timeout, progress callback) applied to every stage of the pipeline
-
exchanges
List available exchanges on the platform. Synchronous — blocks the calling thread for the HTTP round trip. Participates in the session's refresh-on-401 policy: an unauthorized response triggers one token refresh and one retry of this call.- Throws:
QTSError- on HTTP 4xx/5xx or transport failure
-
instruments
List instruments available on the given exchange, including per-data-type coverage and market info. Synchronous — blocks the calling thread for the HTTP round trip. Participates in the session's refresh-on-401 policy: an unauthorized response triggers one token refresh and one retry of this call.- Parameters:
exchangeId- exchange identifier (e.g."binance")- Throws:
QTSError- on HTTP 4xx/5xx or transport failure
-
tickers
Equivalent totickers(String, String, String, String, DownloadFormat)withDownloadFormat.LASTRA. -
tickers
public InputStream tickers(String exchangeId, String base, String quote, String hour, DownloadFormat format) Download one hour of raw tickers for an instrument as a streamingInputStream. Synchronous; the caller is responsible for closing the returned stream. Participates in the session's refresh-on-401 policy: an unauthorized response triggers one token refresh and one retry of this call.- Throws:
QTSDownloadError- on HTTP 4xx/5xx or transport failure
-
klines
Equivalent toklines(String, String, String, String, DownloadFormat)withDownloadFormat.LASTRA. -
klines
public InputStream klines(String exchangeId, String base, String quote, String hour, DownloadFormat format) Download one hour of klines for an instrument as a streamingInputStream. Seetickers(String, String, String, String, DownloadFormat)for blocking, closing, and refresh semantics.- Throws:
QTSDownloadError- on HTTP 4xx/5xx or transport failure
-
authenticate
Mint a fresh session from the given API key.If
apikeyisnullor blank, the value is read from theQTSURFER_APIKEYenvironment variable. AQTSAuthErroris raised when neither source yields a usable API key, or when the initial JWT exchange fails. -
authenticate
Equivalent toauthenticate(String, AuthOptions)withAuthOptions.defaults(). -
authenticate
Equivalent toauthenticate(String, AuthOptions)with anullapikey (resolved fromQTSURFER_APIKEY) andAuthOptions.defaults().
-