omicron
Omicron提供数据持久化、时间(日历、triggers)、行情数据model、基础运算和基础量化因子
init(fetcher=None)
async
初始化omicron
Parameters:
Name | Type | Description | Default |
---|---|---|---|
fetcher |
AbstractQuotesFetcher |
如果不为None,则Omicron会使用这个fetcher |
None |
Source code in omicron/__init__.py
async def init(fetcher=None):
"""初始化omicron
Args:
fetcher (AbstractQuotesFetcher): 如果不为None,则Omicron会使用这个fetcher
来获取行情数据,否则使用远程接口。适用于在`omega`中调用`omicron.init`的情况
Returns:
"""
# to avoid circular import
from .models.securities import Securities
global _local_fetcher, cache
_local_fetcher = fetcher
await cache.init()
secs = Securities()
await secs.load()
await tf.update_calendar()
cfg = cfg4py.get_instance()
if cfg.postgres.enabled:
await init_db(cfg.postgres.dsn)
shutdown()
async
关闭与数据库、缓存的连接
Source code in omicron/__init__.py
async def shutdown():
"""关闭与数据库、缓存的连接"""
try:
await db.pop_bind().close()
except gino.exceptions.UninitializedError:
pass
try:
await cache.close()
except Exception as e: # noqa
pass