34 lines
2.2 KiB
Markdown
34 lines
2.2 KiB
Markdown
### Task Title
|
||
|
||
Trading Activity Summary for a User
|
||
|
||
You are given access to a PostgreSQL database containing trading activity data. Your goal is to generate a JSON report that summarizes trading activity for a specific user over a specified date range.
|
||
|
||
The report must be written to /app/report.json and must contain exactly these seven fields:
|
||
|
||
1. user_id – identifier of the user whose activity is being summarized
|
||
2. date_range_start – start date (inclusive) in YYYY-MM-DD format
|
||
3. date_range_end – end date (inclusive) in YYYY-MM-DD format
|
||
4. total_fills – count of rows in the trades table where event_type = 'fill' and exec_timestamp falls within the date range (inclusive)
|
||
5. total_pnl – sum of the net_pnl column for all rows counted in total_fills, including only rows where completed_trade_id is not null (completed trades)
|
||
6. symbol_quantities – object mapping each symbol to the net quantity from filled trades in the date range (positive for buys, negative for sells), summed per symbol
|
||
7. position_mismatches – array of symbol names where the net trade quantity differs from the net quantity in the positions table for the same user and date range by more than 1 (allowing for rounding)
|
||
|
||
### Constraints
|
||
|
||
- The report must be valid JSON parseable by jsonlint
|
||
- The file must be written exactly to /app/report.json; no other output files are permitted
|
||
- You may read any tables in the schema but may not modify underlying data (no INSERT/UPDATE/DELETE)
|
||
- The task runs offline (no network access)
|
||
- The task is solved when solution/solve.sh exits with status 0, causing the verifier to award reward of 1
|
||
|
||
### Key definitions
|
||
|
||
- **Date range filter**: exec_timestamp values are filtered by casting to date and comparing inclusive boundaries
|
||
- **Completed trade**: a trade row with completed_trade_id not null
|
||
- **Net quantity**: sum of qty values (BUY = positive, SELL = negative) per symbol
|
||
- **Position mismatch**: |summed trade qty per symbol − positions.net_qty per symbol| > 1
|
||
|
||
### Success criteria
|
||
|
||
The verifier will load /app/report.json, parse it, and compare all fields against a ground-truth generated by the oracle. If all fields match, the verifier writes reward of 1 to /logs/verifier/reward.txt and {"reward": 1} to /logs/verifier/reward.json. |