sources
¶
Which broker's ticks an instrument takes, when more than one broker streams it.
The unified table and quote cache do not blend brokers. At any moment one broker owns an
instrument and only its ticks are written; another broker's ticks for the same instrument are
dropped unless the owner goes unhealthy, when the best healthy backup takes over, and the owner
takes the instrument back once it has been healthy again for a while. The ownership engine in
bin/unified/instruments/websocket_quotes applies these rules, and rank orders brokers by them wherever one has to be
picked first.
The priority order is a starting point, not a measurement. Zerodha leads because its feed runs in production and its decoding has been checked against live packets; the rest follow roughly by how much of their feed has been verified. Reorder it as live sessions compare the brokers.
A broker is used only once it is in VERIFIED_BROKERS - or, until then, only as a last resort for an instrument no verified broker streams. A broker joins the set once its normalizer's assumptions (quantity basis, close semantics, timestamps) have been checked live.
Functions:
| Name | Description |
|---|---|
priority_for |
The broker priority for an exchange. |
rank |
A broker's sort key for an exchange: verified brokers before unverified, then by priority. |
priority_for
¶
The broker priority for an exchange.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
exchange
|
str
|
Canonical exchange, for example "nse". |
required |
Returns:
| Type | Description |
|---|---|
tuple[str]
|
Broker names, highest priority first. |
Source code in stock_brokers/instruments/ticks/utilities/sources.py
rank
¶
A broker's sort key for an exchange: verified brokers before unverified, then by priority.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
broker
|
str
|
The broker name. |
required |
exchange
|
str
|
Canonical exchange. |
required |
verified
|
frozenset
|
The brokers treated as verified. |
VERIFIED_BROKERS
|
Returns:
| Type | Description |
|---|---|
tuple[int, int]
|
Lower sorts first. A broker missing from the priority list sorts last. |