How to use the backtesting.backtest_broker.BacktestBroker.get_time function in Backtesting

To help you get started, we’ve selected a few Backtesting examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github paperduck / algo / src / backtesting / strategies / demo.py View on Github external
def _scan(self):
        """Look for opportunities to open a position.
        Returns:
            [] if there is an opportunity.
            Empty list if no opportunities.
            None on failure.
        """
        for iid in self.instrument_ids:
            now = broker.get_time()
            spread = broker.get_spread(iid)
            price = broker.get_price(iid)
            goal = spread # goal profit per trade

            # always update the price history
            if self.last_history_update == None or now - self.last_history_update >= timedelta(minutes=1):
                self.last_history_update = now
                # shift everything by one
                for i in range(len(self.price_history)-1, 0, -1):
                    self.price_history[i] = self.price_history[i-1]
                self.price_history[0] = price

            # check for opp
            go = False
            # only if price history completely filled
            if not None in self.price_history: