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 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.º 3
0
def watcher(ctx, low_latency, replay, session_id):
    pass_ctx_from_parent(ctx)
    ctx.low_latency = low_latency if not replay else True
    ctx.replay = replay
    ctx.session_id = session_id
    watcher_instance = Watcher(ctx)
    if replay:
        ctx.category = 'system'
        ctx.group = 'watcher'
        ctx.name = 'watcher'
        replay_setup.setup(ctx, session_id, watcher, watcher_instance)
    watcher_instance.run()
Exemplo n.º 4
0
def ledger(ctx, low_latency, replay, session_id):
    pass_ctx_from_parent(ctx)
    ctx.low_latency = low_latency if not replay else True
    ctx.replay = replay
    ctx.mode = pyyjj.mode.REPLAY if ctx.replay else pyyjj.mode.LIVE
    ctx.session_id = session_id
    ledger_instance = Ledger(ctx)
    if replay:
        ctx.category = 'system'
        ctx.group = 'service'
        ctx.name = 'ledger'
        replay_setup.setup(ctx, session_id, ledger, ledger_instance)
    ledger_instance.run()
Exemplo n.º 5
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.session_id = session_id
    mode = pyyjj.mode.REPLAY if ctx.replay 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)
    if replay:
        ctx.category = 'strategy'
        replay_setup.setup(ctx, session_id, strategy, runner)
    runner.run()