This repository contains the source code for a Flask server designed to receive alerts from TradingView and forward them to a specified Telegram chat. The server is capable of handling both JSON and plain text data, making it flexible for various types of alerts.
- JSON and Text Data Handling: The server can process both JSON formatted data and plain text, ensuring compatibility with different types of alerts from TradingView.
- Telegram Integration: Automatically sends received alerts to a designated Telegram chat, enabling fast and efficient notifications.
- Logging: Comprehensive logging of received data and errors for easier troubleshooting and monitoring.
- Systemd Integration: Includes a systemd service configuration for easy deployment and management on any Linux system.
Before you can run the server, you need to have the following installed:
- Python 3.6+
- pip (Python package installer)
Follow these steps to get your server running:
-
Clone the repository: Use the following command to clone the repository to your local machine. Replace
<your-path>
with the directory path where you want to clone the repository.git clone https://github.com/TonySchneider/tradingview_telegram.git <your-path>/tradingview_telegram cd <your-path>/tradingview_telegram
-
Set up a virtual environment (optional, but recommended):
python -m venv venv source venv/bin/activate # On Windows use `venv\Scripts\activate`
-
Install the required packages:
pip install -r requirements.txt
Before running the server, you need to set the following environment variables:
CHAT_ID
: The Telegram chat ID where messages will be sent.TELEGRAM_BOT_TOKEN
: Your Telegram bot token.
You can set these variables in your environment, or use a .env
file and load it with a library like python-dotenv
.
The application includes a systemd service configuration for managing the Flask application as a service on Linux systems. You must edit the WorkingDirectory
and ExecStart
paths in the systemd service file to match your project's actual path. Here's how to prepare and use the service configuration:
-
Edit the systemd service file: Open
etc/systemd/system/tradingview_telegram.service
and replace/home/tony/tradingview_telegram
with the actual path to your project directory.[Service] User=root Group=root WorkingDirectory=<your-path>/tradingview_telegram ExecStart=/usr/bin/python3 <your-path>/tradingview_telegram/flask_runner.py Restart=always EnvironmentFile=/etc/environment
-
Copy the service file:
sudo cp etc/systemd/system/tradingview_telegram.service /etc/systemd/system/
-
Reload systemd to read the new service:
sudo systemctl daemon-reload
-
Enable the service to start at boot:
sudo systemctl enable tradingview_telegram.service
-
Start the service:
sudo systemctl start tradingview_telegram.service
To start the server, run the following command:
python flask_runner.py
The server will start on http://localhost:5000
and will listen for POST requests on the /trading-view-alert
endpoint.
Contributions to this project are welcome! Please fork the repository and submit a pull request with your changes. For major changes, please open an issue first to discuss what you would like to change.
This project is licensed under the MIT License - see the LICENSE file for details.
- Thanks to the contributors who maintain the Flask and PyTelegramBotAPI libraries.
- Special thanks to TradingView for their excellent tools and documentation.