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 return # 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(): self.log( 'BUY EXECUTED, Price: %.2f, Cost: %.2f, Comm %.2f, Datetime: %s' % (order.executed.price, order.executed.value, order.executed.comm, datetime.datetime.strftime(datetime.datetime.fromtimestamp(order.executed.dt),'%Y-%m-%d %H:%M:%S')))
The float is a timestamp as defined by
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
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' % (order.executed.price, order.executed.value, order.executed.comm, bt.num2date(order.executed.dt)))