orchestrator
¶
Runs the mapping pass across every broker, in the one order that produces correct answers.
The order is not alphabetical and not configurable. Several adapters resolve their index names
against the nse_equity_indices rows already written for the same date, so the brokers publishing
a clean index vocabulary have to go first. That order is MAPPED_BROKERS in segments.py, which
is imported here rather than restated, because two lists that must agree eventually will not.
Each broker is mapped in its own try/except, so one broker's rules file being wrong does not cost the others their mapping for the day. This matters less than it does for the download stage - the mapping reads stored rows and can be re-run over any date, whereas a missed download is missed forever - but a partial answer is still worth more than none.
A run covering every broker ends by merging away stale duplicate instruments, where a broker publishes two rows for one scrip and the others agree on which is live. A run for a subset skips that step, since a broker cannot vote on itself.
Functions:
| Name | Description |
|---|---|
adapter_for |
The mapping adapter class for a broker. |
has_raw_rows |
Whether a broker stored any raw instrument rows for a date. |
report_row_errors |
Print the distinct row errors an adapter collected, rather than only how many there were. |
map_one |
Map one broker's stored raw rows for one date, catching any failure rather than raising. |
map_all |
Map one date, for one broker, several, or every broker in the fixed processing order. |
adapter_for
¶
The mapping adapter class for a broker.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
broker_name
|
str
|
The name of the broker. |
required |
Returns:
| Type | Description |
|---|---|
type
|
The adapter class, not an instance. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If no adapter is registered for that broker. |
Source code in stock_brokers/instruments/mapping/utilities/orchestrator.py
has_raw_rows
¶
Whether a broker stored any raw instrument rows for a date.
Asked before mapping, so that a broker whose download failed is reported as absent from the day rather than mapped to nothing.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
engine
|
Engine
|
A SQLAlchemy engine over TimescaleDB. |
required |
broker_name
|
str
|
The name of the broker. |
required |
mapping_date
|
date
|
The snapshot date to look for. |
required |
Returns:
| Type | Description |
|---|---|
bool
|
True when at least one row is stored. |
Source code in stock_brokers/instruments/mapping/utilities/orchestrator.py
report_row_errors
¶
Print the distinct row errors an adapter collected, rather than only how many there were.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
broker_name
|
str
|
The name of the broker that produced them. |
required |
errors
|
list
|
The (segment, message) pairs from the adapter's summary. |
required |
limit
|
int
|
The most distinct pairs to print before summarising the rest. |
10
|
Returns:
| Type | Description |
|---|---|
None
|
This function returns nothing. |
Source code in stock_brokers/instruments/mapping/utilities/orchestrator.py
map_one
¶
Map one broker's stored raw rows for one date, catching any failure rather than raising.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
broker_name
|
str
|
The name of the broker to map. |
required |
mapping_date
|
date
|
The snapshot date to map. |
required |
Returns:
| Type | Description |
|---|---|
dict
|
Keys "broker", "matched", "uncategorised", "instruments", "row_errors" and "error", where "error" is None on success. "row_errors" counts rows the adapter could not build an identity for; see below for why that is not the same thing as a failure. |
Source code in stock_brokers/instruments/mapping/utilities/orchestrator.py
map_all
¶
Map one date, for one broker, several, or every broker in the fixed processing order.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
mapping_date
|
date
|
The snapshot date to map. |
required |
brokers
|
list[str] | None
|
The brokers to map. None maps every broker. |
None
|
skip_collisions
|
bool
|
When True, do not run the duplicate merge afterwards. |
False
|
Returns:
| Type | Description |
|---|---|
list[dict]
|
One result dictionary per broker attempted, in processing order. |