brokapi.errors
Errors of brokapi.
The names and the meaning are those of Error in the Rust library (brokapi_core::Error): one class per
variant, and str(error) is the text that Rust prints for the same error. The errors page of the book says what
each one means and what to do. error_class answers the one question that matters most: may the call be tried
again (RETRYABLE), will it fail again until something changes (FATAL), or is the outcome of a command not
known (UNKNOWN).
The one that needs care is Unknown. A command (place, cancel, replace) was sent and nothing
says whether the broker did it. Never send it again. Ask the broker with order_state(cid) first.
>>> from brokapi import errors
>>> str(errors.NotReconciled())
'not reconciled: call reconcile() before trading commands'
>>> errors.Unknown().error_class is errors.ErrorClass.UNKNOWN
True
Base class of every error that brokapi raises about a broker or a command.
May the call be tried again: see ErrorClass.
The setup is wrong: a missing token, a bad value, an input that cannot work with this broker.
Nothing was sent. The call fails the same way until the setting is fixed.
The trading gate is closed because the connector lost events it could not afford to lose.
A lossless subscription overflowed (an ~brokapi.Overflow event was sent). Read the event stream to the
end, then call reconcile(): a successful one opens the gate again. Nothing was sent.
The coarse answer to "may I try this call again" (Error::class in Rust).
The call failed for a reason that can pass: the network, a rate limit.
The same call fails again until something else changes: a setup, a refused request, a closed gate.
The outcome of a command is not known. Repeating it could create a second order.
The event log could not be written or read (LogError of the Rust library).
kind says why: io (the file or the disk failed: check the path and the space), format (a line is not
what the format says, the file is damaged or is not a log: line is its number, the header is line 1) or
schema (the file was written by a newer version: update the package to read it). A reader never skips a bad
line silently: it stops with this error.
The trading gate is closed: reconcile() has not run successfully yet.
Call reconcile with your ledger (an empty list if you have none), then repeat the command. Nothing was sent.
A rate limit stopped the call: the local counter of the connector or the broker's own answer.
Wait retry_after, then repeat. A command refused by the local counter was not sent. The library does not
wait and repeat for you.
The broker (or the connector, before sending) said no to this request, and nothing was done.
The request is wrong or not allowed: a price outside the band, no money, an unknown order. Change the request.
Do not repeat it as it is. code is a short label set by the connector (validation, missing_price,
not_found, price_off_step, ...), safe to compare with ==. Do not parse message.
The connector is shutting down and takes no new trading commands.
Final for this client. Orders already at the exchange are not touched by a shutdown. Connect again to trade.
The network or the broker's endpoint failed in a way that is not an answer (connect, TLS, timeout, a cut stream).
For a reading call, repeat it later. A command that might have reached the broker raises Unknown
instead, so this error on a command means the connector has no sign that it did.
A command was sent and nothing says whether the broker did it: a timeout, a cut connection, an HTTP 5xx.
The order may exist, may be cancelled, or may never have arrived. The library never repeats the command and neither should you:
- Do not send the command again.
- Ask the broker:
order_state(cid),active_orders()or the executions. - Only when the broker has no such order, place a new one under a NEW
cid.
This connector or this broker does not have the capability, so the call was not made.
Raised at once, without a network call. capability is a short name of what is missing. The library does not
emulate a missing stream by polling. client.caps says in advance what a connector can do.