For code/output blocks: Use ``` (aka backtick or grave accent) in a single line before and after the block. See:

Getting executed time - Float to Datetime

  • Hi. I am trying to debug my execution times and am getting a weird float output when I use notify_order. I am trying to convert the float of 'order.executed.dt' to datetime to print a string.

    My question is how to convert this float to readable string, as i am getting weird errors. When I print the float as is I get '735480.4798611111' which equates to Sept 1970. The data I am using is 8/1/2014 10:31:00 AM.

    What am I doing wrong here?

    Here is the code

    def notify_order(self, order):
            if order.status in [order.Submitted, order.Accepted]:
                # Buy/Sell order submitted/accepted to/by broker - Nothing to do
            # Check if an order has been completed
            # Attention: broker could reject order if not enougth cash
            if order.status in [order.Completed]:
                if order.isbuy():
                        'BUY EXECUTED, Price: %.2f, Cost: %.2f, Comm %.2f, Datetime: %s' %
                        datetime.datetime.strftime(datetime.datetime.fromtimestamp(order.executed.dt),'%Y-%m-%d %H:%M:%S')))

  • administrators

    The float is a timestamp as defined by matplotlib

    See for example here: Docs - Evaluating external historical performance for how to convert it with

    Using the method of the data feed guarantees appropriate timezone conversions. If you are using no timezones, you can simply use backtrader.num2date

  • Solved. Thank you so much for the really quick reply!

    Here is the code for reference for anyone else.

    self.log('SELL EXECUTED, Price: %.2f, Cost: %.2f, Comm %.2f, Datetime: %s' %