Skip to content

CODE-FINANC/Forex

Repository files navigation

POPricePredictor

This project is an automated system for extracting real-time price data from the PO Finance website (demo mode), processing it into a CSV file, predicting future price trends (up/down) using advanced statistical models, and executing automated trades based on predictions. It's built for educational and research purposes only—do not use for real trading as it involves financial risk!

The system includes:

  • A Chrome Extension to scrape prices and execute trades.
  • A Flask server (Python) to store data and monitor predictions.
  • A machine learning predictor using models like Context Tree Weighting (CTW), N-grams, Pattern Recognition, and Variable Order Markov Chains for binary sequence prediction (0 for down, 1 for up).

Features

  • Real-time Data Extraction: Scrapes price data from https://po.finance/fa/cabinet/demo-quick-high-low/* every few seconds and sends it to a local server.
  • Data Processing: Compares prices every 30 seconds and saves binary results (0 or 1) to training_data.csv.
  • Prediction Models: Uses ensemble methods (CTW, N-gram, Patterns, Markov) to predict the next price movement with probability and confidence scores.
  • Automated Trading: Checks for new prediction signals every 500ms and executes "buy" (up) or "sell" (down) trades on the website.
  • Modular Storage: Saves model states in separate files for efficient loading/saving (e.g., trees, transitions, weights).
  • Real-time Monitoring: Watches for new data and predictions, with auto-save and checkpointing.
  • Evaluation Tools: Includes functions to evaluate model accuracy, log-loss, and confusion matrix.

Prerequisites

  • Python 3.12+ (with libraries: Flask, pandas, numpy, scikit-learn, scipy – install via pip install -r requirements.txt).
  • Google Chrome browser.
  • A local server setup (runs on http://localhost:5000).
  • Important: This is for demo mode only. Real trading may violate site terms and involves financial loss risk.

Installation

  1. Clone the Repository:

    git clone https://github.com/your-username/POPricePredictor.git
    cd POPricePredictor
    
  2. Install Python Dependencies: Create a requirements.txt file with:

    flask
    flask-cors
    pandas
    numpy
    scikit-learn
    scipy
    

    Then run:

    pip install -r requirements.txt
    
  3. Load Chrome Extension:

    • Go to chrome://extensions/ in Chrome.
    • Enable "Developer mode" (top right).
    • Click "Load unpacked" and select the folder containing manifest.json and content.js.
  4. Prepare Folders:

    • Create a models/ folder for model storage.
    • The system will generate training_data.csv and predictions.csv automatically.

Usage

  1. Run the Flask Server:

    python po_extractor.py
    

    This starts the server on http://localhost:5000. It processes data every 30 seconds and monitors predictions.

  2. Run the Predictor:

    python 1.py
    
    • It loads/trains the model on training_data.csv.
    • Monitors for new data and saves predictions to predictions.csv.
    • Press Ctrl+C to stop gracefully (saves model state).
  3. Open the Website:

    • Go to https://po.finance/fa/cabinet/demo-quick-high-low/ in Chrome.
    • The extension will auto-extract prices and execute trades based on signals from predictions.
  4. Endpoints (for debugging):

    • http://localhost:5000/data: POST price data (used by extension).
    • http://localhost:5000/get_signal: GET latest trade signal.
    • http://localhost:5000/status: GET system status.
    • http://localhost:5000/test_signal: GET last 5 predictions.
  5. Training/Evaluation:

    • The predictor auto-trains on historical data.
    • To evaluate: Run evaluate_model function in 1.py with sample data.

How It Works

  1. Extraction: content.js scrapes prices from the site, sends to Flask server, and checks for signals to trade (buy/sell).
  2. Processing: po_extractor.py compares prices every 30s, saves binary results (1 if up, 0 if down) to CSV.
  3. Prediction: 1.py uses ensemble models to predict next value, saves to predictions.csv.
  4. Trading: Extension polls server for new signals and clicks buy/sell buttons automatically.

Warnings

  • Financial Risk: This is for educational use. Do not use with real money—predictions are not guaranteed accurate.
  • Legal: Scraping and automating trades may violate PO Finance terms. Use only in demo mode.
  • Performance: Models are statistical; accuracy depends on data quality. Test thoroughly.
  • Data Privacy: Handles demo data only—no real user info.

Contributing

Feel free to fork and submit PRs! Issues welcome.

License

MIT License (see LICENSE file).

Author

Your Name (or GitHub username)

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published