This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
Use the Makefile for all development tasks:
make dev- Start development server with Air live reloadmake run- Run the main application directlymake test- Run all testsmake test-cover- Run tests with coverage reportmake lint- Run golangci-lint for code qualitymake fmt- Format code with gofmtmake vet- Run go vetmake check- Run all code quality checks (fmt, vet, lint)make build- Build the application to ./bin/make generate-ent- Generate Ent ORM code from schema
For testing configuration: go run cmd/test-config/main.go
MarketStream is a free self-hosted real-time stock data platform that provides REST API access to TradingView's WebSocket data feeds.
- Configuration Layer (
internal/config/) - Viper-based config with YAML, env vars, and CLI flags - HTTP Layer (
internal/handler/) - Fiber-based REST API handlers - Service Layer (
internal/service/) - Business logic for TradingView integration - Database Layer (
ent/) - PostgreSQL with Ent ORM for data persistence - WebSocket Client - Uses
github.com/iiiyu/tradingview-ws-clientfor real-time data
- HTTP API receives symbol subscription requests
- Service layer manages TradingView WebSocket connections
- Real-time quotes cached in Ristretto cache
- Historical candle data persisted to PostgreSQL
- Technical indicators calculated and stored for analysis
- Symbol: Exchange metadata and symbol information
- Candle: OHLCV historical data with multiple timeframes
- ActiveSession: Tracks active WebSocket subscriptions
- StudySession: Groups technical indicators for analysis
- Indicator: Individual technical analysis indicators
- IndicatorData: Time-series calculated values
Required environment variables:
TRADINGVIEW_DEVICE_TOKEN- TradingView device tokenTRADINGVIEW_SESSION_ID- TradingView session IDTRADINGVIEW_SESSION_SIGN- TradingView session signatureDB_HOST,DB_USER,DB_PASSWORD,DB_NAME- PostgreSQL connection
Configuration hierarchy: CLI flags → env vars → config.yaml → defaults
- Structured logging: Use
slogwith JSON format - Error handling: Return errors with context, avoid panics
- Database: Use Ent ORM with proper migrations
- HTTP: Use Fiber framework with proper error handling middleware
- Dependencies: All managed through go.mod, use
make deps
The service supports 10+ technical indicators including RSI, MACD, Bollinger Bands, Moving Averages, and more. See docs/INDICATORS_API.md for complete API documentation.
cmd/app/main.go- Main HTTP servicecmd/example/main.go- Example WebSocket client usagecmd/test-config/main.go- Configuration validation tool
- Copy
config.example.yamltoconfig.yaml - Set required environment variables
- Run
make setupto install development tools - Use
make devfor development with live reload