institutional-trader/backend/python_service
Deep Koluguri b86bfad73b changed port to 8010 2025-12-12 21:47:20 -05:00
..
__pycache__ initial commit 2025-12-12 12:13:06 -05:00
scripts initial commit 2025-12-12 12:13:06 -05:00
services initial commit 2025-12-12 12:13:06 -05:00
utils initial commit 2025-12-12 12:13:06 -05:00
COMPLETION_STATUS.md initial commit 2025-12-12 12:13:06 -05:00
MIGRATION_NOTES.md initial commit 2025-12-12 12:13:06 -05:00
README.md changed port to 8010 2025-12-12 21:47:20 -05:00
START_SERVICE.md changed port to 8010 2025-12-12 21:47:20 -05:00
TESTING.md changed port to 8010 2025-12-12 21:47:20 -05:00
db.py fixed python 2025-12-12 21:33:13 -05:00
main.py changed port to 8010 2025-12-12 21:47:20 -05:00
requirements.txt initial commit 2025-12-12 12:13:06 -05:00
start.bat changed port to 8010 2025-12-12 21:47:20 -05:00
start.sh changed port to 8010 2025-12-12 21:47:20 -05:00

README.md

Python Options Flow Processing Service

This service extracts complex SQL logic into Python/pandas for better maintainability and easier testing.

Architecture

  • FastAPI: Modern async web framework
  • pandas: Data processing and analytics
  • asyncpg: Async PostgreSQL driver
  • Replaces: Complex 593-line SQL queries with modular Python code

Setup

  1. Install dependencies:
cd backend/python_service
pip install -r requirements.txt
  1. Configure environment:
cp .env.example .env
# Edit .env with your database credentials
  1. Run the service:
python main.py
# Or with uvicorn:
uvicorn main:app --reload --port 8010

API Endpoints

GET /health

Health check endpoint

GET /api/options-flow

Get processed options flow data

Query Parameters:

  • start_date (optional): Start date (YYYY-MM-DD), defaults to yesterday
  • end_date (optional): End date (YYYY-MM-DD), defaults to today
  • min_premium (optional): Minimum premium filter, defaults to 80000
  • tol_pct (optional): Tape alignment tolerance, defaults to 0.20

Example:

curl http://localhost:8010/api/options-flow?start_date=2024-01-01&end_date=2024-01-02

GET /api/options-flow/stats

Get flow statistics

Query Parameters:

  • symbol (optional): Filter by symbol

Integration with Node.js

The Node.js API layer can call this service via HTTP:

const response = await fetch('http://localhost:8010/api/options-flow?start_date=2024-01-01');
const data = await response.json();

Benefits

  1. Maintainability: Complex SQL logic broken into Python functions
  2. Testability: Each processing step can be unit tested
  3. Flexibility: Easy to add new analytics or modify existing ones
  4. Performance: Can leverage pandas vectorization and parallel processing
  5. Debugging: Easier to debug Python code than complex SQL

Migration Path

  1. Python service created
  2. Node.js routes updated to call Python service
  3. Additional SQL scripts migrated
  4. Full testing and validation