Beispiel #1
0
def strategy(ctx, group, name):
    pass_ctx_from_root(ctx)
    ctx.group = group
    ctx.name = name
    ctx.category = 'strategy'
    ctx.mode = "live"
    ctx.low_latency = False
    ctx.logger = create_logger(
        ctx.name, ctx.log_level,
        pyyjj.location(pyyjj.get_mode_by_name(ctx.mode),
                       pyyjj.category.STRATEGY, ctx.group, ctx.name,
                       ctx.locator))
    ctx.path = None
    ctx.runner = Runner(ctx, pyyjj.get_mode_by_name(ctx.mode))

    def init_strategy_patch(self, path):
        pass

    with patch.object(Strategy, '_Strategy__init_strategy',
                      init_strategy_patch):
        ctx.strategy = Strategy(ctx)
        ctx.strategy._pre_start = lambda ctx: None
        ctx.strategy._post_start = lambda ctx: None
        ctx.strategy._pre_stop = lambda ctx: None
        ctx.strategy._post_stop = lambda ctx: None
        ctx.strategy._on_trading_day = lambda ctx, daytime: None
        ctx.strategy._on_entrust = lambda ctx, entrust: None
        ctx.strategy._on_transaction = lambda ctx, transaction: None
        ctx.strategy._on_quote = lambda ctx, quote: ctx.logger.info(
            "quote received: {}".format(quote))
        ctx.strategy._on_order = lambda ctx, order: ctx.logger.info(
            "order received: {}".format(order))
        ctx.strategy._on_trade = lambda ctx, trade: ctx.logger.info(
            "trade received: {}".format(trade))
Beispiel #2
0
 def __init_ledger(self):
     ledger_location = pyyjj.location(pyyjj.get_mode_by_name(self.ctx.mode), pyyjj.category.SYSTEM, 'service', 'ledger', self.ctx.locator)
     self.ctx.ledger_db = LedgerDB(ledger_location, "ledger")
     self.ctx.inst_infos = { inst["instrument_id"]: inst for inst in self.ctx.ledger_db.all_instrument_infos() }
     self.ctx.ledger = self.ctx.ledger_db.load(ctx=self.ctx,ledger_category=LedgerCategory.Portfolio, client_id=self.ctx.name)
     if self.ctx.ledger is None:
         self.ctx.ledger = AccountBook(self.ctx, ledger_category=LedgerCategory.Portfolio,client_id=self.ctx.name, avail=1e7, trading_day=self.ctx.trading_day)
Beispiel #3
0
def strategy(ctx, group, name):
    pass_ctx_from_root(ctx)
    ctx.group = group
    ctx.name = name
    ctx.category = 'strategy'
    ctx.mode = "live"
    ctx.low_latency = False
    ctx.logger = create_logger(
        ctx.name, ctx.log_level,
        pyyjj.location(pyyjj.get_mode_by_name(ctx.mode),
                       pyyjj.category.STRATEGY, ctx.group, ctx.name,
                       ctx.locator))
    ctx.path = None
    ctx.runner = Runner(ctx, pyyjj.get_mode_by_name(ctx.mode))

    def init_strategy_patch(self, path):
        pass

    with patch.object(Strategy, '_Strategy__init_strategy',
                      init_strategy_patch):
        ctx.strategy = Strategy(ctx)
Beispiel #4
0
 def __init_ledger(self):
     ledger_location = pyyjj.location(pyyjj.get_mode_by_name(self.ctx.mode),
                                      pyyjj.category.SYSTEM, 'service',
                                      'ledger', self.ctx.locator)
     self.ctx.ledger_db = LedgerDB(ledger_location, "ledger")
     self.ctx.inst_infos = {
         inst["instrument_id"]: inst
         for inst in self.ctx.ledger_db.all_instrument_infos()
     }
     book_tags = AccountBookTags(ledger_category=LedgerCategory.Portfolio,
                                 client_id=self.ctx.name)
     self.ctx.book = self.ctx.ledger_db.load(ctx=self.ctx,
                                             book_tags=book_tags)
     if self.ctx.book is None:
         self.ctx.book = AccountBook(self.ctx, tags=book_tags, avail=1e7)