From 75a5682e46bdd7926f88d5ca0c22f15a26a3a570 Mon Sep 17 00:00:00 2001 From: moshferatu Date: Sat, 3 Feb 2024 05:34:51 -0800 Subject: [PATCH] Update trade upsert example to strip seconds, microseconds, and timezone information from the trade entry time --- requirements.txt | 1 + upsert_trade_example.py | 11 ++++++++--- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/requirements.txt b/requirements.txt index 5225320..0a0829d 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,4 +1,5 @@ pandas psycopg2 python-dotenv +pytz sqlalchemy \ No newline at end of file diff --git a/upsert_trade_example.py b/upsert_trade_example.py index bca2f9a..2202c48 100644 --- a/upsert_trade_example.py +++ b/upsert_trade_example.py @@ -1,12 +1,17 @@ import pandas as pd from database.trades import upsert +from datetime import datetime +from pytz import timezone + +now = datetime.now().astimezone(timezone('US/Eastern')) +now = now.replace(second = 0, microsecond = 0, tzinfo = None) trade_data = { - 'Date': ['2024-01-22'], + 'Date': [now.date()], 'Symbol': ['SPX'], - 'Strategy': ['Iron Condor @ Market Open'], - 'Entry Time': [pd.to_datetime('2024-01-22 09:30:00')], + 'Strategy': ['Iron Condor'], + 'Entry Time': [now], 'Exit Time': [None], 'Spreads': [ [