Hey all – I feel as though there must be a very simple solution to this problem, but I'm stumped for what that might be...
I'm writing an algorithm that enters trades intraday, and I would like to log the time (hour and minute) those trades are entered during a backtest in EST timezone. Here is the snippet of code for my entries:
# LONG ENTRY ORDER
if (currentPrice > sixtyBars) and currentPositions == 0:
positionSize = int((cash * 0.2) / currentPrice)
order(context.stock, positionSize)
log.info('Long Entry: Bought {0} shares at ${1}.'.format(positionSize, currentPrice))
# TIME LOG
eastern = timezone('US/Eastern') # Sets EST timezone
entryTime = data[context.stock].datetime # Gets time of entry -- but needs to be eastern!
log.debug(entryTime.strftime('%x - %H:%M - %Z')) # Logs time of entry -- displaying date, hour, minute, and timezone
Here are the current logs from the code above:
2015-12-04 firstHour:56 INFO Long Entry: Bought 84 shares at $118.1.
2015-12-04 firstHour:62 DEBUG 12/04/15 - 15:30 - UTC
If only I could somehow apply the 'eastern' variable to the 'entryTime' variable – just not sure how to do this?
Any help/suggestions would be hugely appreciated.