| name | data-sync |
| description | Manage data population and synchronization for ASIC short data and stock prices. Use when populating the database, syncing data, or troubleshooting data issues. |
| allowed-tools | Read, Write, Bash(make:*), Bash(python*), Bash(psql:*), Grep, Glob |
Data Synchronization
This skill guides you through data population and synchronization workflows for the Shorted project.
Quick Reference
make populate-data
make populate-data-quick
make daily-sync-local
make algolia-sync
Data Sources
| Data Type | Source | Frequency | Location |
|---|
| Short positions | ASIC CSV files | Daily | services/data/shorts/ |
| Stock prices | Yahoo Finance / Alpha Vantage | Daily | Database stock_prices table |
| Company metadata | GPT-4 enrichment | On-demand | Database company-metadata table |
ASIC Short Data Population
Full Population (First Time)
Downloads ~3,500 CSV files from ASIC and populates the database:
make populate-data
This takes 30-60 minutes and:
- Downloads all historical ASIC CSV files
- Parses and validates the data
- Inserts into the
shorts table
Quick Population (Existing Files)
If CSV files already exist in services/data/shorts/:
make populate-data-quick
Force Re-download
cd services && make populate-data-force
Stock Price Data
Historical Backfill
cd services && make history.stock-data.backfill-test
cd services && make history.stock-data.backfill
cd services && make history.stock-data.backfill-full
Repair Data Gaps
make repair-gaps-dry-run
make repair-gaps STOCKS=CBA,BHP
make repair-gaps-all
Check Status
cd services && make history.stock-data.status
Daily Sync Pipeline
The daily sync updates both short positions and stock prices:
make daily-sync-local
make daily-sync-deploy
make daily-sync-execute
make daily-sync-logs
Daily Sync Configuration
The sync is configured in services/daily-sync/ and runs:
- ASIC Sync: Downloads latest short position CSV
- Stock Price Sync: Updates prices for all tracked stocks
- Algolia Sync: Updates search index (optional)
Algolia Search Index
Sync Search Index
make algolia-sync
make algolia-sync-prod
Test Search
make algolia-search Q=BHP
Company Metadata Enrichment
Enrich company data using GPT-4:
make enrich-metadata LIMIT=10
make enrich-metadata-stocks STOCKS="CBA BHP WBC"
make enrich-metadata-all
Full Data Pipeline
Run the complete pipeline:
make pipeline-local
make pipeline-prod
make pipeline-daily
Database Verification
Check Short Data
SELECT COUNT(*) FROM shorts;
SELECT COUNT(DISTINCT "PRODUCT_CODE") FROM shorts;
SELECT MIN("DATE")::date, MAX("DATE")::date FROM shorts;
SELECT "PRODUCT_CODE", COUNT(*)
FROM shorts
GROUP BY "PRODUCT_CODE"
ORDER BY COUNT(*) DESC
LIMIT 10;
Check Stock Prices
SELECT COUNT(*) FROM stock_prices;
SELECT MIN(date), MAX(date) FROM stock_prices;
SELECT stock_code, COUNT(*) as records
FROM stock_prices
GROUP BY stock_code
ORDER BY records DESC
LIMIT 10;
Check Company Metadata
SELECT COUNT(*) FROM "company-metadata"
WHERE description IS NOT NULL;
SELECT stock_code, name
FROM "company-metadata"
WHERE logo_url IS NULL
LIMIT 20;
Troubleshooting
Data Not Loading
-
Check database connection:
make dev-db
docker ps
-
Verify CSV files exist:
ls -la services/data/shorts/ | head -20
-
Check for errors in logs:
make daily-sync-logs
Stale Data
cd services && make populate-data-force
psql postgresql://admin:password@localhost:5438/shorts \
-c "TRUNCATE shorts RESTART IDENTITY;"
make populate-data
Missing Stock Prices
cd services && make history.stock-data.status
make repair-gaps STOCKS=CBA,BHP,CSL
Performance Issues
make db-diagnose
make db-optimize
psql postgresql://admin:password@localhost:5438/shorts \
-c "ANALYZE shorts; ANALYZE \"company-metadata\";"
Environment Variables
Required for data sync operations:
DATABASE_URL=postgresql://admin:password@localhost:5438/shorts
ALPHA_VANTAGE_API_KEY=your_key_here
ALGOLIA_APP_ID=1BWAPWSTDD
ALGOLIA_ADMIN_KEY=your_admin_key
OPENAI_API_KEY=sk-...