Manage your sports betting positions in real-time by using RisingWave to monitor exposure and risk.
psql
, is installed in your environment. For detailed instructions, see Download PostgreSQL.positions
tracks key details about each betting position within different sports league. It contains information such as the stake amount, expected return, fair value, and market odds, allowing us to assess the risk and performance of each position.
market_data
describes the market activity related to specific positions. You can track pricing and volume trends across different bookmakers, observing pricing changes over time.
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:
position_overview
materialized view provides key information on each position, such as the stake, max risk, market price, profit loss, and risk level. It joins the positions
table with the most recent market_price
from the market_data
table. This is done using ROW_NUMBER()
, which assigns a rank to each record based on position_id
, ordered by the timestamp in descending order.
profit_loss
is calculated as the difference between market_price
and fair_value
while risk_level
is based on profit_loss
relative to max_risk
.
position_overview
to see the results.
risk_summary
materialized view gives an overview on the number of positions that are considered “High”, “Medium”, or “Low” risk. Group by risk_level
from position_overview
and count the number of positions in each category.
This allows us to quickly understand overall risk exposure across all positions.
risk_summary
to see the results.
market_summary
materialized view shows the current market data for each betting from the positions
table. It joins positions
and market_data
to include the most recent market price for each bookmaker. Again, ROW_NUMBER()
is used to retrieve the most recent record for each bookmaker and position.
market_summary
to see the results.
Ctrl+C
to close the connection between RisingWave and psycopg2
.
psycopg2
.ROW_NUMBER()
to retrieve the most recent message based on the timestamp.