3.4 KiB
3.4 KiB
Quick Start: Local PostgreSQL Setup
Get your trading system running with a local PostgreSQL database in 5 minutes!
Prerequisites
- PostgreSQL installed (see LOCAL_DB_SETUP.md for installation)
- Node.js and npm installed
- CSV files in project root:
OptionsFlow.csv,OptionsVolume.csv,OptionsOpenInterest.csv
Step-by-Step Setup
1. Install PostgreSQL (if not already installed)
Windows:
- Download from: https://www.postgresql.org/download/windows/
- Install and remember the password you set for
postgresuser
macOS:
brew install postgresql@15
brew services start postgresql@15
Linux:
sudo apt install postgresql postgresql-contrib
sudo systemctl start postgresql
2. Configure Environment
Create backend/.env file:
USE_LOCAL_DB=true
LOCAL_DB_HOST=localhost
LOCAL_DB_PORT=5432
LOCAL_DB_USER=postgres
LOCAL_DB_PASSWORD=your_postgres_password
LOCAL_DB_NAME=institutional_trader
PORT=3010
NODE_ENV=development
CORS_ORIGIN=http://localhost:5173
Important: Replace your_postgres_password with your actual PostgreSQL password.
3. Set Up Database
cd backend
npm install
npm run setup-local-db
This creates:
- ✅ Database
institutional_trader - ✅ All necessary tables
- ✅ Indexes for performance
4. Import CSV Files
npm run import-csv
This imports:
- ✅ OptionsFlow.csv → OptionsFlow_monthly table
- ✅ OptionsVolume.csv → OptionsVolume table
- ✅ OptionsOpenInterest.csv → OptionsOpenInterest table
5. Start Server
npm run dev
You should see:
📦 Using local PostgreSQL database
✅ Database connection successful (PostgreSQL direct)
🚀 Server running on http://localhost:3010
Verify Everything Works
-
Check database connection:
- Server should show:
✅ Database connection successful
- Server should show:
-
Test API endpoint:
curl http://localhost:3010/api/options/flow?startDate=2024-12-10&endDate=2024-12-10 -
Check data was imported:
-- Connect to database psql -U postgres -d institutional_trader -- Check record counts SELECT COUNT(*) FROM "OptionsFlow_monthly"; SELECT COUNT(*) FROM "OptionsVolume"; SELECT COUNT(*) FROM "OptionsOpenInterest";
Troubleshooting
"Cannot connect to PostgreSQL"
-
Check PostgreSQL is running:
# Windows: Check Services # macOS brew services list # Linux sudo systemctl status postgresql -
Start PostgreSQL if needed:
# macOS brew services start postgresql@15 # Linux sudo systemctl start postgresql
"password authentication failed"
- Verify password in
.envmatches your PostgreSQL password - Try connecting manually:
psql -U postgres -h localhost
"database does not exist"
- Run setup again:
npm run setup-local-db
Next Steps
✅ Database is set up and running locally ✅ CSV data is imported ✅ Server is running
You can now:
- Test all API endpoints
- Develop new features
- Run queries without quota limits
- Work offline
Switching Back to Remote Database
When you want to use Supabase again:
-
Update
.env:USE_LOCAL_DB=false DATABASE_URL=postgresql://postgres:password@host:5432/database -
Restart server
The system automatically detects which database to use based on your .env configuration.