ingestor / main.py · _handle_trade
# A tick and its derived alert ship in one transaction so a crash# mid-trade cannot leave a chart spike without its alert marker.async with conn.transaction(): await conn.execute( "INSERT INTO ticks (symbol, ts, price, volume) " "VALUES (%s, %s, %s, %s) " "ON CONFLICT (symbol, ts) DO NOTHING", (symbol, ts, price, volume), ) if result.is_anomaly: await conn.execute( "INSERT INTO alerts (symbol, ts, price, z_score, message) " "VALUES (%s, %s, %s, %s, %s)", (symbol, ts, price, result.z_score, message), )