Skip to content

Repository files navigation

Stock Trading Assistant

Real-time stock trading signals with AI chat assistance, built with dependency injection architecture for seamless switching between mock and real data sources.

πŸš€ Quick Start

Prerequisites

  • Node.js 18+
  • npm or yarn

Installation

# 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 build

Start the Server

Development Mode (Mock Data)

npm run start:backend
  • Uses mock data for development
  • Signals every 4 seconds
  • No API keys required

Demo Mode (Fast Mock Data)

npm run start:backend:demo
  • Fast mock data every 2 seconds
  • Perfect for demonstrations
  • Realistic trading signals with events

Production Mode (Real Data)

# 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

Start the Frontend

npm run start:frontend
  • Opens at http://localhost:3000
  • Connects to WebSocket server at ws://localhost:8080
  • Real-time signal display and chat interface

πŸ—οΈ Architecture

Monorepo Structure

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

Dependency Injection System

The backend uses a complete dependency injection architecture:

Environment Config β†’ DI Container β†’ Factory β†’ Data Source
                                         ↓
WebSocket Clients ← WebSocket Server ← Signal Service

Key Components

  • 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

πŸ“‘ WebSocket API

Client β†’ Server Messages

Subscribe to Stock

{
  "type": "subscribe",
  "symbol": "AAPL"
}

Unsubscribe from Stock

{
  "type": "unsubscribe",
  "symbol": "AAPL"
}

Server β†’ Client Messages

Trading Signal

{
  "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"
    }
  }
}

βš™οΈ Configuration

Environment Variables

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

Advanced Configuration

# 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-events

πŸ§ͺ Testing

Run the Complete Demo

node demo-di-system.js

This 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

Manual WebSocket Testing

// 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);
};

Unit Tests

npm test

πŸ“Š Available NPM Scripts

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

πŸ”§ Development

Project Structure

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

Adding New Data Sources

  1. Implement the Interface
export class YahooFinanceDataSource implements ISignalDataSource {
  // Implement all interface methods
}
  1. Update the Factory
// In DataSourceFactory.ts
case 'yahoo':
  return new YahooFinanceDataSource(config);
  1. Configure Environment
SIGNAL_DATA_MODE=yahoo YAHOO_API_KEY=your_key npm run start:real

🎯 Features

Phase 1 (Completed)

  • βœ… 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

Phase 2 (Planned)

  • 🚧 Enhanced signal reasoning (6-second comprehensive analysis)
  • 🚧 Sentiment analysis integration
  • 🚧 Technical indicators (RSI, moving averages)
  • 🚧 Data reconciliation across sources

Phase 3 (Planned)

  • 🚧 Interactive AI chat system
  • 🚧 AWS AppSync integration
  • 🚧 Persistent chat history
  • 🚧 Context-aware responses

πŸ“š Documentation

🀝 Contributing

  1. Fork the repository
  2. Create a feature branch
  3. Make your changes
  4. Add tests
  5. Submit a pull request

πŸ“„ License

MIT License - see LICENSE file for details

πŸ†˜ Support

For issues and questions:

  1. Check the documentation files
  2. Run the demo script to verify setup
  3. Check WebSocket connection at ws://localhost:8080
  4. Verify environment variables are set correctly

Built with dependency injection for clean, testable, and maintainable code πŸš€

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

Packages

Contributors

Languages