A modern web application built with Flask that integrates with the Fyers API for trading and portfolio management.
- Secure Authentication: OAuth 2.0 integration with Fyers API
- Real-time Data: Access to profile information and funds data
- Modern UI: Responsive design with Bootstrap 5
- API Endpoints: RESTful API for profile and funds data
- Session Management: Secure session handling
- Python 3.7 or higher
- Fyers API credentials (Client ID and Secret Key)
- Active Fyers trading account
-
Clone or download the project
cd py-trade -
Install dependencies
pip install -r requirements.txt
-
Configure environment variables
Edit the
.envfile and add your Fyers API credentials:FYERS_CLIENT_ID=your_actual_client_id FYERS_SECRET_KEY=your_actual_secret_key FYERS_REDIRECT_URI=http://localhost:5000/callback FLASK_SECRET_KEY=your_secure_random_secret_keyImportant: Replace the placeholder values with your actual Fyers API credentials.
- Visit the Fyers API Portal
- Create a new app or use an existing one
- Note down your Client ID and Secret Key
- Set the redirect URI to
http://localhost:5000/callback
-
Start the Flask development server
python app.py
-
Access the application
Open your browser and navigate to:
http://localhost:5000
- Login: Click "Login with Fyers" to authenticate with your Fyers account
- Dashboard: View your profile information and funds data
- API Access: Use the API endpoints for programmatic access
GET /api/profile- Get user profile informationGET /api/funds- Get funds and margin information
py-trade/
├── app.py # Main Flask application
├── requirements.txt # Python dependencies
├── .env # Environment variables (configure this!)
├── README.md # This file
└── templates/ # HTML templates
├── base.html # Base template
├── index.html # Home page
└── dashboard.html # Dashboard page
- Never commit your
.envfile to version control - Use strong, unique secret keys
- The redirect URI must match exactly with your Fyers app configuration
- Sessions are secured with Flask's session management
-
"Invalid client_id" error
- Verify your Client ID in the
.envfile - Ensure there are no extra spaces or characters
- Verify your Client ID in the
-
"Redirect URI mismatch" error
- Check that the redirect URI in your Fyers app matches
http://localhost:5000/callback - Ensure the URI in
.envfile matches exactly
- Check that the redirect URI in your Fyers app matches
-
"Access token generation failed"
- Verify your Secret Key is correct
- Check that your Fyers account has API access enabled
The application runs in debug mode by default. For production deployment:
- Set
debug=Falseinapp.py - Use a production WSGI server like Gunicorn
- Set up proper environment variable management
- Fork the repository
- Create a feature branch
- Make your changes
- Test thoroughly
- Submit a pull request
This project is for educational and personal use. Please comply with Fyers API terms of service.
For issues related to:
- Fyers API: Contact Fyers support
- This application: Create an issue in the repository
Disclaimer: This application is for educational purposes. Always test thoroughly before using with real trading accounts.