Skip to main content
Trading calls report failure through two channels. Handle both. HTTP status, action status and error cause are three separate axes: see Execution reports.

Thrown errors

Use PerpsErrorCode for type-safe handling:

Terms must be accepted first

Every non-meta createAction and executeAction call fails with HTTP 401 and code 2012 (TermsNotAccepted) until the address has accepted the current terms version. That covers checkSetup (once the venue account exists), every setup step, trading and withdrawals. A terms-version bump gates the address again, including actions staged earlier. Check and accept before any provider action:

Step results inside a successful response

A venue refusal (insufficient margin, invalid parameters, market closed) and an unclear venue answer both come back inside a 202 response. placeOrder, placeTriggerOrder, placeTwapOrder, cancelOrders, modifyOrders, cancelTwapOrder, updatePositionMargin, sendAsset, withdraw, execute, executeProviderSetupAction, executeProviderOption, executeProviderRevoke and the meta methods resolve with { results } and do not throw on it. 202 does not mean that the venue accepted a step. Read the status of every result: The report holds only the steps that the backend attempted. It stops at the first Failed or Indeterminate step. Earlier acknowledgements stay in the report. Every member of an attempted atomic batch has a result, and two steps with the same action keep two results. This example handles every result:
ActionResult is one flat type. error is set unless the status is Submitted or Accepted, and errorCode is set when the cause is classified. orderId, twapId, txHash and explorerLink are set when the venue and the provider give them.

Returned result or thrown error

  • A returned Failed result is a confirmed refusal of one step, with the steps before it kept in the report. A Failed result after verification can also come from a step that the backend first reported as Submitted or Indeterminate. The response that you hold does not show that change.
  • A thrown PerpsError is a request, signing or transport failure with no report from the backend. Nothing in your hands says what the venue did.
  • A thrown PerpsExecutionError means that a later stage failed after some results were known. Its response.results holds every known result, and cause holds the original error. Read the results before you handle the error.
Not every SDK execution throws the first failed step. The execution methods above return the report and leave the decision to you. A failed result in the report is an input to your code, not an exception.

SDK-originated messages

PerpsErrorMessage pairs canonical human-readable text with PerpsErrors the SDK itself raises (not the backend’s error responses): AgentNotFound (agent-signing setup incomplete) and AgentStorageCorrupt (a stored agent keypair is malformed and the agent must be revoked and re-approved). Both are thrown as PerpsErrorCode.SDKError (2005), so compare error.message.

Common Trading Errors

See Error Codes for the complete reference, including how errorCodeFromStatus resolves a code from an HTTP status.