Exemplo n.º 1
0
def strategy(ctx, group, name, path, low_latency, replay, session_id,
             backtest):
    pass_ctx_from_parent(ctx)
    ctx.group = group
    ctx.name = name
    ctx.path = path
    ctx.low_latency = low_latency if not replay else True
    ctx.md_path = None

    assert not (replay and backtest
                ), "Replay mode and BackTest mode cannot be selected together"
    ctx.replay = replay
    ctx.backtest = backtest
    mode = pyyjj.mode.REPLAY if ctx.replay else pyyjj.mode.BACKTEST if ctx.backtest else pyyjj.mode.LIVE
    ctx.logger = create_logger(
        name, ctx.log_level,
        pyyjj.location(mode, pyyjj.category.STRATEGY, group, name,
                       ctx.locator))

    ctx.strategy = Strategy(ctx)  # keep strategy alive for pybind11
    runner = Runner(ctx, mode)
    runner.add_strategy(ctx.strategy)
    ctx.category = 'strategy'

    if replay:
        ctx.session_id = session_id
        replay_setup.setup(ctx, session_id, strategy, runner)
    if backtest:
        #ctx.md_path = os.path.join(ctx.home, 'md', group, name, 'journal', 'backtest', '00000000.*.journal')
        ctx.category = 'md'
        ctx.mode = pyyjj.get_mode_name(mode)
        ctx.session_id = session_id
        backtest_setup.setup(ctx, session_id, strategy, runner)

    runner.run()
Exemplo n.º 2
0
 def layout_dir(self, location, layout):
     mode = pyyjj.get_mode_name(location.mode)
     category = pyyjj.get_category_name(location.category)
     p = os.path.join(self._home, category, location.group, location.name, pyyjj.get_layout_name(layout), mode)
     if not os.path.exists(p):
         os.makedirs(p)
     return p
Exemplo n.º 3
0
def strategy(ctx, group, name, path, low_latency, replay, session_id):
    pass_ctx_from_parent(ctx)
    ctx.group = group
    ctx.name = name
    ctx.path = path
    ctx.low_latency = low_latency if not replay else True
    ctx.replay = replay
    ctx.category = 'strategy'
    mode = pyyjj.mode.REPLAY if ctx.replay else pyyjj.mode.LIVE
    ctx.mode = pyyjj.get_mode_name(mode)
    ctx.location = pyyjj.location(mode, pyyjj.category.STRATEGY, group, name,
                                  ctx.locator)
    ctx.logger = create_logger(name, ctx.log_level, ctx.location)

    if path.endswith('.py'):
        ctx.strategy = Strategy(ctx)  # keep strategy alive for pybind11
    else:
        spec = util.spec_from_file_location(
            os.path.basename(path).split('.')[0], path)
        cpp = util.module_from_spec(spec)
        spec.loader.exec_module(cpp)
        ctx.strategy = cpp.Strategy(ctx.location)

    runner = Runner(ctx, mode)
    runner.add_strategy(ctx.strategy)

    if replay:
        ctx.session_id = session_id
        replay_setup.setup(ctx, session_id, strategy, runner)

    runner.run()
Exemplo n.º 4
0
 def layout_dir(self, location, layout):
     mode = pyyjj.get_mode_name(location.mode)
     category = pyyjj.get_category_name(location.category)
     p = os.path.join(self._home, category, location.group, location.name,
                      pyyjj.get_layout_name(layout), mode)
     try:
         os.makedirs(p)
     except OSError as e:
         if e.errno != errno.EEXIST:
             raise
     return p
Exemplo n.º 5
0
 def add_location(self, location):
     with session_scope(self.session_factory) as session:
         if not session.query(Location).get(location.uid):
             info = {
                 "uid": location.uid,
                 "uname": location.uname,
                 "mode": pyyjj.get_mode_name(location.mode),
                 "category": pyyjj.get_category_name(location.category),
                 "group": location.group,
                 "name": location.name
             }
             loc_obj = Location(uid=location.uid, info=info)
             session.add(loc_obj)
Exemplo n.º 6
0
def strategy(ctx, group, name, path, low_latency, replay, session_id):
    pass_ctx_from_parent(ctx)
    ctx.group = group
    ctx.name = name
    ctx.path = path
    ctx.low_latency = low_latency if not replay else True
    ctx.replay = replay
    ctx.category = 'strategy'
    mode = pyyjj.mode.REPLAY if ctx.replay else pyyjj.mode.LIVE
    ctx.mode = pyyjj.get_mode_name(mode)
    ctx.logger = create_logger(
        name, ctx.log_level,
        pyyjj.location(mode, pyyjj.category.STRATEGY, group, name,
                       ctx.locator))

    ctx.strategy = Strategy(ctx)  # keep strategy alive for pybind11
    runner = Runner(ctx, mode)
    runner.add_strategy(ctx.strategy)

    if replay:
        ctx.session_id = session_id
        replay_setup.setup(ctx, session_id, strategy, runner)

    runner.run()