configurations
¶
Configuration read from the environment, and the shared clients built from it.
The connection helpers live beside the settings they read rather than in a module of their own: there is one source of truth for where Redis, MongoDB and TimescaleDB are, and one place that opens them.
Functions:
| Name | Description |
|---|---|
get_cache |
Redis client shared by the broker API classes and scripts. |
get_mongo_db |
MongoDB database shared by the broker API classes and scripts. |
get_logger |
Named logger. |
get_postgres |
TimescaleDB connection used by the tick persistence layer. |
get_postgres_engine |
SQLAlchemy engine over the same TimescaleDB the persisters write to. |
get_cache
¶
Redis client shared by the broker API classes and scripts.
health_check_interval makes redis-py ping a connection that has been idle for longer than
thirty seconds before handing it back, which matters for the long running scripts: one that
holds a connection across a quiet spell, overnight say, would otherwise only discover a dropped
connection on its next command.
Deliberately no socket_timeout: a blocking stream read (XREADGROUP with block) would then
raise whenever it waited longer than the timeout. Stream readers bound their waiting with the
read's own block instead.
Source code in utilities/configurations.py
get_mongo_db
¶
MongoDB database shared by the broker API classes and scripts.
get_logger
¶
Named logger.
nameis the name of the logger, for examplezerodha.websocket_quotes.
get_postgres
¶
TimescaleDB connection used by the tick persistence layer.
Source code in utilities/configurations.py
get_postgres_engine
¶
SQLAlchemy engine over the same TimescaleDB the persisters write to.
get_postgres returns a psycopg2 connection, which is what the tick, order and position
persisters want because they COPY a fixed, known column list. The instrument loader instead
writes whatever columns a broker published that day, straight off a pandas DataFrame, and
DataFrame.to_sql needs an engine. The DDL runner uses it too.