def start(): cfg4py.init(get_config_dir()) myapp = Application() app.register_listener(myapp.init, 'before_server_start') app.run(host='0.0.0.0', port=cfg.alpha.server.port, workers=cfg.alpha.server.workers)
async def setUp(self) -> None: os.environ[cfg4py.envar] = 'DEV' config_dir = get_config_dir() cfg4py.init(config_dir, False) await omicron.init() await emit.start(emit.Engine.REDIS, dsn=cfg.redis.dsn)
async def setUp(self) -> None: os.environ[cfg4py.envar] = 'DEV' config_dir = get_config_dir() cfg4py.init(config_dir) await omicron.init()
def init(): server_roles = ['PRODUCTION', 'TEST', 'DEV'] if os.environ.get(cfg4py.envar) not in ['PRODUCTION', 'TEST', 'DEV']: print(f"请设置环境变量{colored(cfg4py.envar, 'red')}为[" f"{colored(server_roles, 'red')}]之一。") sys.exit(-1) config_dir = get_config_dir() cfg4py.init(config_dir, False)
async def init(self, model_file: Optional[str] = None): os.environ[cfg4py.envar] = 'DEV' self.config_dir = get_config_dir() cfg4py.init(self.config_dir, False) await emit.start(engine=emit.Engine.REDIS, dsn=cfg.redis.dsn, start_server=True) await omicron.init() if model_file is not None: with open(model_file, "rb") as f: self.model = load(f)
async def test_screen(self): import cfg4py import os from alpha.config import get_config_dir os.environ[cfg4py.envar] = 'PRODUCTION' cfg4py.init(get_config_dir()) await omicron.init() code = '300023.XSHE' sec = Security(code) stop = arrow.now().datetime start = tf.day_shift(stop, -3) bars = await sec.load_bars(start, stop, FrameType.DAY) print(bars) if np.all(bars['close'] > bars['open']): print(sec.display_name, "\t", 100 * (bars[-1]['close'] / bars[-2]['close'] - 1))
from omicron.core.timeframe import tf from omicron.core.types import FrameType from omicron.dal import cache from omicron.models.security import Security from pandas import DataFrame from pyemit import emit from termcolor import colored from alpha.config import get_config_dir from alpha.notify.itek import ItekClient from alpha.plots import create_plot logger = logging.getLogger(__name__) cfg = cfg4py.get_instance() cfg4py.init(get_config_dir()) event_loop = asyncio.get_running_loop() sched = AsyncIOScheduler(timezone=cfg.tz, loop=event_loop) sched.start() # global variables queued_sound = 0 fired_signals = {} async def dec_queued_sound(): global queued_sound queued_sound -= 1 clear_output(wait=True)