A simple Python backend for a trading platform using Quart and asyncpg.
- User authentication with httpOnly cookies (no JWT)
- Wallet management (deposit, withdraw, transfer)
- Trading functionality (buy/sell assets)
- Copy trading subscriptions
- Admin panel for user management and withdrawal approvals
- PostgreSQL database with asyncpg
- Email notifications for important events
The backend automatically sends email notifications for:
- Welcome Email: Sent after successful account registration
- Login Notifications: Sent after each successful login
- Withdrawal Requests: Sent when user requests a withdrawal
- Withdrawal Approvals: Sent when admin approves a withdrawal
- Trade Executions: Sent when a trade order is executed
- Password Reset: Sent when user requests password reset (if implemented)
To enable email notifications:
- Configure SMTP settings in
.envfile - For Gmail, use an "App Password" instead of your regular password
- Enable "Less secure app access" or use OAuth2 for production
Example Gmail setup:
SMTP_SERVER=smtp.gmail.com
SMTP_PORT=587
[email protected]
SMTP_PASSWORD=your-gmail-app-passwordThis backend is optimized for Supabase PostgreSQL. Follow these steps:
- Go to supabase.com and create a new project
- Wait for the database to be set up
In your Supabase dashboard:
- Go to Settings → Database
- Copy the connection details (host, port, user, password, database name)
- Use the Pooled connection for better performance
Update your .env file with Supabase connection details:
# Option 1: Use full DATABASE_URL (recommended)
DATABASE_URL=postgresql://postgres.[your-project-ref]:[your-password]@aws-0-[region].pooler.supabase.com:6543/postgres?sslmode=require
# Option 2: Use individual components
SUPABASE_DB_HOST=aws-0-[region].pooler.supabase.com
SUPABASE_DB_PORT=6543
SUPABASE_DB_NAME=postgres
SUPABASE_DB_USER=postgres.[your-project-ref]
SUPABASE_DB_PASSWORD=your-passwordRun the SQL schema in your Supabase dashboard:
- Go to SQL Editor in your Supabase dashboard
- Copy and paste the contents of
supabase_schema.sql - Click Run to create all tables and initial data
python setup_db.pyThis will verify the connection and create any missing data.
If you prefer to use a traditional PostgreSQL instance instead of Supabase:
# Ubuntu/Debian
sudo apt-get install postgresql postgresql-contrib
# macOS with Homebrew
brew install postgresql
# Or use Docker
docker run --name postgres -e POSTGRES_PASSWORD=mypassword -d -p 5432:5432 postgresDATABASE_URL=postgresql://username:password@localhost:5432/trading_platformpython setup_db.pyAfter setup is complete:
python run.pyThe application will start on http://localhost:5000.
POST /login- User loginPOST /signup- User registrationPOST /logout- User logoutGET /user- Get current user infoPOST /forgot-password- Password reset request
GET /wallet- Get wallet balancePOST /deposit- Deposit fundsPOST /withdraw- Request withdrawalPOST /transfer- Transfer funds to another userGET /withdrawals- Get user's withdrawal history
POST /trade- Place a trade orderGET /trades- Get user's trade historyPOST /copy/subscribe- Subscribe to copy traderGET /copy/subscriptions- Get user's subscriptions
GET /admin/users- Get all usersPOST /admin/users/{user_id}/block- Block/unblock userGET /admin/withdrawals- Get all withdrawalsPOST /admin/withdrawals/{id}/approve- Approve withdrawal
Use the supabase_schema.sql file in your Supabase SQL Editor to create tables.
The application automatically creates the following tables on startup:
users- User accountswallet_transactions- Wallet transaction historytrades- Trade recordswithdrawals- Withdrawal requestscopy_trading_subscriptions- Copy trading subscriptions
- Passwords are stored in plain text (as requested - not recommended for production)
- Uses httpOnly cookies for session management
- All wallet operations are tracked in transaction history
- Balance is calculated from transaction history
- Admin role is required for admin endpoints