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).
- 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.
- 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.
-
Clone the Repository:
git clone https://github.com/your-username/POPricePredictor.git cd POPricePredictor -
Install Python Dependencies: Create a
requirements.txtfile with:flask flask-cors pandas numpy scikit-learn scipyThen run:
pip install -r requirements.txt -
Load Chrome Extension:
- Go to
chrome://extensions/in Chrome. - Enable "Developer mode" (top right).
- Click "Load unpacked" and select the folder containing
manifest.jsonandcontent.js.
- Go to
-
Prepare Folders:
- Create a
models/folder for model storage. - The system will generate
training_data.csvandpredictions.csvautomatically.
- Create a
-
Run the Flask Server:
python po_extractor.pyThis starts the server on
http://localhost:5000. It processes data every 30 seconds and monitors predictions. -
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).
- It loads/trains the model on
-
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.
- Go to
-
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.
-
Training/Evaluation:
- The predictor auto-trains on historical data.
- To evaluate: Run
evaluate_modelfunction in1.pywith sample data.
- Extraction:
content.jsscrapes prices from the site, sends to Flask server, and checks for signals to trade (buy/sell). - Processing:
po_extractor.pycompares prices every 30s, saves binary results (1 if up, 0 if down) to CSV. - Prediction:
1.pyuses ensemble models to predict next value, saves topredictions.csv. - Trading: Extension polls server for new signals and clicks buy/sell buttons automatically.
- 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.
Feel free to fork and submit PRs! Issues welcome.
MIT License (see LICENSE file).
Your Name (or GitHub username)