Skip to content

eaglesaigon/Tradesecbot

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

204 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

🎯 XRZ Intelligence Agency - Real-time Financial Intelligence System

Overview

Advanced real-time financial intelligence platform integrating Polygon.io WebSocket for live stock data with Telegram Bot API for command and control operations. Designed with intelligence agency aesthetics and professional-grade monitoring capabilities.

Features

πŸ”΄ Real-time Stock Monitoring

  • Live Data Stream: Polygon.io WebSocket integration for real-time stock trades
  • Multi-Symbol Tracking: Monitor multiple stocks simultaneously (AAPL, MSFT, GOOGL, etc.)
  • Anomaly Detection: Automatic detection of volume spikes and price movements
  • Intelligence Reports: Military-style console logging and reporting

πŸ€– Telegram Bot Integration

  • Command Interface: Full bot command system for remote monitoring
  • Multi-Agent Support: Multiple Telegram users can connect simultaneously
  • Real-time Alerts: Automatic notifications for anomalous trading activity
  • Status Reporting: Comprehensive system status and portfolio reports

🌐 Web Dashboard

  • Live Intelligence Feed: Real-time web interface with agency styling
  • System Monitoring: Connection status, uptime, and trade statistics
  • Dark Theme: Professional intelligence agency aesthetic
  • Auto-refresh: Live updates every 5 seconds

Installation & Setup

1. Prerequisites

  • Node.js 16+ installed
  • Polygon.io API key (provided: UWxatfnpZfpPMIrFhcmU3rjC1OOYSIqU)
  • Telegram Bot Token (configured: existing @frbrssbot)

2. Installation

# Install dependencies
npm install @polygon.io/client-js node-telegram-bot-api dotenv ws express

# Copy environment configuration
cp .env.example .env

# Run the XRZ Intelligence System
node xrz-intelligence.js

3. Environment Configuration

Edit .env file:

POLYGON_API_KEY=UWxatfnpZfpPMIrFhcmU3rjC1OOYSIqU
TELEGRAM_TOKEN=7988577153:AAGpgt3Rjuu3-1bnlHXdeHiwJQd4DiAhEg0
TELEGRAM_CHAT_ID=6598842264
PORT=3000

Telegram Bot Commands

Basic Operations

  • /start - Initialize agent connection and view welcome message
  • /help - Display complete command reference
  • /status - Get comprehensive system status report

Monitoring Commands

  • /monitor AAPL - Start tracking Apple stock for anomalies
  • /monitor MSFT - Start tracking Microsoft stock
  • /unmonitor AAPL - Stop tracking Apple stock
  • /portfolio - View all currently monitored stocks with latest prices

Intelligence Commands

  • /alerts - View recent anomalous trading activity
  • /status - Detailed system health and statistics

Supported Stock Symbols

  • AAPL - Apple Inc.
  • MSFT - Microsoft Corporation
  • GOOGL - Alphabet Inc.
  • TSLA - Tesla Inc.
  • AMZN - Amazon.com Inc.
  • NVDA - NVIDIA Corporation
  • META - Meta Platforms Inc.

Web Interface

Access the intelligence dashboard at: http://localhost:3000

Dashboard Features

  • System Status: Connection state, uptime, trade statistics
  • Active Monitors: Currently tracked stocks and agent count
  • Anomaly Detection: Alert counts and last update timestamps
  • Live Feed: Real-time trade data stream with timestamps
  • Auto-refresh: Updates every 5 seconds

Anomaly Detection

Volume Spike Detection

  • Triggers when trade volume exceeds 5x average volume
  • Alert Type: VOLUME_SPIKE
  • Severity: HIGH
  • Example: "🚨 VOLUME ANOMALY: AAPL traded 150,000 shares (7x normal volume)"

Price Movement Detection

  • Triggers on price changes exceeding 2% from recent average
  • Alert Type: PRICE_MOVEMENT
  • Severity: MEDIUM
  • Example: "πŸ“ˆ PRICE ALERT: MSFT at $285.50 (2.45% change)"

System Architecture

