aboutsummaryrefslogtreecommitdiff
path: root/server/create_db.py
diff options
context:
space:
mode:
Diffstat (limited to 'server/create_db.py')
-rw-r--r--server/create_db.py84
1 files changed, 84 insertions, 0 deletions
diff --git a/server/create_db.py b/server/create_db.py
new file mode 100644
index 0000000..44646be
--- /dev/null
+++ b/server/create_db.py
@@ -0,0 +1,84 @@
+from datetime import datetime, timedelta, timezone
+from db import Base, engine, SessionLocal
+from models.auth import User
+from models.bid import Bid
+from models.market import MarketData
+from zoneinfo import ZoneInfo
+
+NEW_ENGLAND_TZ = ZoneInfo("America/New_York")
+
+def init_db():
+ Base.metadata.create_all(bind=engine)
+ db = SessionLocal()
+
+ # Create default user if not exists
+ user = db.query(User).filter(User.username == "user").first()
+ if not user:
+ user = User(username="user", password="password")
+ db.add(user)
+ db.commit()
+ db.refresh(user)
+ else:
+ print("Default user already exists.")
+
+ # Insert dummy bids for 2025-04-25
+ existing_bids = db.query(Bid).filter(Bid.timestamp.between(
+ datetime(2025, 4, 25, 0, 0),
+ datetime(2025, 4, 25, 23, 59)
+ )).all()
+
+ if not existing_bids:
+ print("Inserting dummy bids for 2025-04-25...")
+ dummy_bids = []
+
+ times_and_prices = [
+ (5, 30.0),
+ (8, 35.0),
+ (12, 40.0),
+ (18, 45.0),
+ ]
+
+ for hour, price in times_and_prices:
+ bid = Bid(
+ timestamp=datetime(2025, 4, 25, hour, 0),
+ quantity=10.0,
+ price=price,
+ user_id=user.id,
+ status="Submitted",
+ pnl=None
+ )
+ dummy_bids.append(bid)
+
+ db.add_all(dummy_bids)
+ db.commit()
+ print(f"Inserted {len(dummy_bids)} dummy bids for 2025-04-25.")
+ else:
+ print("Dummy bids for 2025-04-25 already exist.")
+
+ # Insert one dummy bid for today at 11:00PM local time
+ today_local = datetime.now(NEW_ENGLAND_TZ).date()
+ bid_time_local = datetime.combine(today_local, datetime.min.time(), tzinfo=NEW_ENGLAND_TZ).replace(hour=23)
+ bid_time_utc = bid_time_local.astimezone(timezone.utc)
+
+ existing_bid_today = db.query(Bid).filter(Bid.timestamp == bid_time_utc).first()
+
+ if not existing_bid_today:
+ print(f"Inserting dummy bid for today at {bid_time_local.strftime('%Y-%m-%d %I:%M %p')} local time...")
+ today_bid = Bid(
+ timestamp=bid_time_utc,
+ quantity=20.0,
+ price=50.0,
+ user_id=user.id,
+ status="Submitted",
+ pnl=None
+ )
+ db.add(today_bid)
+ db.commit()
+ print("Inserted dummy bid for today at 11:00PM.")
+ else:
+ print("Dummy bid for today at 11:00PM already exists.")
+
+ db.close()
+
+if __name__ == "__main__":
+ init_db()