Real-time stock trading signals with AI chat assistance, built with dependency injection architecture for seamless switching between mock and real data sources.
- Node.js 18+
- npm or yarn
# Clone the repository
git clone <repository-url>
cd stock-trading-assistant
# Install all workspace dependencies
npm install
# Build all packages (common-utils β backend β frontend)
npm run buildnpm run start:backend- Uses mock data for development
- Signals every 4 seconds
- No API keys required
npm run start:backend:demo- Fast mock data every 2 seconds
- Perfect for demonstrations
- Realistic trading signals with events
# Set your API key
export BENZINGA_API_KEY=your_api_key_here
npm run start:backend:real- Uses real Benzinga API data
- Requires valid API key
- Live market data and events
npm run start:frontend- Opens at http://localhost:3000
- Connects to WebSocket server at ws://localhost:8080
- Real-time signal display and chat interface
The application uses a clean monorepo architecture with three main packages:
stock-trading-assistant/
βββ common-utils/ # Shared types, interfaces, models
βββ backend/ # WebSocket server, data sources, business logic
βββ frontend/ # React UI, WebSocket client, user interface
The backend uses a complete dependency injection architecture:
Environment Config β DI Container β Factory β Data Source
β
WebSocket Clients β WebSocket Server β Signal Service
- Common Utils: Shared Signal types, interfaces (ISignalDataSource, IWebSocketServer)
- Backend: WebSocket server, data sources (Mock/Benzinga), dependency injection
- Frontend: React components, WebSocket client, real-time UI
- Factory Pattern: Creates appropriate implementations based on configuration
{
"type": "subscribe",
"symbol": "AAPL"
}{
"type": "unsubscribe",
"symbol": "AAPL"
}{
"type": "signal",
"data": {
"symbol": "AAPL",
"recommendation": "BUY",
"confidence": 0.87,
"reasoning": "Earnings beat expectations by 4.7%",
"timestamp": "2024-01-15T16:30:00.000Z",
"price": 185.50,
"change": 2.30,
"changePercent": 1.26,
"upcomingEvent": {
"type": "EARNINGS",
"date": "2024-01-20T21:30:00.000Z",
"description": "Q4 2024 Earnings Call",
"importance": "HIGH"
}
}
}| Variable | Description | Default | Example |
|---|---|---|---|
SIGNAL_DATA_MODE |
Data source mode | mock |
mock, real, hybrid |
WS_PORT |
WebSocket server port | 8080 |
8080 |
MOCK_DATA_INTERVAL |
Mock signal interval (ms) | 4000 |
2000 |
ENABLE_EVENTS |
Include upcoming events | true |
true, false |
BENZINGA_API_KEY |
Benzinga API key | - | your_api_key |
FOCUS_STOCKS |
Priority stocks | AAPL,TSLA,NVDA |
AAPL,MSFT,GOOGL |
# Custom startup with specific settings
./scripts/start-server.sh --mode mock --port 8080 --interval 2000
# Real data mode with custom port
BENZINGA_API_KEY=your_key ./scripts/start-server.sh --mode real --port 9000
# Fast testing mode without events
./scripts/start-server.sh --mode mock --interval 1000 --no-eventsnode demo-di-system.jsThis will:
- Start the server with fast mock data
- Connect a WebSocket client
- Subscribe to AAPL, TSLA, NVDA
- Display 5 realistic trading signals
- Demonstrate the complete system flow
// Browser console or Node.js
const ws = new WebSocket('ws://localhost:8080');
ws.onopen = () => {
console.log('Connected!');
ws.send(JSON.stringify({
type: 'subscribe',
symbol: 'AAPL'
}));
};
ws.onmessage = (event) => {
const message = JSON.parse(event.data);
console.log('Received:', message);
};npm test| Script | Description |
|---|---|
npm run start:dev |
Development mode with mock data |
npm run start:demo |
Demo mode with fast mock data |
npm run start:real |
Production mode with real data |
npm run start:fast |
Testing mode with very fast mock data |
npm run build |
Build TypeScript to JavaScript |
npm run test |
Run unit tests |
npm run lint |
Run ESLint |
src/
βββ backend/ # Server-side code
β βββ di/ # Dependency injection
β βββ factories/ # Factory implementations
β βββ services/ # Business logic services
β βββ websocket/ # WebSocket server
β βββ server.ts # Main entry point
βββ frontend/ # React frontend
β βββ src/
β β βββ components/ # React components
β β βββ hooks/ # Custom hooks
β β βββ pages/ # Page components
β βββ public/
βββ services/ # Shared services
βββ data-sources/ # Data source implementations
- Implement the Interface
export class YahooFinanceDataSource implements ISignalDataSource {
// Implement all interface methods
}- Update the Factory
// In DataSourceFactory.ts
case 'yahoo':
return new YahooFinanceDataSource(config);- Configure Environment
SIGNAL_DATA_MODE=yahoo YAHOO_API_KEY=your_key npm run start:real- β Real-time WebSocket signal streaming
- β Mock data source with realistic signals
- β Dependency injection architecture
- β React frontend with live signal display
- β Focus stock selection (AAPL, TSLA, NVDA, etc.)
- β Connection status monitoring
- β Signal history and performance tracking
- π§ Enhanced signal reasoning (6-second comprehensive analysis)
- π§ Sentiment analysis integration
- π§ Technical indicators (RSI, moving averages)
- π§ Data reconciliation across sources
- π§ Interactive AI chat system
- π§ AWS AppSync integration
- π§ Persistent chat history
- π§ Context-aware responses
- DI_ARCHITECTURE.md - Detailed dependency injection architecture
- IMPLEMENTATION_SUMMARY.md - Implementation summary and benefits
- DEMO_GUIDE.md - Demo and testing guide
- .kiro/specs/stock-trading-assistant/ - Complete specification
- Fork the repository
- Create a feature branch
- Make your changes
- Add tests
- Submit a pull request
MIT License - see LICENSE file for details
For issues and questions:
- Check the documentation files
- Run the demo script to verify setup
- Check WebSocket connection at ws://localhost:8080
- Verify environment variables are set correctly
Built with dependency injection for clean, testable, and maintainable code π