1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
|
from datetime import datetime, timedelta, timezone, UTC
from db import Base, engine, SessionLocal
from models.auth import User
from models.bid import Bid
from models.market import MarketDataDB
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, tzinfo=NEW_ENGLAND_TZ).astimezone(UTC),
quantity=10.0,
price=price,
user_id=user.id,
market="ISONE",
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,
market="ISONE",
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()
|