Skip to Content

Errors

The error codes of the Local API, the errors the clients raise and the close codes of the stream.

Every failed request carries a stable code. Rely on the code: the message is for a human and may change. Over HTTP the error is the body of the answer: {"error": {"code": "not_found", "message": "no such operation"}}.

Error codes

CodeHTTPWhenWhat to do
unauthorized401The token is missing or wrong, or the API is offCopy the current token and check the switch
forbidden403The request comes from a browser page, or its host is not 127.0.0.1 or localhostCall from a program on the same machine
forbidden_scope403The token lacks the scope of the callCheck meta().scopes
not_found404Unknown address or connection, or no connection for the instrumentCheck the instrument and connections()
invalid_request400A bad parameter, or an instrument the catalogue does not knowFix the parameter
unsupported501MOEX, a terminal built without market data, or a setting the API cannot writeDo not retry
not_active409Clusters or leverage of the instrument are not loaded yetCall again in a few seconds. For leverage, open the instrument in the terminal
not_tradable409The connection is disabled, read-only or has no credentialsPick a trading connection
rate_limited429A limit is exceededWait a moment and call again
unavailable503The exchange or the terminal did not answer, or there is no data yetCall again later

The stream uses the same codes. New codes can be added inside v1.

Catch an error

from spectre_terminal import ApiError

try:
    book = terminal.orderbook("binance:futures:BTCUSDT", depth=20)
except ApiError as error:
    print(error.status, error.code, error.message)

The clients raise these errors.

PythonTypeScriptWhen
ApiErrorApiErrorThe terminal answered with a code from the table above
TokenMissingTokenMissingErrorNo token was passed or set in SPECTRE_LOCAL_API_TOKEN
LocalApiDisabledLocalApiDisabledErrorThe Local API is switched off
TerminalUnreachableTerminalUnreachableErrorThe terminal is not running or listens on another port
IncompatibleTerminalIncompatibleTerminalErrorThe client does not support the API version of the terminal
StreamRequestErrorStreamRequestErrorA subscribe or unsubscribe was refused
StreamClosedStreamClosedErrorThe terminal closed the stream

All of them extend SpectreTerminalError. The token never appears in an error text.

Stream close codes

CodeWhyWhat to do
1001The API was switched off or the token was reissuedReconnect with the current token
1006The connection was lostReconnect
4008Your program did not read for more than 5 secondsRead faster or subscribe to less
4029The token already has 8 stream connectionsReuse a connection

To reconnect in code, see Reconnect.

On this page