Example #1
0
    def _init_func(self, context):
        """Sets up catalyst's context object and fetches external data"""

        self._context_ref = context

        self.state.load_from_context(context)

        self.log.info(f"Starting strategy on iteration {self.state.i}")

        self.state.asset = symbol(self.trading_info["ASSET"])
        if self.is_backtest:
            self.log.debug("Setting benchmark")
            set_benchmark(self.state.asset)

        if self._datasets.items():
            if self.state.DATA_FREQ == "daily":
                for dataset, manager in self._datasets.items():
                    manager.fetch_data()
            else:
                raise ValueError(
                    'Internal Error: Value of self.state.DATA_FREQ should be "minute" if you use Google Search Volume or Quandl datasets.'
                )

        self._extra_init(context)

        if self.in_job and not self.is_backtest:
            job = get_current_job()
            if job.meta.get("PAUSED"):
                self.notify("Your strategy has resumed!")
                self.log.info(f"Resuming on trade iteration {self.state.i}")
                self._load_state_end_time(context)

            else:
                self.notify("Your strategy has started!")
                self.state.i = 0
                self.state.errors = []
                self.state.end = context.end

        for k, v in self.trading_info.items():
            if "__" not in k:
                setattr(self.state, k, v)

        self.log.info("Initilized Strategy")
        self._check_configuration(context)

        # Set self.state.BARS size to work with custom minute frequency
        if self.state.DATA_FREQ == "minute":
            self.state.BARS = int(
                self.state.BARS * 24 * 60 / int(24 * 60 / int(self.state.MINUTE_FREQ))
            )

        self.date_init_reference = pd.Timestamp(
            "2013-01-01 00:00:00", tz="utc"
        ) + pd.Timedelta(minutes=int(self.state.MINUTE_TO_OPERATE))

        # Set commissions
        context.set_commission(
            maker=self.state.MAKER_COMMISSION, taker=self.state.TAKER_COMMISSION
        )
        self.state.dump_to_context(context)
Example #2
0
def initialize(context):
    context.ASSET_NAME = 'USDT_REP'
    context.asset = symbol(context.ASSET_NAME)
    set_benchmark(context.asset)
    context.is_first_time = True

    # For all trading pairs in the poloniex bundle, the default denomination
    # currently supported by Catalyst is 1/1000th of a full coin. Use this
    # constant to scale the price of up to that of a full coin if desired.
    context.TICK_SIZE = 1.0
Example #3
0
def initialize(context):
    context.NORMALIZED_PAIR = ALGO_INPUTS["PAIR"].upper().replace("_", "/")
    log.info(
        f'Initializing algo: {context.NORMALIZED_PAIR} @ {ALGO_INPUTS["EXCHANGE"]}'
    )
    context.SYMBOL = symbol(symbol_str=ALGO_INPUTS["PAIR"],
                            exchange_name=ALGO_INPUTS["EXCHANGE"])
    set_benchmark(context.SYMBOL)
    context.EXITED = False
    context.PLACING_ORDERS = False
    context.CANCELLING_ORDERS = False
def initialize(context):
    context.ASSET_NAME = 'USDT_BTC'
    context.asset = symbol(context.ASSET_NAME)
    set_benchmark(context.asset)
    
    # For all trading pairs in the poloniex bundle, the default denomination
    # currently supported by Catalyst is 1/1000th of a full coin. Use this
    # constant to scale the price of up to that of a full coin if desired.
    context.TICK_SIZE = 1000.0
    
    # Start this trading algorithm when market is bullish
    context.i = 0
    context.IS_MARKET_BEAR = False