Skip to content

Errors

Describes github.com/stxapp/stx-go v0.3.1, the current release.

var (
// ErrConfig: the client is misconfigured (unknown environment, missing key,
// bad PEM, unreadable credentials file).
ErrConfig = errors.New("stx: configuration error")
// ErrBadRequest: 400, a parameter or body field was refused.
ErrBadRequest = errors.New("stx: bad request")
// ErrUnauthorized: 401, the signature, key id or timestamp was not
// accepted. A machine clock more than 30 seconds off also lands here.
ErrUnauthorized = errors.New("stx: unauthorized")
// ErrInvalidToken: 401 on an OAuth bearer request whose access token is
// missing, expired or revoked. Also matches ErrUnauthorized.
ErrInvalidToken = errors.New("stx: invalid token")
// ErrForbidden: 403, the key is read-only or the account may not do this.
ErrForbidden = errors.New("stx: forbidden")
// ErrInsufficientScope: 403 on an OAuth bearer request whose grant lacks a
// scope; see APIError.RequiredScopes. Also matches ErrForbidden.
ErrInsufficientScope = errors.New("stx: insufficient scope")
// ErrTermsRequired: 403, the member has not accepted the current terms;
// see APIError.TermsURL. Also matches ErrForbidden.
ErrTermsRequired = errors.New("stx: terms not accepted")
// ErrIPNotAllowed: 403, the write came from an address the app's IP
// allow-list lacks. Also matches ErrForbidden.
ErrIPNotAllowed = errors.New("stx: ip address not allowed")
// ErrNotFound: 404, the resource does not exist or belongs to another
// account.
ErrNotFound = errors.New("stx: not found")
// ErrRejected: 422, the exchange refused the request, for example
// insufficient funds or a closed market.
ErrRejected = errors.New("stx: rejected")
// ErrRateLimited: 429, too many requests; see APIError.RetryAfter.
ErrRateLimited = errors.New("stx: rate limited")
// ErrServer: 5xx, the server failed.
ErrServer = errors.New("stx: server error")
// ErrTransport: the request got no answer (connection, DNS, TLS or
// timeout). The error also wraps the underlying network error.
ErrTransport = errors.New("stx: transport error")
// ErrBlocked: 403 from the edge firewall in front of the API, before the
// request reached the exchange; see APIError.Code and
// APIError.Reference. Never retried. Also matches ErrForbidden.
ErrBlocked = errors.New("stx: blocked")
// ErrRestrictedJurisdiction: blocked because the request came from a
// location the exchange does not serve. Also matches ErrBlocked.
ErrRestrictedJurisdiction = errors.New("stx: restricted jurisdiction")
// ErrUnusualNetwork: blocked because the request came through a network
// the exchange does not accept traffic from, such as an anonymizing
// proxy. Also matches ErrBlocked.
ErrUnusualNetwork = errors.New("stx: unusual network")
// ErrFillModeNotAllowed: 422, the market does not take the order's fill
// mode. Combination markets take neither post_only nor fill_or_kill.
// Also matches ErrRejected.
ErrFillModeNotAllowed = errors.New("stx: fill mode not allowed on this market")
// ErrPostOnlyWouldMatch: a post-only order would have matched on arrival,
// so the exchange did not rest it; see *PostOnlyWouldMatchError.
ErrPostOnlyWouldMatch = errors.New("stx: post-only order would match")
// ErrNotAvailable: this exchange does not have the feature yet, for
// example combos where they are not switched on. Nothing is wrong with the
// request or the credentials; see *NotAvailableError for the feature.
ErrNotAvailable = errors.New("stx: not available")
)

Sentinel errors. Match them with errors.Is; an *APIError matches the sentinel for its status, and the more specific ones listed below.

var (
// ErrStreamClosed: the stream was closed, or gave up reconnecting.
ErrStreamClosed = errors.New("stx: stream closed")
// ErrAlreadySubscribed: the stream already holds a subscription to this
// topic. Close it first, or read from the one you have.
ErrAlreadySubscribed = errors.New("stx: already subscribed")
// ErrNotJoined: a channel command was sent while the topic is not joined,
// for example during a reconnect.
ErrNotJoined = errors.New("stx: channel not joined")
// ErrChannelRefused: the exchange refused a join or a channel command;
// see *ChannelError for its reason.
ErrChannelRefused = errors.New("stx: channel refused")
// ErrTimeout: no reply to a join or a channel command in time. The error
// also matches context.DeadlineExceeded.
ErrTimeout = errors.New("stx: no reply in time")
)

