INNER CODE UNIT · Python
get_timestamp
ldt9/PyOptionTrader · models/futures/short_strangle.py:151
def get_timestamp(self):
# Get the current datetime
now = datetime.datetime.now()
# Format the datetime as a string with seconds
timestamp = now.strftime("[%Y-%m-%d %I:%M:%S%p]")
return timestamp
def on_open_order_update(self, trade: Trade):
# Add the order to the log
conId = trade.contract.comboLegs[0].conId
self.open_order_log.append(conId)
# Count the current number of unique orders
current_unique_orders = len(set(self.open_order_log))
# Check if a new unique order is added
if current_unique_orders > self.previous_unique_orders:
print(f"{self.get_timestamp()} New Order Created")
self.previous_unique_orders = current_unique_orders
self.order_placed = not self.order_placed