Describes github.com/stxapp/stx-go v0.3.1, the current release.
Constants and variables
Section titled “Constants and variables”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.
APIError
Section titled “APIError”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.APIErrorif errors.As(err, &apiErr) { fmt.Println(apiErr.StatusCode, apiErr.Message)}fmt.Println(errors.Is(err, stx.ErrRejected))// Output:// 422 Insufficient assets.// true422 Insufficient assets.trueAPIError.Error
Section titled “APIError.Error”func (e *APIError) Error() stringError returns “stx: METHOD PATH: STATUS: message”.
APIError.Is
Section titled “APIError.Is”func (e *APIError) Is(target error) boolIs matches the sentinel errors for this status and code.
ChannelError
Section titled “ChannelError”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”.
ChannelError.Error
Section titled “ChannelError.Error”func (e *ChannelError) Error() stringError returns “stx: EVENT on TOPIC refused: REASON”.
ChannelError.Is
Section titled “ChannelError.Is”func (e *ChannelError) Is(target error) boolIs matches ErrChannelRefused for a refusal, and ErrUnauthorized and ErrInsufficientScope for those reasons.
ComboRefusedError
Section titled “ComboRefusedError”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.
ComboRefusedError.Error
Section titled “ComboRefusedError.Error”func (e *ComboRefusedError) Error() stringError returns “stx: COMMAND on TOPIC refused: REASON”.
ComboRefusedError.Is
Section titled “ComboRefusedError.Is”func (e *ComboRefusedError) Is(target error) boolIs matches ErrComboPriceMoved, ErrNotFound for “not_found”, ErrUnauthorized for “unauthorized” and ErrInsufficientScope for “insufficient_scope”.
ForbiddenError
Section titled “ForbiddenError”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`.
HandshakeError
Section titled “HandshakeError”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.
HandshakeError.Error
Section titled “HandshakeError.Error”func (e *HandshakeError) Error() stringError returns “stx: websocket handshake refused: HTTP STATUS (REASON)”.
HandshakeError.Is
Section titled “HandshakeError.Is”func (e *HandshakeError) Is(target error) boolIs matches ErrUnauthorized on 401 and ErrForbidden on 403.
NotAvailableError
Section titled “NotAvailableError”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.
NotAvailableError.Error
Section titled “NotAvailableError.Error”func (e *NotAvailableError) Error() stringError returns a sentence such as “stx: Combos are not available on demo.stxapp.ca yet.”
NotAvailableError.Is
Section titled “NotAvailableError.Is”func (e *NotAvailableError) Is(target error) boolIs matches ErrNotAvailable.
NotAvailableError.Unwrap
Section titled “NotAvailableError.Unwrap”func (e *NotAvailableError) Unwrap() errorUnwrap returns the underlying answer, if any.
PostOnlyWouldMatchError
Section titled “PostOnlyWouldMatchError”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.
PostOnlyWouldMatchError.Error
Section titled “PostOnlyWouldMatchError.Error”func (e *PostOnlyWouldMatchError) Error() stringError describes the refusal.
PostOnlyWouldMatchError.Is
Section titled “PostOnlyWouldMatchError.Is”func (e *PostOnlyWouldMatchError) Is(target error) boolIs matches ErrPostOnlyWouldMatch and ErrRejected.
PostOnlyWouldMatchError.Unwrap
Section titled “PostOnlyWouldMatchError.Unwrap”func (e *PostOnlyWouldMatchError) Unwrap() errorUnwrap returns the 422, if any.
TransportError
Section titled “TransportError”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.
TransportError.Error
Section titled “TransportError.Error”func (e *TransportError) Error() stringError describes the failed request.
TransportError.Is
Section titled “TransportError.Is”func (e *TransportError) Is(target error) boolIs matches ErrTransport.
TransportError.Unwrap
Section titled “TransportError.Unwrap”func (e *TransportError) Unwrap() errorUnwrap returns the network error.

