brokapi.models
The data that brokapi returns and takes: instruments, order books, orders, events.
Every type is a frozen dataclass, so == and hash work and match can take it apart. Prices, quantities and
money are decimal.Decimal, never float. Moments are timezone-aware datetime in UTC with microsecond
precision. The exact nanoseconds are on Timestamps.
The fields have the names of the Rust types in brokapi_core, so the book and the Rust reference describe them
both.
What a subscription does when the reader is slow. Build it with the class methods.
Keep up to cap events and drop the newest beyond that (and count them).
Money of one currency.
The balances of the account changed.
One price level of an order book.
What a connection can do (client.caps).
One bar.
One event with its address.
What an Envelope carries.
A fill of one of your orders.
Events were lost between the gateway and this client: the gateway no longer has what came after the last event the
client was given. Only a client made by ~brokapi.connect_gateway() gets it (source is <gateway>-gateway).
It is the gateway's counterpart of Overflow and Reconnected, and the rule is the same: read the state
from the broker (active_orders, order_state, executions) and call reconcile. Trading is closed
(~brokapi.Degraded) until you have. The stream goes on from the present moment, nothing needs to be reopened.
reason is "too_old" (the gateway keeps a limited number of recent events and the client was away longer),
"new_epoch" (the gateway was restarted: it is a new process, and the numbers of events begin again) or "ahead"
(the client's number is ahead of the gateway's, which does not happen unless the gateway's data was replaced).
requested_after is the number the client asked to continue from, first_available the oldest event the
gateway still has.
A directory entry.
An instrument: the common key and the broker's own id.
The same for every broker: a symbol on a venue.
Kind of an instrument.
What to look for in the directory of the broker. Build it with the class methods.
What the market data side can do.
A deal on the exchange tape.
How the broker itself names an instrument. Opaque: take it from client.instrument and pass it back.
The broker accepted an order.
A book message: OrderBookSnapshot or OrderBookIncrement.
A change to apply to the book. A level with a zero qty is removed. seq grows by one.
The whole book (the levels asked for). Replaces what you had.
An order as the broker has it. Also the event for a change of an order.
Where an order is. The fields that do not apply to kind are None.
Where an order is in its life. See the orders page of the book for the diagram.
The outcome is not known. Ask the broker with order_state(cid).
Limit order (needs a price) or market order.
The connector lost events of a lossless subscription since lost_from.
Trading is closed (~brokapi.Degraded) until you read the stream to the end and call reconcile.
The stream of your orders or of your fills was cut and opened again: events of the gap never reached you.
sub is the subscription whose stream was cut (one event for the order state subscription and one for the
executions subscription). gap_from is when the connector noticed the cut: the hole starts at or before it.
Trading is closed (~brokapi.Degraded) until you read the stream to the end, read the state from the broker
(active_orders, order_state, executions from a little before gap_from) and call reconcile.
What the broker does with a second place that has the same cid.
Money and holdings of the account.
A holding.
The positions of the account changed.
Best bid and best ask.
What reconcile found.
The order book of this instrument must be taken again (take a snapshot, then follow increments).
Why an order book must be taken again.
Trading sessions of an exchange.
One trading session.
Kind of a trading session.
What a stop of one connector did.
Buy or sell.
How long a stop order lives. Build it with the class methods.
What a stop order is for. With the side it fixes the direction of the trigger.
Protects a position: a sell triggers when the price falls to stop_price, a buy when it rises.
Takes a profit: a sell triggers when the price rises to stop_price, a buy when it falls.
Triggers like STOP_LOSS and always puts a limit order, so limit_price is required.
The id of the broker, from OrderAck.broker_id or StopOrderSnapshot.broker_id.
A stop order as the broker shows it (active_stop_orders).
Where a stop order is: kind, and the broker's own text when it is OTHER.
Where a stop order is in its life.
Cancelled before it triggered, by you or by the broker.
The status of the broker does not fit the others: its text is on StopOrderState.text.
Which market data streams the broker has.
Candle length.
When something happened, in nanoseconds since the Unix epoch (exact).
Whether an instrument trades right now.
What an order must respect: the step of the price, the smallest quantity, the lot.
Whether an instrument trades now.
An event of a kind this version of the Python package does not know (the core is newer than the package).
The stream does not break on it: kind is the name the core gave it and data its content as it came
(JSON values, money as text). Update the package to get a typed class. An event of a kind you do not know may be
about the loss of data (the way Overflow and Reconnected are): when in doubt, reconcile before
trading further.
What the account side can do.