Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 21 additions & 13 deletions update_utils/process_live.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,19 +108,21 @@ def process_live():
print("🔄 Processing Live Trades")
print("=" * 60)

last_processed = {}
last_processed = None

if os.path.exists(processed_file):
print(f"✓ Found existing processed file: {processed_file}")
result = subprocess.run(['tail', '-n', '1', processed_file], capture_output=True, text=True)
last_line = result.stdout.strip()
splitted = last_line.split(',')

last_processed['timestamp'] = pd.to_datetime(splitted[0])
last_processed['transactionHash'] = splitted[-1]
last_processed['maker'] = splitted[2]
last_processed['taker'] = splitted[3]

last_processed = {
'timestamp': pd.to_datetime(splitted[0]),
'transactionHash': splitted[-1],
'maker': splitted[2],
'taker': splitted[3],
}

print(f"📍 Resuming from: {last_processed['timestamp']}")
print(f" Last hash: {last_processed['transactionHash'][:16]}...")
else:
Expand All @@ -142,13 +144,19 @@ def process_live():

df = df.with_row_index()

same_timestamp = df.filter(pl.col('timestamp') == last_processed['timestamp'])
same_timestamp = same_timestamp.filter(
(pl.col("transactionHash") == last_processed['transactionHash']) & (pl.col("maker") == last_processed['maker']) & (pl.col("taker") == last_processed['taker'])
)

df_process = df.filter(pl.col('index') > same_timestamp.row(0)[0])
df_process = df_process.drop('index')
if last_processed is None:
df_process = df.drop('index')
else:
same_timestamp = df.filter(pl.col('timestamp') == last_processed['timestamp'])
same_timestamp = same_timestamp.filter(
(pl.col("transactionHash") == last_processed['transactionHash']) & (pl.col("maker") == last_processed['maker']) & (pl.col("taker") == last_processed['taker'])
)

if same_timestamp.is_empty():
print("⚠ Last processed row not found in source data; processing all rows")
df_process = df.drop('index')
else:
df_process = df.filter(pl.col('index') > same_timestamp.row(0)[0]).drop('index')

print(f"⚙️ Processing {len(df_process):,} new rows...")

Expand Down