-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgenerate_data.py
More file actions
28 lines (20 loc) · 785 Bytes
/
generate_data.py
File metadata and controls
28 lines (20 loc) · 785 Bytes
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
import struct
import time
import random
FILE_NAME = "market_data.bin"
NUM_RECORDS = 40_000_000
SYMBOL = b"NVDA "
print(f"Generating {NUM_RECORDS} records...")
with open(FILE_NAME, "wb") as f:
start_time = time.time()
# We use struct.pack to turn Python numbers into raw C-style bytes
# 'Q' = uint64, '8s' = 8-byte string, 'd' = double
packer = struct.Struct("<Q8sd")
for i in range(NUM_RECORDS):
timestamp = 1700000000000000000 + i
price = 150.0 + random.uniform(-1, 1)
f.write(packer.pack(timestamp, SYMBOL, price))
if i % 5_000_000 == 0:
print(f"Progress: {i}/{NUM_RECORDS}...")
end_time = time.time()
print(f"Finished! Created {FILE_NAME} in {end_time - start_time:.2f}s")