A high-performance, real-time financial market data processing pipeline built with Go. This system ingests, normalizes, analyzes, and serves financial market data with comprehensive validation, persistent storage, and secure authentication.
- Real-time Data Ingestion: WebSocket and HTTP endpoints for market data feeds
- Data Validation & Sanomalization: Comprehensive input validation and data cleaning
- PostgreSQL Integration: Persistent storage with connection pooling and migrations
- JWT Authentication: Secure role-based access control
- Anomaly Detection: Real-time detection of market anomalies using statistical analysis
- Redis Streams: High-performance message queuing and caching
- GraphQL API: Flexible data querying with real-time subscriptions
- Prometheus Metrics: Comprehensive monitoring and observability
- Docker Support: Containerized deployment
- Health Checks: Built-in health monitoring and readiness probes
- Language: Go 1.21+
- API: GraphQL (gqlgen), REST (net/http, gorilla/mux)
- Database: PostgreSQL (lib/pq)
- Cache & Messaging: Redis Streams (go-redis)
- Authentication: JWT (golang-jwt), RSA keys
- WebSockets: gorilla/websocket
- Validation: go-playground/validator
- Monitoring: Prometheus (client_golang)
- Logging: Uber Zap
- Containerization: Docker, Docker Compose
- Other: Make, OpenSSL (for key generation)
โโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโ
โ Ingest โโโโโถโ Normalize โโโโโถโ Cache/Pub โโโโโถโ API โ
โ Service โ โ Service โ โ Service โ โ Service โ
โโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโ
โ โ โ โ
โผ โผ โผ โผ
โโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโ
โ Redis โ โ PostgreSQL โ โ Redis โ โ GraphQL โ
โ Streams โ โ Database โ โ Pub/Sub โ โ Endpoint โ
โโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโ
- Ingest Service: Receives raw market data from various sources
- Normalize Service: Cleans and standardizes data format
- Cache/Pub Service: Manages Redis caching and pub/sub messaging
- Anomaly Detection: Identifies statistical anomalies in price movements
- API Service: Provides REST and GraphQL endpoints
- Archival Service: Long-term data storage and backup
Before running this project, ensure you have the following installed:
- Go 1.21+: Download Go
- PostgreSQL 13+: Download PostgreSQL
- Redis 6+: Download Redis
- Docker (optional): Download Docker
git clone https://github.com/yourusername/fin_line.git
cd fin_linemacOS (using Homebrew):
brew install postgresql
brew services start postgresqlUbuntu/Debian:
sudo apt update
sudo apt install postgresql postgresql-contrib
sudo systemctl start postgresql
sudo systemctl enable postgresqlWindows: Download and install from PostgreSQL official website
-- Connect to PostgreSQL as superuser
sudo -u postgres psql
-- Create database and user
CREATE DATABASE fin_line;
CREATE USER fin_line_user WITH PASSWORD 'your_secure_password';
GRANT ALL PRIVILEGES ON DATABASE fin_line TO fin_line_user;
ALTER USER fin_line_user CREATEDB;
\qmacOS (using Homebrew):
brew install redis
brew services start redisUbuntu/Debian:
sudo apt install redis-server
sudo systemctl start redis-server
sudo systemctl enable redis-serverWindows: Download and install from Redis official website
Generate RSA key pair for JWT authentication:
# Create keys directory
mkdir -p keys
# Generate private key
openssl genrsa -out keys/private.pem 2048
# Generate public key
openssl rsa -in keys/private.pem -pubout -out keys/public.pem
# Set proper permissions
chmod 600 keys/private.pem
chmod 644 keys/public.pemCreate a .env file in the project root:
# Database Configuration
export DB_HOST=localhost
export DB_PORT=5432
export DB_USER=fin_line_user
export DB_PASSWORD=your_secure_password
export DB_NAME=fin_line
export DB_SSLMODE=disable
export DB_MAX_OPEN_CONNS=25
export DB_MAX_IDLE_CONNS=5
export DB_CONN_MAX_LIFETIME=5m
export DB_CONN_MAX_IDLE_TIME=5m
# Redis Configuration
export REDIS_URL=redis://localhost:6379
# JWT Configuration
export JWT_PRIVATE_KEY_PATH=keys/private.pem
export JWT_PUBLIC_KEY_PATH=keys/public.pem
export JWT_ISSUER=fin-line
export JWT_AUDIENCE=fin-line-api
export JWT_EXPIRATION=24h
# Application Configuration
export ENVIRONMENT=development
export LOG_LEVEL=info
export API_PORT=8080
# Service Configuration
export INGEST_PORT=8081
export NORMALIZE_PORT=8082
export CACHEPUB_PORT=8083
export ANOMALY_PORT=8084
export ARCHIVAL_PORT=8085# Download Go modules
go mod download
# Verify dependencies
go mod verifyThe database migrations will run automatically when you start the API service, but you can also run them manually:
# Build the application
go build -o bin/api cmd/api/main.go
# Run migrations manually (optional)
./bin/api --migrate-only# Start all services in development mode
make dev# Terminal 1: Start API service
go run cmd/api/main.go
# Terminal 2: Start Ingest service
go run cmd/ingest/main.go
# Terminal 3: Start Normalize service
go run cmd/normalize/main.go
# Terminal 4: Start Cache/Pub service
go run cmd/cachepub/main.go
# Terminal 5: Start Anomaly Detection service
go run cmd/anomaly/main.go
# Terminal 6: Start Archival service
go run cmd/archival/main.go# Build all services
make build
# Run with production configuration
ENVIRONMENT=production ./bin/api
ENVIRONMENT=production ./bin/ingest
ENVIRONMENT=production ./bin/normalize
ENVIRONMENT=production ./bin/cachepub
ENVIRONMENT=production ./bin/anomaly
ENVIRONMENT=production ./bin/archival# Build Docker images
docker-compose build
# Start all services
docker-compose up -d
# View logs
docker-compose logs -f
# Stop services
docker-compose downGET /health- Health check endpointGET /ready- Readiness check endpointGET /metrics- Prometheus metrics
GET /api/v1/quotes/latest- Get latest quotes for all tickersGET /api/v1/quotes/{ticker}- Get quotes for specific tickerGET /api/v1/stats- Get system statistics
GET /api/v1/quotes/sector/{sector}- Get quotes by sectorGET /api/v1/quotes/{ticker}/history- Get quote historyGET /api/v1/anomalies- Get detected anomaliesGET /api/v1/anomalies/{ticker}- Get anomalies for specific ticker
GET /api/v1/admin/raw-events- Get raw eventsGET /api/v1/admin/raw-events/source/{source}- Get raw events by sourceGET /api/v1/admin/migrations/status- Get migration status
POST /graphql- GraphQL endpoint with subscriptions
# Example: Generate a token (you'll need to implement a login endpoint)
curl -X POST http://localhost:8080/api/v1/auth/login \
-H "Content-Type: application/json" \
-d '{"username": "user", "password": "password"}'# Include token in Authorization header
curl -H "Authorization: Bearer YOUR_JWT_TOKEN" \
http://localhost:8080/api/v1/quotes/sector/technology# Run all tests
go test ./...
# Run tests with coverage
go test -cover ./...
# Run tests with verbose output
go test -v ./...# Test validation package
go test ./pkg/validation
# Test database package
go test ./pkg/database
# Test authentication package
go test ./pkg/auth# Run integration tests (requires running services)
make test-integrationAccess metrics at http://localhost:8080/metrics
Key metrics include:
- Request duration and count
- Database operation performance
- Redis operation performance
- Authentication metrics
- System resource usage
# Check API health
curl http://localhost:8080/health
# Check readiness
curl http://localhost:8080/readyLogs are written to stdout/stderr and can be configured via environment variables:
export LOG_LEVEL=debug # debug, info, warn, error
export LOG_FORMAT=json # json, console| Variable | Description | Default |
|---|---|---|
ENVIRONMENT |
Application environment | development |
LOG_LEVEL |
Logging level | info |
API_PORT |
API service port | 8080 |
DB_HOST |
Database host | localhost |
DB_PORT |
Database port | 5432 |
REDIS_URL |
Redis connection URL | redis://localhost:6379 |
JWT_EXPIRATION |
JWT token expiration | 24h |
The application supports configuration via:
- Environment variables (highest priority)
- Configuration files (YAML/JSON)
- Default values (lowest priority)
# Check PostgreSQL status
sudo systemctl status postgresql
# Check database connectivity
psql -h localhost -U fin_line_user -d fin_line
# Verify environment variables
echo $DB_HOST $DB_PORT $DB_USER $DB_NAME# Check Redis status
sudo systemctl status redis-server
# Test Redis connectivity
redis-cli ping
# Check Redis logs
sudo journalctl -u redis-server# Verify key files exist
ls -la keys/
# Check key permissions
chmod 600 keys/private.pem
chmod 644 keys/public.pem
# Test key generation
openssl rsa -in keys/private.pem -check# Check if ports are in use
netstat -tulpn | grep :8080
lsof -i :8080
# Kill process using port
sudo kill -9 <PID>Access the GraphQL playground at http://localhost:8080/graphql/playground
# Get latest quotes
query {
latestQuotes {
ticker
price
timestamp
sector
}
}
# Get quotes for specific ticker
query {
quotes(ticker: "AAPL", limit: 10) {
ticker
price
timestamp
}
}
# Get anomalies
query {
anomalies(minZScore: 2.0, limit: 10) {
ticker
price
zScore
timestamp
}
}- Anomaly Detection Improvements: Implement more sophisticated ML models (LSTM, Isolation Forest)
- Price Prediction: Add price forecasting capabilities using time series analysis
- Sentiment Analysis: Integrate news and social media sentiment analysis
- Pattern Recognition: Identify technical analysis patterns automatically
- Multiple Data Sources: Integrate additional market data providers (Alpha Vantage, IEX Cloud, Polygon)
- Fundamental Data: Add company fundamentals, earnings, and financial ratios
- News Integration: Real-time news feed integration with sentiment scoring
- Social Media: Twitter and Reddit sentiment analysis for crypto assets
- Streaming Analytics: Apache Kafka integration for real-time data processing
- Complex Event Processing: Detect complex market events and patterns
- Risk Management: Real-time risk assessment and alerting
- Portfolio Analytics: Portfolio performance tracking and optimization
- Backtesting Engine: Historical strategy backtesting capabilities
- Algorithmic Trading: Basic algorithmic trading signal generation
- Market Microstructure: Order book analysis and market depth
- Cross-Asset Correlation: Multi-asset correlation analysis
- Horizontal Scaling: Kubernetes deployment with auto-scaling
- Database Sharding: Implement database sharding for high-volume data
- Caching Layer: Redis Cluster for distributed caching
- Load Balancing: Advanced load balancing and failover
- Multi-factor Authentication: TOTP and hardware key support
- Audit Logging: Comprehensive audit trail for compliance
- Data Encryption: End-to-end encryption for sensitive data
- SOC 2 Compliance: Security and compliance certifications
- WebSocket API: Real-time streaming API for live data
- REST API v2: Enhanced REST API with pagination and filtering
- GraphQL Subscriptions: Real-time GraphQL subscriptions
- Webhook Support: Configurable webhooks for events
- Multi-tenancy: Support for multiple organizations
- Role-based Access Control: Advanced permission system
- API Key Management: Self-service API key generation
- Usage Analytics: API usage tracking and billing
- Third-party Integrations: Trading platforms, CRM systems
- Plugin System: Extensible plugin architecture
- API Marketplace: Public API marketplace for data consumers
- Developer Portal: Comprehensive developer documentation
- Custom Indicators: User-defined technical indicators
- Strategy Builder: Visual strategy building interface
- Risk Analytics: Advanced risk modeling and stress testing
- Performance Attribution: Detailed performance analysis
- Backend: Go, PostgreSQL, Redis
- API: REST, GraphQL
- Authentication: JWT
- Monitoring: Prometheus, Grafana
- Message Queue: Apache Kafka
- Stream Processing: Apache Flink
- Machine Learning: Python ML services
- Frontend: React/TypeScript dashboard
- Mobile: React Native mobile app
-
Immediate (Next Sprint)
- Fix any critical bugs
- Add comprehensive test coverage
- Implement proper error handling
- Add API rate limiting
-
Short-term (Next Month)
- Add more data sources
- Implement caching strategies
- Add comprehensive logging
- Create deployment automation
-
Medium-term (Next Quarter)
- Machine learning integration
- Advanced analytics features
- Performance optimization
- Security hardening
-
Long-term (Next Year)
- Enterprise features
- Platform capabilities
- Advanced integrations
- Global expansion
We welcome contributions! Please see our Contributing Guide for details.
# Fork and clone the repository
git clone https://github.com/yourusername/fin_line.git
cd fin_line
# Create a feature branch
git checkout -b feature/your-feature-name
# Make your changes
# Add tests for new functionality
# Update documentation
# Commit your changes
git commit -m "Add your feature description"
# Push to your fork
git push origin feature/your-feature-name
# Create a pull requestThis project is licensed under the MIT License - see the LICENSE file for details.
- Documentation: Implementation Guide
- Issues: GitHub Issues
- Discussions: GitHub Discussions
- Email: support@fin-line.com
- Built with Go
- Database powered by PostgreSQL
- Caching with Redis
- Monitoring with Prometheus
- Authentication with JWT
Fin-Line - Empowering financial data analysis with real-time insights and advanced analytics.