Sentinel errors for streams.

var ErrComboPriceMoved = errors.New("stx: combo price moved")

ErrComboPriceMoved: an accept found nothing live at least as good as the amount; the request stays open. See ComboRefusedError.Best for the live quote.

type APIError struct {
// StatusCode is the HTTP status, for example 422.
StatusCode int
// Code is the machine-readable error code when the API sends one, such as
// "terms_required" or "not_found"; otherwise empty.
Code string
// Message is the API's human-readable message, kept verbatim.
Message string
// RequestID is the X-Request-Id response header, when present. Quote it
// when you contact support.
RequestID string
// Method and Path are the request that failed; Path includes the query.
Method string
Path string
// Body is the raw response body.
Body []byte
// RetryAfter is the server's Retry-After on a 429, or zero.
RetryAfter time.Duration
// RequiredScopes names the OAuth scopes that would satisfy a 403
// insufficient-scope answer.
RequiredScopes []string
// TermsURL is the page where the member accepts the terms, on a
// terms-required answer.
TermsURL string
// Reference identifies a block by the edge firewall in front of the API
// (a 403 matching ErrBlocked, or a 429 with Code "rate_limited"): the
// request's CloudFront id, from the x-amz-cf-id response header. Quote it
// when you contact support.
Reference string
// contains filtered or unexported fields
}

APIError is an error status answered by the API.

Example

Matching API errors.

err := error(&stx.APIError{StatusCode: 422, Message: "Insufficient assets.", Method: "POST", Path: "/api/v1/orders"})
var apiErr *stx.APIError
if errors.As(err, &apiErr) {
fmt.Println(apiErr.StatusCode, apiErr.Message)
}
fmt.Println(errors.Is(err, stx.ErrRejected))
// Output:
// 422 Insufficient assets.
// true
422 Insufficient assets.
true
func (e *APIError) Error() string

Error returns “stx: METHOD PATH: STATUS: message”.

func (e *APIError) Is(target error) bool

Is matches the sentinel errors for this status and code.

type ChannelError struct {
// Topic is the wire topic, for example "orders:7fb55544-3a7e-4f6b-bd66-fc89bd3a1087".
Topic string
// Event is what was sent: "phx_join", "select_market_ids", ...
Event string
// Reason is the reply's "reason", or the server event ("phx_close",
// "phx_error") that ended a join before it was answered.
Reason string
// Reply is the reply's raw "response" object.
Reply json.RawMessage
// contains filtered or unexported fields
}

ChannelError is the exchange refusing a join or a channel command, with the reason it gave, such as “market_ids_required” or “unauthorized”.

func (e *ChannelError) Error() string

Error returns “stx: EVENT on TOPIC refused: REASON”.

func (e *ChannelError) Is(target error) bool

Is matches ErrChannelRefused for a refusal, and ErrUnauthorized and ErrInsufficientScope for those reasons.

type ComboRefusedError struct {
// Command is what was sent: "request_quote", "accept", "phx_join", ...
Command string
// Topic is the wire topic.
Topic string
// Code is the refusal reason, such as "not_found" or "price_moved". A
// "player_refused:<detail>" reason has Code "player_refused" and the rest
// in Detail.
Code string
Detail string
// Reason is the reason exactly as sent.
Reason string
// Reply is the raw reply.
Reply json.RawMessage
// Best is the live best quote on "price_moved", or nil.
Best *ComboBestQuote
}

ComboRefusedError is a combo command or join the exchange refused.

func (e *ComboRefusedError) Error() string

Error returns “stx: COMMAND on TOPIC refused: REASON”.

func (e *ComboRefusedError) Is(target error) bool

Is matches ErrComboPriceMoved, ErrNotFound for “not_found”, ErrUnauthorized for “unauthorized” and ErrInsufficientScope for “insufficient_scope”.

