Detect suspicious patterns, compliance breaches, and anomalies from trading activities in real-time.
psql
, is installed in your environment. For detailed instructions, see Download PostgreSQL.trade_data
tracks key details about individual trades, such as the buyer, seller, volume, and price of the trade.
market_data
table tracks information related to financial assets, such as the bid price, ask price, and the trading volume over a rolling time period..
data_generator.py
file. This Python script utilizes the psycopg2
library to establish a connection with RisingWave so you can generate and insert synthetic data into the tables positions
and market_data
.
If you are not running RisingWave locally or using default credentials, update the connection parameters accordingly:
unusual_volume
materialized view indicates if a trade has a higher than average trading volume within a 10-minute window. TUMBLE()
is used to to split everything into non-overlapping 10-minute windows. GROUP BY
is used to group the data by the unique trade ID, asset ID, volume, and window start time. Then PARTITION BY
is used to ensure that the average volume is calculated separately for each asset.
If the trade’s volume is 1.5 times greater than the average volume of each asset over the past ten-minutes, it is marked as an unusual trade.
position_overview
to see the results. High volume trades are indicated in the unusual_volume
column.
price_spike
materialized view analyzes the price fluctuation of assets within a five-minute window to detect potential price spikes. For each asset, calculate the percent change between the highest and lower prices within a five-minute window.
A price spike for the asset is detected if the percentage change exceeds 5%.
price_spike
to see the results. The if_price_spike
column denotes if there was a price spike for the asset.
spoofing_detection
materialized view detects potential spoofing activity by analyzing the bid-ask price difference and the trading volume.
The following two conditions must be met to flag spoofing activity:
spoofing_detection
to see the results.
Ctrl+C
to close the connection between RisingWave and psycopg2
.
PARTITION BY
to calculate the average volume separately for each asset