A FastAPI application for interacting with the Groww trading platform with enhanced features including portfolio management, stock quotes, and market status.
- Order Management: Place BUY/SELL orders with automatic market/limit detection
- Stock Quotes: Get real-time quotes for single or multiple stocks
- Portfolio Tracking: View current holdings and P&L (placeholder)
- Market Status: Check if markets are open/closed
- Health Monitoring: API health checks and status monitoring
- Push Notifications: Get notified about order status via Pushbullet
- Auto-retry: Automatic token refresh and retry logic
- Python 3.8+ installed
- Docker installed (for containerized deployment)
- AWS CLI configured with your credentials
-
Clone and setup:
git clone <your-repo> cd Groww
-
Create environment file:
cp .env.example .env # Edit .env with your actual credentials -
Start development server:
./run-local.sh
-
Access your API:
- API: http://localhost:8000
- Documentation: http://localhost:8000/docs
- Health Check: http://localhost:8000/health
Use the interactive development menu:
./dev-workflow.shThis provides options for:
- π Starting local server
- π§ͺ Running API tests
- π³ Building Docker images
- π¦ Deploying to Lambda
- π Viewing logs
- π Updating environment variables
Start local server:
./run-local.shTest API endpoints:
./test-api.shBuild Docker image:
sudo docker build -t groww-trading-api:dev .GET /- Welcome messageGET /hello- Hello messageGET /health- Health checkGET /market-status- Market open/closed status
GET /quote/{ticker}- Get single stock quotePOST /quotes- Get multiple stock quotes
POST /order- Place trading orderGET /orders_list- Get order historyPOST /stop-loss/sell- Place stop loss sell orderPOST /gtt/buy- Place GTT buy order
POST /gtt/order- Place GTT order (buy/sell)PUT /gtt/order- Modify existing GTT orderGET /gtt/orders- Get all GTT ordersDELETE /gtt/order/{gtt_id}- Cancel GTT order
GET /portfolio- Get portfolio holdings (placeholder)
POST /test-notification- Test push notifications
Get stock quote:
curl http://localhost:8000/quote/SBINGet multiple quotes:
curl -X POST http://localhost:8000/quotes \
-H "Content-Type: application/json" \
-d '["SBIN", "RELIANCE", "TCS"]'Place order:
curl -X POST http://localhost:8000/order \
-H "Content-Type: application/json" \
-d '{
"ticker": "SBIN",
"quantity": 1,
"transaction_type": "BUY",
"price": 800
}'Place stop loss sell order:
curl -X POST http://localhost:8000/stop-loss/sell \
-H "Content-Type: application/json" \
-d '{
"ticker": "SBIN",
"quantity": 10,
"stop_loss_price": 750,
"limit_price": 745
}'Place GTT buy order:
curl -X POST http://localhost:8000/gtt/buy \
-H "Content-Type: application/json" \
-d '{
"ticker": "RELIANCE",
"quantity": 5,
"transaction_type": "BUY",
"trigger_price": 2800,
"limit_price": 2805
}'Get GTT orders:
curl http://localhost:8000/gtt/ordersThis deployment method uses Docker containers to deploy to AWS Lambda, which is ideal for applications larger than 50MB.
- Install Docker and ensure it's running
- Install the AWS CLI and configure it with your credentials:
pip install awscli aws configure
-
Create your
.envfile with required environment variables:API_KEY=your_api_key_here TOTP_SECRET=your_totp_secret_here PUSH_TOKEN=your_push_token_here -
Deploy to Lambda:
./deploy-lambda.sh -
Set environment variables:
./set-env-vars.sh
-
View function logs:
aws logs tail /aws/lambda/groww-trading-api --follow --region us-east-1 -
Update function code (after making changes):
./deploy-lambda.sh -
Delete the function:
aws lambda delete-function --function-name groww-trading-api --region us-east-1
-
Install the AWS CLI and configure it with your credentials:
pip install awscli aws configure -
Install the Elastic Beanstalk CLI:
pip install awsebcli
-
Initialize your Elastic Beanstalk application (first time only):
eb init -p python-3.8 groww-api --region <your-region> -
Create an environment (first time only):
eb create groww-api-env -
Set up environment variables in the Elastic Beanstalk console:
- API_KEY
- TOTP_SECRET
- PUSH_TOKEN
-
Deploy your application:
eb deploy
Alternatively, you can use the provided deploy.sh script:
./deploy.sh
-
To view the application status:
eb status -
To view application logs:
eb logs -
To open the application in a browser:
eb open -
To terminate the environment when no longer needed:
eb terminate groww-api-env
Create a .env file with:
API_KEY=your_groww_api_key
TOTP_SECRET=your_totp_secret_key
PUSH_TOKEN=your_pushbullet_token- Local Development: Uses
uvicornwith auto-reload - Lambda Deployment: Uses
mangumadapter for serverless - Environment: Automatically detected based on runtime
./test-api.shVisit http://localhost:8000/docs for interactive API documentation.
# Install hey (HTTP load testing tool)
sudo apt install hey
# Test with 100 requests, 10 concurrent
hey -n 100 -c 10 http://localhost:8000/health- Server logs appear in terminal
- Access logs via uvicorn output
# View real-time logs
aws logs tail /aws/lambda/groww-trading-api --follow --region us-east-1
# View specific time range
aws logs tail /aws/lambda/groww-trading-api --since 1h --region us-east-1- Environment variables stored securely in Lambda
- API keys never logged or exposed
- HTTPS enforced in production
- Input validation on all endpoints
- Pay only for actual usage
- Automatic scaling
- No idle costs
- ~85-95% cost savings vs traditional servers
- 1,000 requests/month: ~$0.04
- 10,000 requests/month: ~$0.40
- 100,000 requests/month: ~$4.00
Token Authentication Errors:
- Check your API_KEY and TOTP_SECRET
- Ensure TOTP is generating correctly
- Token auto-refreshes on failure
Local Server Won't Start:
# Check if port 8000 is in use
lsof -i :8000
# Kill existing processes
pkill -f uvicornDocker Build Issues:
# Clean Docker cache
sudo docker system prune -f
# Rebuild without cache
sudo docker build --no-cache -t groww-trading-api:dev .Lambda Deployment Issues:
# Check AWS credentials
aws sts get-caller-identity
# Verify ECR permissions
aws ecr describe-repositories --region us-east-1- Add endpoint to
app.py - Test locally with
./run-local.sh - Test with
./test-api.sh - Deploy with
./deploy-lambda.sh
βββ app.py # Main FastAPI application
βββ lambda_handler.py # Lambda adapter
βββ requirements.txt # Python dependencies
βββ Dockerfile # Container definition
βββ .env # Environment variables (local)
βββ run-local.sh # Local development server
βββ test-api.sh # API testing script
βββ dev-workflow.sh # Development workflow menu
βββ deploy-lambda.sh # Lambda deployment
βββ set-env-vars.sh # Environment variable setup
- Fork the repository
- Create a feature branch
- Test locally with
./dev-workflow.sh - Submit a pull request
This project is licensed under the MIT License.