Core Components

  1. WebSocket Client: Polygon.io connection with auto-reconnection
  2. Telegram Bot: Command processing and alert broadcasting
  3. Web Server: Express.js dashboard with real-time updates
  4. Intelligence Engine: Anomaly detection and analysis
  5. State Management: In-memory tracking of trades and alerts

Error Handling

  • Auto-reconnection: Up to 10 attempts with exponential backoff
  • Graceful Degradation: System continues operating during temporary disconnections
  • Error Logging: Comprehensive error tracking and reporting
  • Recovery Protocols: Automatic subscription restoration after reconnection

Usage Examples

Starting the System

node xrz-intelligence.js

Telegram Interaction

Agent: /start
Bot: 🎯 XRZ Intelligence Agency Welcome...

Agent: /monitor AAPL
Bot: πŸ“‘ [XRZ-MONITOR] Now tracking AAPL for intelligence gathering

Agent: /status
Bot: πŸ“Š XRZ Intelligence System Status
     πŸ”— Connection: CONNECTED
     ⏱️ Uptime: 2h 15m
     πŸ“ˆ Total Trades: 1,847

Console Output

πŸš€ [XRZ-INIT] Initializing XRZ Intelligence Agency Financial Monitor...
βœ… [XRZ-CONNECTED] WebSocket established with Polygon.io Intelligence Network
πŸ“‘ [XRZ-MONITOR] Now tracking AAPL for anomalous trading activity
πŸ“Š [XRZ-INTEL] AAPL: $175.23 | Volume: 1,250 | 14:32:15
🚨 [XRZ-ALERT] VOLUME ANOMALY: AAPL traded 45,000 shares (6x normal volume)

Technical Specifications

Dependencies

  • @polygon.io/client-js: WebSocket client for Polygon.io API
  • node-telegram-bot-api: Telegram Bot API integration
  • express: Web server for dashboard interface
  • dotenv: Environment variable management
  • ws: WebSocket protocol support

Performance

  • Real-time Processing: Sub-second trade data processing
  • Memory Efficient: Circular buffer for trade history (100 trades max)
  • Scalable: Supports unlimited Telegram agents
  • Robust: Auto-recovery from network failures

Security

  • API Key Protection: Environment variable configuration
  • Access Control: Telegram bot token authentication
  • Data Sanitization: Input validation and error handling
  • Secure Communications: HTTPS/WSS protocol usage

Troubleshooting

Common Issues

WebSocket Connection Failed

❌ [XRZ-ERROR] WebSocket error: Connection refused

Solution: Verify Polygon.io API key and network connectivity

Telegram Bot Not Responding

❌ [XRZ-TELEGRAM] Failed to send to chat: 401 Unauthorized

Solution: Verify bot token and ensure bot is added to target chats

No Trade Data Received

πŸ“‘ [XRZ-MONITOR] Now tracking AAPL for anomalous trading activity

Solution: Ensure markets are open and symbol is valid

Debug Mode

Enable verbose logging by setting:

NODE_ENV=development

Production Deployment

Replit Deployment

  1. Upload all files to Replit project
  2. Configure environment variables in Replit Secrets
  3. Use "Run" button or configure custom run command: node xrz-intelligence.js
  4. Access web interface via Replit's provided URL

Custom Deployment

# Install PM2 for process management
npm install -g pm2

# Start with PM2
pm2 start xrz-intelligence.js --name "xrz-intelligence"

# Monitor
pm2 status
pm2 logs xrz-intelligence

API Reference

Internal Status API

  • GET /api/status: System status JSON
    {
      "connectionStatus": "CONNECTED",
      "totalTrades": 1847,
      "uptime": 8100,
      "lastUpdate": "2025-08-18T07:15:30.000Z",
      "activeSymbols": ["AAPL", "MSFT", "GOOGL"],
      "telegramChats": 3,
      "anomalies": 12
    }

License

This project is for educational and research purposes. Ensure compliance with Polygon.io terms of service and Telegram Bot API guidelines.

Support

For technical issues or feature requests, contact the development team or refer to the official documentation:

Releases

No releases published

Packages

 
 
 

Contributors