tradingSystem/app/observation_worker.py

39 lines
1.5 KiB
Python
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

"""ETF观测单进程入口,不启动交易worker或QMT连接。"""
import logging
import signal
from threading import Event
def main():
from app.services.etf_observation import consume_once
from app.services.broad_funds import consume_once as consume_daily
from app.services.etf_query import consume_once as consume_query
logging.basicConfig(level=logging.INFO)
stopping = Event()
signal.signal(signal.SIGTERM, lambda *_: stopping.set())
signal.signal(signal.SIGINT, lambda *_: stopping.set())
while not stopping.is_set():
try:
result = consume_once()
if result.get('status') == 'unavailable':
logging.warning('ETF观测暂不可用:%s', result.get('error'))
except Exception as exc:
logging.warning('ETF观测保存失败:%s', type(exc).__name__)
try:
result = consume_daily()
if result.get('status') == 'unavailable':
logging.warning('每日资金暂不可用:%s', result.get('error'))
except Exception as exc:
logging.warning('每日资金保存失败:%s', type(exc).__name__)
try:
result = consume_query()
if result.get('status') == 'unavailable':
logging.warning('宽基分时暂不可用:%s', result.get('error'))
except Exception as exc:
logging.warning('宽基分时保存失败:%s', type(exc).__name__)
stopping.wait(15)
if __name__ == '__main__':
main()