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 🚀