type ForbiddenError struct {
// Failure reason: `terms_required` or `terms_not_delegable` for a terms
// refusal, otherwise a human-readable message.
Error string `json:"error,omitempty"`
// Present on a terms refusal: what the app should do, in plain words.
ErrorDescription string `json:"error_description,omitempty"`
// Present on a terms refusal: the STX page where the member accepts the terms,
// e.g. `<STX host>/connect/terms?client_id=<client_id>`.
TermsURL string `json:"terms_url,omitempty"`
}

ForbiddenError: The 403 failure envelope. A refusal on the member’s STX terms adds `error_description` and `terms_url` to `error`.

type HandshakeError struct {
// StatusCode is the HTTP status, for example 403.
StatusCode int
// Reason is the exchange's x-stx-error header, such as
// "5300 - OAuth token auth failed", when it sent one.
Reason string
}

HandshakeError is a WebSocket handshake the exchange refused with an HTTP status, for example 403 for a bad signature or a missing User-Agent.

func (e *HandshakeError) Error() string

Error returns “stx: websocket handshake refused: HTTP STATUS (REASON)”.

func (e *HandshakeError) Is(target error) bool

Is matches ErrUnauthorized on 401 and ErrForbidden on 403.

type NotAvailableError struct {
// Feature is a stable id: "combos", "markets.create", "market_types",
// "event_players", "leaderboard", "oauth", "oauth.member", "oauth.app",
// "connect", "terms.stx_page", "loyalty", "orders.post_only",
// "orders.fill_or_kill", or "scope:<name>".
Feature string
// Host is the exchange that lacks it, for example "demo.stxapp.ca".
Host string
// Err is the answer the decision came from, when there was one.
Err error
}

NotAvailableError reports a feature this exchange does not have yet. It matches ErrNotAvailable.

func (e *NotAvailableError) Error() string

Error returns a sentence such as “stx: Combos are not available on demo.stxapp.ca yet.”

func (e *NotAvailableError) Is(target error) bool

Is matches ErrNotAvailable.

func (e *NotAvailableError) Unwrap() error

Unwrap returns the underlying answer, if any.

type PostOnlyWouldMatchError struct {
// Reason is "auto_matching" when it would have matched another member's
// order: the exchange cancelled it and Order is the cancelled order. It is
// "match_with_self" when the first order it would have matched is your
// own: the exchange rejected it (a 422) and Order is nil.
Reason string
// Order is the cancelled order, for "auto_matching".
Order *Order
// Err is the 422, for "match_with_self".
Err error
}

PostOnlyWouldMatchError reports a PostOnly order that would have matched on arrival, so the exchange did not rest it. Nothing traded and the book is unchanged; re-price and place again. It matches ErrPostOnlyWouldMatch and ErrRejected.

func (e *PostOnlyWouldMatchError) Error() string

Error describes the refusal.

func (e *PostOnlyWouldMatchError) Is(target error) bool

Is matches ErrPostOnlyWouldMatch and ErrRejected.

func (e *PostOnlyWouldMatchError) Unwrap() error

Unwrap returns the 422, if any.

type TransportError struct {
Method string
Path string
Err error
}

TransportError is a request that got no answer. It matches ErrTransport and unwraps to the network error.

func (e *TransportError) Error() string

Error describes the failed request.

func (e *TransportError) Is(target error) bool

Is matches ErrTransport.

func (e *TransportError) Unwrap() error

Unwrap returns the network error.

STX is operated by XV Exchange, LLC, a Designated Contract Market regulated by the U.S. Commodity Futures Trading Commission (CFTC). Contracts traded on STX are cleared by XV Clearing, LLC, a CFTC-registered Derivatives Clearing Organization. Trading involves substantial risk of loss and may not be appropriate for everyone. Members risk losing the cost to enter any transaction, including fees. Consider whether trading is appropriate for you in light of your experience and financial resources. Nothing on this site is investment advice or a recommendation to trade. Past performance is not indicative of future results.

© 2026 STX. All rights reserved.llms.txtllms-full.txtView as Markdown
Docs version v1.10.5