Ejemplo n.º 1
0
    def start_up(self, env, mod_config):

        if env.config.base.run_type == RUN_TYPE.LIVE_TRADING:
            return

        mod_config.matching_type = self.parse_matching_type(mod_config.matching_type)

        if env.config.base.margin_multiplier <= 0:
            raise patch_user_exc(ValueError(_(u"invalid margin multiplier value: value range is (0, +∞]")))

        if env.config.base.frequency == "tick":
            mod_config.volume_limit = False
            if mod_config.matching_type not in [
                MATCHING_TYPE.NEXT_TICK_LAST,
                MATCHING_TYPE.NEXT_TICK_BEST_OWN,
                MATCHING_TYPE.NEXT_TICK_BEST_COUNTERPARTY,
            ]:
                raise RuntimeError(_("Not supported matching type {}").format(mod_config.matching_type))
        else:
            if mod_config.matching_type not in [
                MATCHING_TYPE.NEXT_BAR_OPEN,
                MATCHING_TYPE.CURRENT_BAR_CLOSE,
            ]:
                raise RuntimeError(_("Not supported matching type {}").format(mod_config.matching_type))

        if mod_config.signal:
            env.set_broker(SignalBroker(env, mod_config))
        else:
            env.set_broker(SimulationBroker(env, mod_config))

        event_source = SimulationEventSource(env)
        env.set_event_source(event_source)
        env.event_bus.add_listener(EVENT.BEFORE_SYSTEM_RESTORED, self._before_system_restore)
Ejemplo n.º 2
0
    def start_up(self, env, mod_config):
        self._env = env
        if env.config.base.run_type == RUN_TYPE.LIVE_TRADING:
            return

        mod_config.matching_type = self.parse_matching_type(
            mod_config.matching_type)

        if env.config.base.margin_multiplier <= 0:
            raise patch_user_exc(
                ValueError(
                    _(u"invalid margin multiplier value: value range is (0, +∞]"
                      )))

        if env.config.base.frequency == "tick":
            mod_config.volume_limit = False
            if mod_config.matching_type not in [
                    MATCHING_TYPE.NEXT_TICK_LAST,
                    MATCHING_TYPE.NEXT_TICK_BEST_OWN,
                    MATCHING_TYPE.NEXT_TICK_BEST_COUNTERPARTY,
                    MATCHING_TYPE.COUNTERPARTY_OFFER,
            ]:
                raise RuntimeError(
                    _("Not supported matching type {}").format(
                        mod_config.matching_type))
        else:
            if mod_config.matching_type not in [
                    MATCHING_TYPE.NEXT_BAR_OPEN,
                    MATCHING_TYPE.VWAP,
                    MATCHING_TYPE.CURRENT_BAR_CLOSE,
            ]:
                raise RuntimeError(
                    _("Not supported matching type {}").format(
                        mod_config.matching_type))

        if env.config.base.frequency == "1d" and mod_config.matching_type == MATCHING_TYPE.NEXT_BAR_OPEN:
            mod_config.matching_type = MATCHING_TYPE.CURRENT_BAR_CLOSE
            user_system_log.warn(
                _(u"matching_type = 'next_bar' is abandoned when frequency == '1d',"
                  u"Current matching_type is 'current_bar'."))

        if mod_config.signal:
            env.set_broker(SignalBroker(env, mod_config))
        else:
            env.set_broker(SimulationBroker(env, mod_config))

        if mod_config.management_fee:
            env.event_bus.add_listener(EVENT.POST_SYSTEM_INIT,
                                       self.register_management_fee_calculator)

        event_source = SimulationEventSource(env)
        env.set_event_source(event_source)
Ejemplo n.º 3
0
    def init_fixture(self):
        from rqalpha.mod.rqalpha_mod_sys_simulation.simulation_event_source import SimulationEventSource

        super(SimulationEventSourceFixture, self).init_fixture()
        self.simulation_event_source = SimulationEventSource(self.env)