Socketrade

Error catalogue

Know which failures are final.

The status code tells you what kind of problem you have. The code field in the body tells you the specific case when a status covers more than one. Most failures here are about the key, the plan or the account, and sending the same request again will not change the answer.

The catalogue

StatusCodeMeansWhat to do
401 The key is missing, or it is not a key we know.Send your key in the X-API-Key header and check that it starts with a2t_. Stop: nothing about the request will work until the key is right.
402names which kindEvery seat of that kind is already in use.Add seats, or remove an account to free one. The body names the kind of seat that ran out, so you know which one to buy. Stop: not retryable.
403SUBSCRIPTION_INACTIVEThe subscription is inactive or has expired. The body also carries status, which reads past_due or canceled.Send the customer to billing. Stop: not retryable.
403READ_ONLYThe account is on a monitor seat, which may read but not trade.Use a trade or an execution seat for this account, or drop the order call. Stop: not retryable.
404 No account with that id, or it does not belong to this key.Check the account id you stored when the account was added. Stop: not retryable.
409 That account has already been added.Use the account id you already have. Stop: not retryable.
503WINDOW_CLOSEDA close or modify arrived between execution windows.Wait retryAfterSeconds, then send the same request again. Retryable.
503 The account is not ready to serve that call yet.Retry with a short backoff. This clears without you changing anything.

The two codes you will branch on

Most statuses need no parsing. These two carry a named code, because the client has to behave differently for each.

403 Forbidden
{ "code": "READ_ONLY" }

503 Service Unavailable
{ "code": "WINDOW_CLOSED", "retryAfterSeconds": 42 }

What to retry

401, 402, 403, 404, 409

Not retryable. Something has to change first: the key, the seats, the subscription or the account id.

503 WINDOW_CLOSED

Retryable. Wait retryAfterSeconds and send the same close or modify again.

503 not ready

Retryable. Back off for a few seconds and try again. Nothing is wrong with your request.

In short: 402 and 403 are not retryable, they need a change on the account or the plan. 503 with WINDOW_CLOSED is, once the wait in retryAfterSeconds has passed. A retry loop that ignores this only repeats an answer that cannot change.

Reading a failure

Log the status, the code and the account id together. That triple is usually enough to tell a wrong key from a seat that ran out from an account that was never added, and it is what support will ask for first. Never log the key itself.

Related